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
|
|
|
*
|
|
|
|
*
|
2021-01-02 19:06:25 +01:00
|
|
|
* Portions Copyright (c) 1996-2021, 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>
|
|
|
|
|
2019-11-25 03:38:57 +01:00
|
|
|
#include "datatype/timestamp.h"
|
2000-06-09 03:11:16 +02:00
|
|
|
#include "fmgr.h"
|
2018-01-17 09:33:02 +01:00
|
|
|
#include "pgtime.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-04-21 21:52:18 +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)
|
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
|
|
|
|
|
|
|
|
#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
|
|
|
|
#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
|
|
|
|
#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);
|
2019-10-21 22:04:14 +02:00
|
|
|
extern Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow);
|
|
|
|
extern TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow);
|
Prevent internal overflows in date-vs-timestamp and related comparisons.
The date-vs-timestamp, date-vs-timestamptz, and timestamp-vs-timestamptz
comparators all worked by promoting the first type to the second and
then doing a simple same-type comparison. This works fine, except
when the conversion result is out of range, in which case we throw an
entirely avoidable error. The sources of such failures are
(a) type date can represent dates much farther in the future than
the timestamp types can;
(b) timezone rotation might cause a just-in-range timestamp value to
become a just-out-of-range timestamptz value.
Up to now we just ignored these corner-case issues, but now we have
an actual user complaint (bug #16657 from Huss EL-Sheikh), so let's
do something about it.
It turns out that commit 52ad1e659 already built all the necessary
infrastructure to support error-free comparisons, but neglected to
actually use it in the main-line code paths. Fix that, do a little
bit of code style review, and remove the now-duplicate logic in
jsonpath_exec.c.
Back-patch to v13 where 52ad1e659 came in. We could take this back
further by back-patching said infrastructure, but given the small
number of complaints so far, I don't feel a great need to.
Discussion: https://postgr.es/m/16657-cde2f876d8cc7971@postgresql.org
2020-10-07 23:10:26 +02:00
|
|
|
extern int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2);
|
|
|
|
extern int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2);
|
|
|
|
|
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);
|
2019-09-25 20:50:55 +02:00
|
|
|
extern int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result);
|
|
|
|
extern int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result);
|
2020-06-04 22:42:08 +02:00
|
|
|
extern bool time_overflows(int hour, int min, int sec, fsec_t fsec);
|
|
|
|
extern bool float_time_overflows(int hour, int min, double sec);
|
2019-09-25 20:50:55 +02:00
|
|
|
extern void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
|
2010-12-29 04:49:57 +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
|
|
|
#endif /* DATE_H */
|