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
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* date.h
|
2013-04-20 17:04:41 +02:00
|
|
|
* Definitions for the SQL "date" and "time" types.
|
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
|
|
|
*
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
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
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/date.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
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef DATE_H
|
|
|
|
#define DATE_H
|
|
|
|
|
2006-07-13 18:49:20 +02:00
|
|
|
#include <math.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
|
|
|
typedef int32 DateADT;
|
|
|
|
|
2002-04-21 21:52:18 +02:00
|
|
|
typedef int64 TimeADT;
|
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
|
|
|
|
2000-03-15 00:06:59 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-03-21 02:31:43 +01:00
|
|
|
TimeADT time; /* all time units other than months and years */
|
2002-09-04 22:31:48 +02:00
|
|
|
int32 zone; /* numeric time zone, in seconds */
|
2000-03-15 00:06:59 +01:00
|
|
|
} TimeTzADT;
|
|
|
|
|
2008-10-14 19:12:33 +02:00
|
|
|
/*
|
|
|
|
* Infinity and minus infinity must be the max and min values of DateADT.
|
|
|
|
*/
|
2015-04-02 17:43:35 +02:00
|
|
|
#define DATEVAL_NOBEGIN ((DateADT) PG_INT32_MIN)
|
|
|
|
#define DATEVAL_NOEND ((DateADT) PG_INT32_MAX)
|
2008-10-14 19:12:33 +02:00
|
|
|
|
|
|
|
#define DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN)
|
|
|
|
#define DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN)
|
|
|
|
#define DATE_NOEND(j) ((j) = DATEVAL_NOEND)
|
|
|
|
#define DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND)
|
|
|
|
#define DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
|
|
|
|
|
2005-02-25 17:13:29 +01:00
|
|
|
/*
|
|
|
|
* Macros for fmgr-callable functions.
|
|
|
|
*
|
2017-02-23 20:04:43 +01:00
|
|
|
* For TimeADT, we make use of the same support routines as for int64.
|
|
|
|
* Therefore TimeADT is pass-by-reference if and only if int64 is!
|
2005-02-25 17:13:29 +01:00
|
|
|
*/
|
2002-04-21 21:52:18 +02:00
|
|
|
#define MAX_TIME_PRECISION 6
|
2005-02-25 17:13:29 +01:00
|
|
|
|
|
|
|
#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
|
|
|
|
#define DatumGetTimeADT(X) ((TimeADT) DatumGetInt64(X))
|
|
|
|
#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
|
|
|
|
|
|
|
|
#define DateADTGetDatum(X) Int32GetDatum(X)
|
|
|
|
#define TimeADTGetDatum(X) Int64GetDatum(X)
|
|
|
|
#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
|
2000-06-09 03:11:16 +02:00
|
|
|
#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
|
|
|
|
#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
|
2000-06-09 03:11:16 +02:00
|
|
|
#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
|
|
|
|
|
|
|
|
|
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
|
|
|
/* date.c */
|
2016-08-17 02:33:01 +02:00
|
|
|
extern int32 anytime_typmod_check(bool istz, int32 typmod);
|
2010-12-29 04:49:57 +01:00
|
|
|
extern double date2timestamp_no_overflow(DateADT dateVal);
|
2015-10-20 20:06:24 +02:00
|
|
|
extern void EncodeSpecialDate(DateADT dt, char *str);
|
2016-08-17 02:33:01 +02:00
|
|
|
extern DateADT GetSQLCurrentDate(void);
|
|
|
|
extern TimeTzADT *GetSQLCurrentTime(int32 typmod);
|
|
|
|
extern TimeADT GetSQLLocalTime(int32 typmod);
|
2010-12-29 04:49:57 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* DATE_H */
|