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
|
|
|
*
|
|
|
|
*
|
2019-01-02 18:44:25 +01:00
|
|
|
* Portions Copyright (c) 1996-2019, 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"
|
2018-01-17 09:33:02 +01:00
|
|
|
#include "pgtime.h"
|
2018-01-17 01:07:13 +01:00
|
|
|
#include "datatype/timestamp.h"
|
2000-06-09 03:11:16 +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
|
|
|
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);
|
2018-01-17 01:07:13 +01:00
|
|
|
extern int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec);
|
|
|
|
extern int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp);
|
2010-12-29 04:49:57 +01:00
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
#endif /* DATE_H */
|