PostgreSQL Source Code: src/include/utils/date.h Source File

PostgreSQL Source Code git master
date.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * date.h
4 * Definitions for the SQL "date" and "time" types.
5 *
6 *
7 * Portions Copyright (c) 1996-2025, 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 "datatype/timestamp.h"
20#include "fmgr.h"
21#include "pgtime.h"
22
23 typedef int32 DateADT;
24
25 typedef int64 TimeADT;
26
27 typedef struct
28{
29 TimeADT time; /* all time units other than months and years */
30 int32 zone; /* numeric time zone, in seconds */
31} TimeTzADT;
32
33/*
34 * Infinity and minus infinity must be the max and min values of DateADT.
35 */
36 #define DATEVAL_NOBEGIN ((DateADT) PG_INT32_MIN)
37 #define DATEVAL_NOEND ((DateADT) PG_INT32_MAX)
38
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))
44
45 #define MAX_TIME_PRECISION 6
46
47/*
48 * Functions for fmgr-callable functions.
49 *
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!
52 */
53static inline DateADT
54 DatumGetDateADT(Datum X)
55{
56 return (DateADT) DatumGetInt32(X);
57}
58
59static inline TimeADT
60 DatumGetTimeADT(Datum X)
61{
62 return (TimeADT) DatumGetInt64(X);
63}
64
65static inline TimeTzADT *
66 DatumGetTimeTzADTP(Datum X)
67{
68 return (TimeTzADT *) DatumGetPointer(X);
69}
70
71static inline Datum
72 DateADTGetDatum(DateADT X)
73{
74 return Int32GetDatum(X);
75}
76
77static inline Datum
78 TimeADTGetDatum(TimeADT X)
79{
80 return Int64GetDatum(X);
81}
82
83static inline Datum
84 TimeTzADTPGetDatum(const TimeTzADT *X)
85{
86 return PointerGetDatum(X);
87}
88
89 #define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
90 #define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
91 #define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
92
93 #define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
94 #define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
95 #define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
96
97
98/* date.c */
99extern int32 anytime_typmod_check(bool istz, int32 typmod);
100extern double date2timestamp_no_overflow(DateADT dateVal);
101extern Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow);
102extern TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow);
103extern DateADT timestamp2date_opt_overflow(Timestamp timestamp, int *overflow);
104extern DateADT timestamptz2date_opt_overflow(TimestampTz timestamp, int *overflow);
105extern int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2);
106extern int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2);
107
108extern void EncodeSpecialDate(DateADT dt, char *str);
109extern DateADT GetSQLCurrentDate(void);
110extern TimeTzADT *GetSQLCurrentTime(int32 typmod);
111extern TimeADT GetSQLLocalTime(int32 typmod);
112extern int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec);
113extern int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp);
114extern int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result);
115extern int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result);
116extern bool time_overflows(int hour, int min, int sec, fsec_t fsec);
117extern bool float_time_overflows(int hour, int min, double sec);
118extern void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
119
120#endif /* DATE_H */
int64_t int64
Definition: c.h:535
int32_t int32
Definition: c.h:534
int64 Timestamp
Definition: timestamp.h:38
int64 TimestampTz
Definition: timestamp.h:39
int32 fsec_t
Definition: timestamp.h:41
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:808
DateADT timestamp2date_opt_overflow(Timestamp timestamp, int *overflow)
Definition: date.c:1385
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2550
static Datum DateADTGetDatum(DateADT X)
Definition: date.h:72
bool float_time_overflows(int hour, int min, double sec)
Definition: date.c:1598
int32 anytime_typmod_check(bool istz, int32 typmod)
Definition: date.c:72
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1563
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:370
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2410
static TimeTzADT * DatumGetTimeTzADTP(Datum X)
Definition: date.h:66
bool time_overflows(int hour, int min, int sec, fsec_t fsec)
Definition: date.c:1574
int32 DateADT
Definition: date.h:23
static DateADT DatumGetDateADT(Datum X)
Definition: date.h:54
DateADT GetSQLCurrentDate(void)
Definition: date.c:317
static TimeADT DatumGetTimeADT(Datum X)
Definition: date.h:60
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1792
static Datum TimeTzADTPGetDatum(const TimeTzADT *X)
Definition: date.h:84
int64 TimeADT
Definition: date.h:25
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:689
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1635
void EncodeSpecialDate(DateADT dt, char *str)
Definition: date.c:302
DateADT timestamptz2date_opt_overflow(TimestampTz timestamp, int *overflow)
Definition: date.c:1471
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:629
static Datum TimeADTGetDatum(TimeADT X)
Definition: date.h:78
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:888
double date2timestamp_no_overflow(DateADT dateVal)
Definition: date.c:785
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:350
const char * str
static struct pg_tm tm
Definition: localtime.c:104
int64 timestamp
static Datum Int64GetDatum(int64 X)
Definition: postgres.h:403
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:393
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:222
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212
Definition: date.h:28
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30
Definition: pgtime.h:35

AltStyle によって変換されたページ (->オリジナル) /