1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* nabstime.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Definitions for the "new" abstime code.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2000-03-27 19:07:48 +02:00
|
|
|
* $Id: nabstime.h,v 1.24 2000/03/27 17:07:48 thomas Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef NABSTIME_H
|
|
|
|
#define NABSTIME_H
|
|
|
|
|
|
|
|
#include <time.h>
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
#include "utils/timestamp.h"
|
|
|
|
#include "utils/datetime.h"
|
1997-03-15 00:34:16 +01:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* time types + support macros
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
2000-01-24 20:34:19 +01:00
|
|
|
/*
|
|
|
|
* Although time_t generally is a long int on 64 bit systems, these two
|
|
|
|
* types must be 4 bytes, because that's what the system assumes. They
|
|
|
|
* should be yanked (long) before 2038 and be replaced by timestamp and
|
|
|
|
* interval.
|
1999-03-14 17:44:02 +01:00
|
|
|
*/
|
2000-01-24 20:34:19 +01:00
|
|
|
typedef int32 AbsoluteTime;
|
|
|
|
typedef int32 RelativeTime;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int32 status;
|
|
|
|
AbsoluteTime data[2];
|
1997-09-08 23:56:23 +02:00
|
|
|
} TimeIntervalData;
|
1996-08-28 03:59:28 +02:00
|
|
|
typedef TimeIntervalData *TimeInterval;
|
|
|
|
|
1997-03-15 00:34:16 +01:00
|
|
|
/*
|
|
|
|
* Reserved values
|
|
|
|
* Epoch is Unix system time zero, but needs to be kept as a reserved
|
1997-09-07 07:04:48 +02:00
|
|
|
* value rather than converting to time since timezone calculations
|
|
|
|
* might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20
|
1997-03-15 00:34:16 +01:00
|
|
|
*
|
|
|
|
* Pre-v6.1 code had large decimal numbers for reserved values.
|
|
|
|
* These were chosen as special 32-bit bit patterns,
|
1997-09-07 07:04:48 +02:00
|
|
|
* so redefine them explicitly using these bit patterns. - tgl 97/02/24
|
1997-03-15 00:34:16 +01:00
|
|
|
*/
|
1996-08-28 03:59:28 +02:00
|
|
|
#define EPOCH_ABSTIME ((AbsoluteTime) 0)
|
2000-03-27 19:07:48 +02:00
|
|
|
#define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
|
|
|
|
#define CURRENT_ABSTIME ((AbsoluteTime) 0x7FFFFFFD) /* 2147483646 (2^31 - 2) */
|
|
|
|
#define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
|
|
|
|
#define BIG_ABSTIME ((AbsoluteTime) 0x7FFFFFFB) /* 2147483644 (2^31 - 4) */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1998-02-13 18:12:08 +01:00
|
|
|
#if defined(_AIX)
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
|
|
|
* AIX considers 2147483648 == -2147483648 (since they have the same bit
|
1997-09-07 07:04:48 +02:00
|
|
|
* representation) but uses a different sign sense in a comparison to
|
|
|
|
* these integer constants depending on whether the constant is signed
|
1996-08-28 03:59:28 +02:00
|
|
|
* or not!
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN)
|
1996-08-28 03:59:28 +02:00
|
|
|
#else
|
2000-03-27 19:07:48 +02:00
|
|
|
#define NOSTART_ABSTIME ((AbsoluteTime) 0x80000001) /* -2147483647 (- 2^31) */
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* _AIX */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-03-27 19:07:48 +02:00
|
|
|
#define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define AbsoluteTimeIsValid(time) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool) ((time) != INVALID_ABSTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define AbsoluteTimeIsReal(time) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
|
|
|
|
((AbsoluteTime) time) > NOSTART_ABSTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* have to include this because EPOCH_ABSTIME used to be invalid - yuk */
|
|
|
|
#define AbsoluteTimeIsBackwardCompatiblyValid(time) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool) (((AbsoluteTime) time) != INVALID_ABSTIME && \
|
|
|
|
((AbsoluteTime) time) > EPOCH_ABSTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define AbsoluteTimeIsBackwardCompatiblyReal(time) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
|
|
|
|
((AbsoluteTime) time) > NOSTART_ABSTIME && \
|
|
|
|
((AbsoluteTime) time) > EPOCH_ABSTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define RelativeTimeIsValid(time) \
|
1997-09-07 07:04:48 +02:00
|
|
|
((bool) (((RelativeTime) time) != INVALID_RELTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-03-15 00:34:16 +01:00
|
|
|
extern AbsoluteTime GetCurrentAbsoluteTime(void);
|
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/*
|
1999-05-25 18:15:34 +02:00
|
|
|
* getSystemTime
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns system time.
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
#define getSystemTime() \
|
1997-09-07 07:04:48 +02:00
|
|
|
((time_t) (time(0l)))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* nabstime.c prototypes
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
extern AbsoluteTime nabstimein(char *timestr);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *nabstimeout(AbsoluteTime time);
|
1997-03-15 00:34:16 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool abstimeeq(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstimene(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstimelt(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstimegt(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstimele(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstimege(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern bool abstime_finite(AbsoluteTime time);
|
1997-03-15 00:34:16 +01:00
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
extern AbsoluteTime timestamp_abstime(Timestamp *timestamp);
|
|
|
|
extern Timestamp *abstime_timestamp(AbsoluteTime abstime);
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern bool AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2);
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
extern RelativeTime reltimein(char *timestring);
|
|
|
|
extern char *reltimeout(RelativeTime timevalue);
|
|
|
|
extern TimeInterval tintervalin(char *intervalstr);
|
|
|
|
extern char *tintervalout(TimeInterval interval);
|
|
|
|
extern RelativeTime interval_reltime(Interval *interval);
|
|
|
|
extern Interval *reltime_interval(RelativeTime reltime);
|
|
|
|
extern TimeInterval mktinterval(AbsoluteTime t1, AbsoluteTime t2);
|
|
|
|
extern AbsoluteTime timepl(AbsoluteTime t1, RelativeTime t2);
|
|
|
|
extern AbsoluteTime timemi(AbsoluteTime t1, RelativeTime t2);
|
|
|
|
|
|
|
|
/* extern RelativeTime abstimemi(AbsoluteTime t1, AbsoluteTime t2); static*/
|
|
|
|
extern int intinterval(AbsoluteTime t, TimeInterval interval);
|
|
|
|
extern RelativeTime tintervalrel(TimeInterval interval);
|
|
|
|
extern AbsoluteTime timenow(void);
|
|
|
|
extern bool reltimeeq(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool reltimene(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool reltimelt(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool reltimegt(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool reltimele(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool reltimege(RelativeTime t1, RelativeTime t2);
|
|
|
|
extern bool tintervalsame(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervaleq(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalne(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervallt(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalgt(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalle(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalge(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalleneq(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervallenne(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervallenlt(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervallengt(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervallenle(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervallenge(TimeInterval i, RelativeTime t);
|
|
|
|
extern bool tintervalct(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern bool tintervalov(TimeInterval i1, TimeInterval i2);
|
|
|
|
extern AbsoluteTime tintervalstart(TimeInterval i);
|
|
|
|
extern AbsoluteTime tintervalend(TimeInterval i);
|
|
|
|
extern int32 int4reltime(int32 timevalue);
|
|
|
|
extern text *timeofday(void);
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* NABSTIME_H */
|