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
|
|
|
*
|
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2001-11-05 18:46:40 +01:00
|
|
|
* $Id: nabstime.h,v 1.35 2001/11/05 17:46:36 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef NABSTIME_H
|
|
|
|
#define NABSTIME_H
|
|
|
|
|
2000-11-18 06:41:45 +01:00
|
|
|
#include <limits.h>
|
1996-08-28 03:59:28 +02:00
|
|
|
#include <time.h>
|
2000-06-09 03:11:16 +02:00
|
|
|
|
|
|
|
#include "fmgr.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
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
*
|
2000-06-09 03:11:16 +02:00
|
|
|
* time types + support macros
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
2000-04-12 19:17:23 +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;
|
2000-06-09 03:11:16 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
typedef TimeIntervalData *TimeInterval;
|
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
/*
|
|
|
|
* Macros for fmgr-callable functions.
|
|
|
|
*/
|
|
|
|
#define DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X))
|
|
|
|
#define DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X))
|
|
|
|
#define DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X))
|
|
|
|
|
|
|
|
#define AbsoluteTimeGetDatum(X) Int32GetDatum(X)
|
|
|
|
#define RelativeTimeGetDatum(X) Int32GetDatum(X)
|
|
|
|
#define TimeIntervalGetDatum(X) PointerGetDatum(X)
|
|
|
|
|
|
|
|
#define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n))
|
|
|
|
|
|
|
|
#define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x)
|
|
|
|
#define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x)
|
|
|
|
#define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x)
|
|
|
|
|
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
|
|
|
*/
|
2000-04-12 19:17:23 +02:00
|
|
|
#define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
|
|
|
|
#define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
|
2001-03-22 05:01:46 +01:00
|
|
|
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) /* -2147483648 */
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-04-12 19:17:23 +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
|
|
|
|
2000-11-18 06:41:45 +01:00
|
|
|
/*
|
|
|
|
* Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any
|
|
|
|
* AbsoluteTime values less than it. Therefore, we can code the test
|
|
|
|
* "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids
|
|
|
|
* compiler bugs on some platforms. --- tgl & az, 11/2000
|
|
|
|
*/
|
1996-08-28 03:59:28 +02:00
|
|
|
#define AbsoluteTimeIsReal(time) \
|
2000-11-18 06:41:45 +01:00
|
|
|
((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \
|
|
|
|
((AbsoluteTime) (time)) != NOSTART_ABSTIME))
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
#define RelativeTimeIsValid(time) \
|
2000-11-18 06:41:45 +01:00
|
|
|
((bool) (((RelativeTime) (time)) != INVALID_RELTIME))
|
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
|
|
|
*/
|
2000-06-09 03:11:16 +02:00
|
|
|
extern Datum nabstimein(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum nabstimeout(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
extern Datum abstimeeq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstimene(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstimelt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstimegt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstimele(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstimege(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstime_finite(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
extern Datum timestamp_abstime(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstime_timestamp(PG_FUNCTION_ARGS);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Datum timestamptz_abstime(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum abstime_timestamptz(PG_FUNCTION_ARGS);
|
2000-06-09 03:11:16 +02:00
|
|
|
|
|
|
|
extern Datum reltimein(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimeout(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalin(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalout(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum interval_reltime(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltime_interval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum mktinterval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timepl(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timemi(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
extern Datum intinterval(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalrel(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timenow(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimeeq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimene(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimelt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimegt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimele(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum reltimege(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalsame(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervaleq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalgt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalle(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalleneq(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallenne(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallenlt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallengt(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallenle(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervallenge(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalct(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalov(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalstart(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum tintervalend(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum int4reltime(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum timeofday(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
/* non-fmgr-callable support routines */
|
|
|
|
extern AbsoluteTime GetCurrentAbsoluteTime(void);
|
2001-09-28 10:09:14 +02:00
|
|
|
extern AbsoluteTime GetCurrentAbsoluteTimeUsec(int *usec);
|
2001-10-18 19:30:21 +02:00
|
|
|
extern void abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char **tzn);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* NABSTIME_H */
|