Header And Logo

PostgreSQL
| The world's most advanced open source database.

date.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * date.h
00004  *    Definitions for the SQL "date" and "time" types.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/utils/date.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef DATE_H
00015 #define DATE_H
00016 
00017 #include <math.h>
00018 
00019 #include "fmgr.h"
00020 
00021 
00022 typedef int32 DateADT;
00023 
00024 #ifdef HAVE_INT64_TIMESTAMP
00025 typedef int64 TimeADT;
00026 #else
00027 typedef float8 TimeADT;
00028 #endif
00029 
00030 typedef struct
00031 {
00032     TimeADT     time;           /* all time units other than months and years */
00033     int32       zone;           /* numeric time zone, in seconds */
00034 } TimeTzADT;
00035 
00036 /*
00037  * Infinity and minus infinity must be the max and min values of DateADT.
00038  * We could use INT_MIN and INT_MAX here, but seems better to not assume that
00039  * int32 == int.
00040  */
00041 #define DATEVAL_NOBEGIN     ((DateADT) (-0x7fffffff - 1))
00042 #define DATEVAL_NOEND       ((DateADT) 0x7fffffff)
00043 
00044 #define DATE_NOBEGIN(j)     ((j) = DATEVAL_NOBEGIN)
00045 #define DATE_IS_NOBEGIN(j)  ((j) == DATEVAL_NOBEGIN)
00046 #define DATE_NOEND(j)       ((j) = DATEVAL_NOEND)
00047 #define DATE_IS_NOEND(j)    ((j) == DATEVAL_NOEND)
00048 #define DATE_NOT_FINITE(j)  (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
00049 
00050 /*
00051  * Macros for fmgr-callable functions.
00052  *
00053  * For TimeADT, we make use of the same support routines as for float8 or int64.
00054  * Therefore TimeADT is pass-by-reference if and only if float8 or int64 is!
00055  */
00056 #ifdef HAVE_INT64_TIMESTAMP
00057 
00058 #define MAX_TIME_PRECISION 6
00059 
00060 #define DatumGetDateADT(X)    ((DateADT) DatumGetInt32(X))
00061 #define DatumGetTimeADT(X)    ((TimeADT) DatumGetInt64(X))
00062 #define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
00063 
00064 #define DateADTGetDatum(X)    Int32GetDatum(X)
00065 #define TimeADTGetDatum(X)    Int64GetDatum(X)
00066 #define TimeTzADTPGetDatum(X) PointerGetDatum(X)
00067 #else                           /* !HAVE_INT64_TIMESTAMP */
00068 
00069 #define MAX_TIME_PRECISION 10
00070 
00071 /* round off to MAX_TIME_PRECISION decimal places */
00072 #define TIME_PREC_INV 10000000000.0
00073 #define TIMEROUND(j) (rint(((double) (j)) * TIME_PREC_INV) / TIME_PREC_INV)
00074 
00075 #define DatumGetDateADT(X)    ((DateADT) DatumGetInt32(X))
00076 #define DatumGetTimeADT(X)    ((TimeADT) DatumGetFloat8(X))
00077 #define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
00078 
00079 #define DateADTGetDatum(X)    Int32GetDatum(X)
00080 #define TimeADTGetDatum(X)    Float8GetDatum(X)
00081 #define TimeTzADTPGetDatum(X) PointerGetDatum(X)
00082 #endif   /* HAVE_INT64_TIMESTAMP */
00083 
00084 #define PG_GETARG_DATEADT(n)     DatumGetDateADT(PG_GETARG_DATUM(n))
00085 #define PG_GETARG_TIMEADT(n)     DatumGetTimeADT(PG_GETARG_DATUM(n))
00086 #define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
00087 
00088 #define PG_RETURN_DATEADT(x)     return DateADTGetDatum(x)
00089 #define PG_RETURN_TIMEADT(x)     return TimeADTGetDatum(x)
00090 #define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
00091 
00092 
00093 /* date.c */
00094 extern double date2timestamp_no_overflow(DateADT dateVal);
00095 
00096 extern Datum date_in(PG_FUNCTION_ARGS);
00097 extern Datum date_out(PG_FUNCTION_ARGS);
00098 extern Datum date_recv(PG_FUNCTION_ARGS);
00099 extern Datum date_send(PG_FUNCTION_ARGS);
00100 extern Datum date_eq(PG_FUNCTION_ARGS);
00101 extern Datum date_ne(PG_FUNCTION_ARGS);
00102 extern Datum date_lt(PG_FUNCTION_ARGS);
00103 extern Datum date_le(PG_FUNCTION_ARGS);
00104 extern Datum date_gt(PG_FUNCTION_ARGS);
00105 extern Datum date_ge(PG_FUNCTION_ARGS);
00106 extern Datum date_cmp(PG_FUNCTION_ARGS);
00107 extern Datum date_sortsupport(PG_FUNCTION_ARGS);
00108 extern Datum date_finite(PG_FUNCTION_ARGS);
00109 extern Datum date_larger(PG_FUNCTION_ARGS);
00110 extern Datum date_smaller(PG_FUNCTION_ARGS);
00111 extern Datum date_mi(PG_FUNCTION_ARGS);
00112 extern Datum date_pli(PG_FUNCTION_ARGS);
00113 extern Datum date_mii(PG_FUNCTION_ARGS);
00114 extern Datum date_eq_timestamp(PG_FUNCTION_ARGS);
00115 extern Datum date_ne_timestamp(PG_FUNCTION_ARGS);
00116 extern Datum date_lt_timestamp(PG_FUNCTION_ARGS);
00117 extern Datum date_le_timestamp(PG_FUNCTION_ARGS);
00118 extern Datum date_gt_timestamp(PG_FUNCTION_ARGS);
00119 extern Datum date_ge_timestamp(PG_FUNCTION_ARGS);
00120 extern Datum date_cmp_timestamp(PG_FUNCTION_ARGS);
00121 extern Datum date_eq_timestamptz(PG_FUNCTION_ARGS);
00122 extern Datum date_ne_timestamptz(PG_FUNCTION_ARGS);
00123 extern Datum date_lt_timestamptz(PG_FUNCTION_ARGS);
00124 extern Datum date_le_timestamptz(PG_FUNCTION_ARGS);
00125 extern Datum date_gt_timestamptz(PG_FUNCTION_ARGS);
00126 extern Datum date_ge_timestamptz(PG_FUNCTION_ARGS);
00127 extern Datum date_cmp_timestamptz(PG_FUNCTION_ARGS);
00128 extern Datum timestamp_eq_date(PG_FUNCTION_ARGS);
00129 extern Datum timestamp_ne_date(PG_FUNCTION_ARGS);
00130 extern Datum timestamp_lt_date(PG_FUNCTION_ARGS);
00131 extern Datum timestamp_le_date(PG_FUNCTION_ARGS);
00132 extern Datum timestamp_gt_date(PG_FUNCTION_ARGS);
00133 extern Datum timestamp_ge_date(PG_FUNCTION_ARGS);
00134 extern Datum timestamp_cmp_date(PG_FUNCTION_ARGS);
00135 extern Datum timestamptz_eq_date(PG_FUNCTION_ARGS);
00136 extern Datum timestamptz_ne_date(PG_FUNCTION_ARGS);
00137 extern Datum timestamptz_lt_date(PG_FUNCTION_ARGS);
00138 extern Datum timestamptz_le_date(PG_FUNCTION_ARGS);
00139 extern Datum timestamptz_gt_date(PG_FUNCTION_ARGS);
00140 extern Datum timestamptz_ge_date(PG_FUNCTION_ARGS);
00141 extern Datum timestamptz_cmp_date(PG_FUNCTION_ARGS);
00142 extern Datum date_pl_interval(PG_FUNCTION_ARGS);
00143 extern Datum date_mi_interval(PG_FUNCTION_ARGS);
00144 extern Datum date_timestamp(PG_FUNCTION_ARGS);
00145 extern Datum timestamp_date(PG_FUNCTION_ARGS);
00146 extern Datum date_timestamptz(PG_FUNCTION_ARGS);
00147 extern Datum timestamptz_date(PG_FUNCTION_ARGS);
00148 extern Datum datetime_timestamp(PG_FUNCTION_ARGS);
00149 extern Datum abstime_date(PG_FUNCTION_ARGS);
00150 
00151 extern Datum time_in(PG_FUNCTION_ARGS);
00152 extern Datum time_out(PG_FUNCTION_ARGS);
00153 extern Datum time_recv(PG_FUNCTION_ARGS);
00154 extern Datum time_send(PG_FUNCTION_ARGS);
00155 extern Datum timetypmodin(PG_FUNCTION_ARGS);
00156 extern Datum timetypmodout(PG_FUNCTION_ARGS);
00157 extern Datum time_transform(PG_FUNCTION_ARGS);
00158 extern Datum time_scale(PG_FUNCTION_ARGS);
00159 extern Datum time_eq(PG_FUNCTION_ARGS);
00160 extern Datum time_ne(PG_FUNCTION_ARGS);
00161 extern Datum time_lt(PG_FUNCTION_ARGS);
00162 extern Datum time_le(PG_FUNCTION_ARGS);
00163 extern Datum time_gt(PG_FUNCTION_ARGS);
00164 extern Datum time_ge(PG_FUNCTION_ARGS);
00165 extern Datum time_cmp(PG_FUNCTION_ARGS);
00166 extern Datum time_hash(PG_FUNCTION_ARGS);
00167 extern Datum overlaps_time(PG_FUNCTION_ARGS);
00168 extern Datum time_larger(PG_FUNCTION_ARGS);
00169 extern Datum time_smaller(PG_FUNCTION_ARGS);
00170 extern Datum time_mi_time(PG_FUNCTION_ARGS);
00171 extern Datum timestamp_time(PG_FUNCTION_ARGS);
00172 extern Datum timestamptz_time(PG_FUNCTION_ARGS);
00173 extern Datum time_interval(PG_FUNCTION_ARGS);
00174 extern Datum interval_time(PG_FUNCTION_ARGS);
00175 extern Datum time_pl_interval(PG_FUNCTION_ARGS);
00176 extern Datum time_mi_interval(PG_FUNCTION_ARGS);
00177 extern Datum time_part(PG_FUNCTION_ARGS);
00178 
00179 extern Datum timetz_in(PG_FUNCTION_ARGS);
00180 extern Datum timetz_out(PG_FUNCTION_ARGS);
00181 extern Datum timetz_recv(PG_FUNCTION_ARGS);
00182 extern Datum timetz_send(PG_FUNCTION_ARGS);
00183 extern Datum timetztypmodin(PG_FUNCTION_ARGS);
00184 extern Datum timetztypmodout(PG_FUNCTION_ARGS);
00185 extern Datum timetz_scale(PG_FUNCTION_ARGS);
00186 extern Datum timetz_eq(PG_FUNCTION_ARGS);
00187 extern Datum timetz_ne(PG_FUNCTION_ARGS);
00188 extern Datum timetz_lt(PG_FUNCTION_ARGS);
00189 extern Datum timetz_le(PG_FUNCTION_ARGS);
00190 extern Datum timetz_gt(PG_FUNCTION_ARGS);
00191 extern Datum timetz_ge(PG_FUNCTION_ARGS);
00192 extern Datum timetz_cmp(PG_FUNCTION_ARGS);
00193 extern Datum timetz_hash(PG_FUNCTION_ARGS);
00194 extern Datum overlaps_timetz(PG_FUNCTION_ARGS);
00195 extern Datum timetz_larger(PG_FUNCTION_ARGS);
00196 extern Datum timetz_smaller(PG_FUNCTION_ARGS);
00197 extern Datum timetz_time(PG_FUNCTION_ARGS);
00198 extern Datum time_timetz(PG_FUNCTION_ARGS);
00199 extern Datum timestamptz_timetz(PG_FUNCTION_ARGS);
00200 extern Datum datetimetz_timestamptz(PG_FUNCTION_ARGS);
00201 extern Datum timetz_part(PG_FUNCTION_ARGS);
00202 extern Datum timetz_zone(PG_FUNCTION_ARGS);
00203 extern Datum timetz_izone(PG_FUNCTION_ARGS);
00204 extern Datum timetz_pl_interval(PG_FUNCTION_ARGS);
00205 extern Datum timetz_mi_interval(PG_FUNCTION_ARGS);
00206 
00207 #endif   /* DATE_H */