]> granicus.if.org Git - postgresql/blob - src/include/utils/date.h
Update copyright for 2018
[postgresql] / src / include / utils / date.h
1 /*-------------------------------------------------------------------------
2  *
3  * date.h
4  *        Definitions for the SQL "date" and "time" types.
5  *
6  *
7  * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/utils/date.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef DATE_H
15 #define DATE_H
16
17 #include <math.h>
18
19 #include "fmgr.h"
20
21
22 typedef int32 DateADT;
23
24 typedef int64 TimeADT;
25
26 typedef struct
27 {
28         TimeADT         time;                   /* all time units other than months and years */
29         int32           zone;                   /* numeric time zone, in seconds */
30 } TimeTzADT;
31
32 /*
33  * Infinity and minus infinity must be the max and min values of DateADT.
34  */
35 #define DATEVAL_NOBEGIN         ((DateADT) PG_INT32_MIN)
36 #define DATEVAL_NOEND           ((DateADT) PG_INT32_MAX)
37
38 #define DATE_NOBEGIN(j)         ((j) = DATEVAL_NOBEGIN)
39 #define DATE_IS_NOBEGIN(j)      ((j) == DATEVAL_NOBEGIN)
40 #define DATE_NOEND(j)           ((j) = DATEVAL_NOEND)
41 #define DATE_IS_NOEND(j)        ((j) == DATEVAL_NOEND)
42 #define DATE_NOT_FINITE(j)      (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
43
44 /*
45  * Macros for fmgr-callable functions.
46  *
47  * For TimeADT, we make use of the same support routines as for int64.
48  * Therefore TimeADT is pass-by-reference if and only if int64 is!
49  */
50 #define MAX_TIME_PRECISION 6
51
52 #define DatumGetDateADT(X)        ((DateADT) DatumGetInt32(X))
53 #define DatumGetTimeADT(X)        ((TimeADT) DatumGetInt64(X))
54 #define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
55
56 #define DateADTGetDatum(X)        Int32GetDatum(X)
57 #define TimeADTGetDatum(X)        Int64GetDatum(X)
58 #define TimeTzADTPGetDatum(X) PointerGetDatum(X)
59
60 #define PG_GETARG_DATEADT(n)     DatumGetDateADT(PG_GETARG_DATUM(n))
61 #define PG_GETARG_TIMEADT(n)     DatumGetTimeADT(PG_GETARG_DATUM(n))
62 #define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
63
64 #define PG_RETURN_DATEADT(x)     return DateADTGetDatum(x)
65 #define PG_RETURN_TIMEADT(x)     return TimeADTGetDatum(x)
66 #define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
67
68
69 /* date.c */
70 extern int32 anytime_typmod_check(bool istz, int32 typmod);
71 extern double date2timestamp_no_overflow(DateADT dateVal);
72 extern void EncodeSpecialDate(DateADT dt, char *str);
73 extern DateADT GetSQLCurrentDate(void);
74 extern TimeTzADT *GetSQLCurrentTime(int32 typmod);
75 extern TimeADT GetSQLLocalTime(int32 typmod);
76
77 #endif                                                  /* DATE_H */