14#define USE_POSTGRES_DATES 0
15#define USE_ISO_DATES 1
16#define USE_SQL_DATES 2
17#define USE_GERMAN_DATES 3
19#define INTSTYLE_POSTGRES 0
20#define INTSTYLE_POSTGRES_VERBOSE 1
21#define INTSTYLE_SQL_STANDARD 2
22#define INTSTYLE_ISO_8601 3
24#define INTERVAL_FULL_RANGE (0x7FFF)
25#define INTERVAL_MASK(b) (1 << (b))
26#define MAX_INTERVAL_PRECISION 6
28#define DTERR_BAD_FORMAT (-1)
29#define DTERR_FIELD_OVERFLOW (-2)
30#define DTERR_MD_FIELD_OVERFLOW (-3)
31#define DTERR_INTERVAL_OVERFLOW (-4)
32#define DTERR_TZDISP_OVERFLOW (-5)
36#define DCURRENT "current"
38#define INVALID "invalid"
39#define EARLY "-infinity"
40#define LATE "infinity"
43#define TOMORROW "tomorrow"
44#define YESTERDAY "yesterday"
47#define DMICROSEC "usecond"
48#define DMILLISEC "msecond"
49#define DSECOND "second"
50#define DMINUTE "minute"
55#define DQUARTER "quarter"
57#define DDECADE "decade"
58#define DCENTURY "century"
59#define DMILLENNIUM "millennium"
62#define DTIMEZONE "timezone"
105#define MILLISECOND 13
106#define MICROSECOND 14
121#define UNKNOWN_FIELD 31
152#define DTK_YESTERDAY 13
154#define DTK_TOMORROW 15
164#define DTK_QUARTER 24
167#define DTK_CENTURY 27
168#define DTK_MILLENNIUM 28
169#define DTK_MILLISEC 29
170#define DTK_MICROSEC 30
175#define DTK_TZ_HOUR 34
176#define DTK_TZ_MINUTE 35
177#define DTK_ISOYEAR 36
185#define DTK_M(t) (0x01 << (t))
186#define DTK_ALL_SECS_M (DTK_M(SECOND) | DTK_M(MILLISECOND) | DTK_M(MICROSECOND))
187#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY))
188#define DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_M(SECOND))
196#define MAXDATELEN 128
198#define MAXDATEFIELDS 25
217#define FMODULO(t,q,u) \
219 (q) = (((t) < 0) ? ceil((t) / (u)): floor((t) / (u))); \
220 if ((q) != 0) (t) -= rint((q) * (u)); \
228#define TMODULO(t,q,u) \
231 if ((q) != 0) (t) -= ((q) * (u)); \
235#define DAYS_PER_YEAR 365.25
236#define MONTHS_PER_YEAR 12
244#define DAYS_PER_MONTH 30
245#define HOURS_PER_DAY 24
252#define SECS_PER_YEAR (36525 * 864)
253#define SECS_PER_DAY 86400
254#define SECS_PER_HOUR 3600
255#define SECS_PER_MINUTE 60
256#define MINS_PER_HOUR 60
258#define USECS_PER_DAY INT64CONST(86400000000)
259#define USECS_PER_HOUR INT64CONST(3600000000)
260#define USECS_PER_MINUTE INT64CONST(60000000)
261#define USECS_PER_SEC INT64CONST(1000000)
267#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
273#define JULIAN_MINYEAR (-4713)
274#define JULIAN_MINMONTH (11)
275#define JULIAN_MINDAY (24)
276#define JULIAN_MAXYEAR (5874898)
277#define JULIAN_MAXMONTH (6)
278#define JULIAN_MAXDAY (3)
280#define IS_VALID_JULIAN(y,m,d) \
281 (((y) > JULIAN_MINYEAR || \
282 ((y) == JULIAN_MINYEAR && ((m) >= JULIAN_MINMONTH))) && \
283 ((y) < JULIAN_MAXYEAR || \
284 ((y) == JULIAN_MAXYEAR && ((m) < JULIAN_MAXMONTH))))
286#define MIN_TIMESTAMP INT64CONST(-211813488000000000)
287#define END_TIMESTAMP INT64CONST(9223371331200000000)
289#define IS_VALID_TIMESTAMP(t) (MIN_TIMESTAMP <= (t) && (t) < END_TIMESTAMP)
291#define UTIME_MINYEAR (1901)
292#define UTIME_MINMONTH (12)
293#define UTIME_MINDAY (14)
294#define UTIME_MAXYEAR (2038)
295#define UTIME_MAXMONTH (01)
296#define UTIME_MAXDAY (18)
298#define IS_VALID_UTIME(y,m,d) ((((y) > UTIME_MINYEAR) \
299 || (((y) == UTIME_MINYEAR) && (((m) > UTIME_MINMONTH) \
300 || (((m) == UTIME_MINMONTH) && ((d) >= UTIME_MINDAY))))) \
301 && (((y) < UTIME_MAXYEAR) \
302 || (((y) == UTIME_MAXYEAR) && (((m) < UTIME_MAXMONTH) \
303 || (((m) == UTIME_MAXMONTH) && ((d) <= UTIME_MAXDAY))))))
305#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
306#define DT_NOEND (INT64CONST(0x7fffffffffffffff))
308#define TIMESTAMP_NOBEGIN(j) do {(j) = DT_NOBEGIN;} while (0)
309#define TIMESTAMP_NOEND(j) do {(j) = DT_NOEND;} while (0)
310#define TIMESTAMP_IS_NOBEGIN(j) ((j) == DT_NOBEGIN)
311#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
312#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
323int ParseDateTime(
char *timestr,
char *lowstr,
char **field,
int *ftype,
int *numfields,
char **endstr);
325void j2date(
int jd,
int *year,
int *month,
int *day);
327int date2j(
int y,
int m,
int d);
329void dt2time(
double jd,
int *hour,
int *min,
int *sec,
fsec_t *fsec);
331 int *year,
int *month,
int *day,
332 int *hour,
int *minute,
int *second,
339extern const int day_tab[2][13];
void EncodeDateOnly(struct tm *tm, int style, char *str, bool EuroDates)
int GetEpochTime(struct tm *tm)
int PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d, int *year, int *month, int *day, int *hour, int *minute, int *second, int *tz)
void EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str, bool EuroDates)
void TrimTrailingZeros(char *str)
void GetCurrentDateTime(struct tm *tm)
int DecodeTime(char *str, int *tmask, struct tm *tm, fsec_t *fsec)
int date2j(int y, int m, int d)
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str)
int ParseDateTime(char *timestr, char *lowstr, char **field, int *ftype, int *numfields, char **endstr)
bool CheckDateTokenTables(void)
void j2date(int jd, int *year, int *month, int *day)
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec, bool EuroDates)
int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec)
char * pgtypes_date_months[]
char * pgtypes_date_weekdays_short[]
void dt2time(double jd, int *hour, int *min, int *sec, fsec_t *fsec)
int DecodeUnits(int field, char *lowtoken, int *val)
int tm2timestamp(struct tm *tm, fsec_t fsec, int *tzp, timestamp *result)
static void const char * fmt