Harmonize parameter names in ecpg code.
[pgsql.git] / src / include / utils / date.h
blob3991da41f0feec865690750fd1e74282d5f9b381
1 /*-------------------------------------------------------------------------
3 * date.h
4 * Definitions for the SQL "date" and "time" types.
7 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/utils/date.h
12 *-------------------------------------------------------------------------
14 #ifndef DATE_H
15 #define DATE_H
17 #include <math.h>
19 #include "datatype/timestamp.h"
20 #include "fmgr.h"
21 #include "pgtime.h"
23 typedef int32 DateADT;
25 typedef int64 TimeADT;
27 typedef struct
29 TimeADT time; /* all time units other than months and years */
30 int32 zone; /* numeric time zone, in seconds */
31 } TimeTzADT;
34 * Infinity and minus infinity must be the max and min values of DateADT.
36 #define DATEVAL_NOBEGIN ((DateADT) PG_INT32_MIN)
37 #define DATEVAL_NOEND ((DateADT) PG_INT32_MAX)
39 #define DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN)
40 #define DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN)
41 #define DATE_NOEND(j) ((j) = DATEVAL_NOEND)
42 #define DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND)
43 #define DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
45 #define MAX_TIME_PRECISION 6
48 * Macros for fmgr-callable functions.
50 * For TimeADT, we make use of the same support routines as for int64.
51 * Therefore TimeADT is pass-by-reference if and only if int64 is!
53 #define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
54 #define DatumGetTimeADT(X) ((TimeADT) DatumGetInt64(X))
55 #define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
57 #define DateADTGetDatum(X) Int32GetDatum(X)
58 #define TimeADTGetDatum(X) Int64GetDatum(X)
59 #define TimeTzADTPGetDatum(X) PointerGetDatum(X)
61 #define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
62 #define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
63 #define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
65 #define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
66 #define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
67 #define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
70 /* date.c */
71 extern int32 anytime_typmod_check(bool istz, int32 typmod);
72 extern double date2timestamp_no_overflow(DateADT dateVal);
73 extern Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow);
74 extern TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow);
75 extern int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2);
76 extern int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2);
78 extern void EncodeSpecialDate(DateADT dt, char *str);
79 extern DateADT GetSQLCurrentDate(void);
80 extern TimeTzADT *GetSQLCurrentTime(int32 typmod);
81 extern TimeADT GetSQLLocalTime(int32 typmod);
82 extern int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec);
83 extern int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp);
84 extern int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result);
85 extern int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result);
86 extern bool time_overflows(int hour, int min, int sec, fsec_t fsec);
87 extern bool float_time_overflows(int hour, int min, double sec);
88 extern void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
90 #endif /* DATE_H */