MobilityDB 1.1
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-2021, 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// MobilityDB
20// #include "datatype/timestamp.h"
21// #include "utils/timestamp_def.h"
22#include "../pgtime.h"
23
24typedef int32 DateADT;
25
26typedef int64 TimeADT;
27
28typedef struct
29{
30 TimeADT time; /* all time units other than months and years */
31 int32 zone; /* numeric time zone, in seconds */
32} TimeTzADT;
33
34/*
35 * Infinity and minus infinity must be the max and min values of DateADT.
36 */
37#define DATEVAL_NOBEGIN ((DateADT) PG_INT32_MIN)
38#define DATEVAL_NOEND ((DateADT) PG_INT32_MAX)
39
40#define DATE_NOBEGIN(j) ((j) = DATEVAL_NOBEGIN)
41#define DATE_IS_NOBEGIN(j) ((j) == DATEVAL_NOBEGIN)
42#define DATE_NOEND(j) ((j) = DATEVAL_NOEND)
43#define DATE_IS_NOEND(j) ((j) == DATEVAL_NOEND)
44#define DATE_NOT_FINITE(j) (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
45
46/*
47 * Macros for fmgr-callable functions.
48 *
49 * For TimeADT, we make use of the same support routines as for int64.
50 * Therefore TimeADT is pass-by-reference if and only if int64 is!
51 */
52#define MAX_TIME_PRECISION 6
53
54#define DatumGetDateADT(X) ((DateADT) DatumGetInt32(X))
55#define DatumGetTimeADT(X) ((TimeADT) DatumGetInt64(X))
56#define DatumGetTimeTzADTP(X) ((TimeTzADT *) DatumGetPointer(X))
57
58#define DateADTGetDatum(X) Int32GetDatum(X)
59#define TimeADTGetDatum(X) Int64GetDatum(X)
60#define TimeTzADTPGetDatum(X) PointerGetDatum(X)
61
62#define PG_GETARG_DATEADT(n) DatumGetDateADT(PG_GETARG_DATUM(n))
63#define PG_GETARG_TIMEADT(n) DatumGetTimeADT(PG_GETARG_DATUM(n))
64#define PG_GETARG_TIMETZADT_P(n) DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
65
66#define PG_RETURN_DATEADT(x) return DateADTGetDatum(x)
67#define PG_RETURN_TIMEADT(x) return TimeADTGetDatum(x)
68#define PG_RETURN_TIMETZADT_P(x) return TimeTzADTPGetDatum(x)
69
70
71/* date.c */
72extern int32 anytime_typmod_check(bool istz, int32 typmod);
73extern double date2timestamp_no_overflow(DateADT dateVal);
74extern Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow);
75extern TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow);
78
79extern void EncodeSpecialDate(DateADT dt, char *str);
83extern int interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec);
84extern int tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span);
85extern int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec);
86extern int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp);
87extern int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result);
88extern int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result);
89extern bool time_overflows(int hour, int min, int sec, fsec_t fsec);
90extern bool float_time_overflows(int hour, int min, double sec);
91extern void AdjustTimeForTypmod(TimeADT *time, int32 typmod);
92
93#endif /* DATE_H */
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
bool float_time_overflows(int hour, int min, double sec)
int32 anytime_typmod_check(bool istz, int32 typmod)
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:60
TimeADT GetSQLLocalTime(int32 typmod)
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
bool time_overflows(int hour, int min, int sec, fsec_t fsec)
Definition: date.c:36
int32 DateADT
Definition: date.h:24
int interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
Definition: timestamp.c:237
DateADT GetSQLCurrentDate(void)
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: pg_types.c:315
int64 TimeADT
Definition: date.h:26
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:75
void EncodeSpecialDate(DateADT dt, char *str)
Definition: datetime.c:3817
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
double date2timestamp_no_overflow(DateADT dateVal)
TimeTzADT * GetSQLCurrentTime(int32 typmod)
int tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span)
Definition: timestamp.c:263
static struct pg_tm tm
Definition: localtime.c:104
int64 Timestamp
Definition: pg_ext_defs.in.h:18
int64 TimestampTz
Definition: pg_ext_defs.in.h:19
int32 fsec_t
Definition: pg_ext_defs.in.h:21
signed int int32
Definition: pg_ext_defs.in.h:8
int32 DateADT
Definition: pg_ext_defs.in.h:16
int64 TimeADT
Definition: pg_ext_defs.in.h:17
long int int64
Definition: pg_ext_defs.in.h:9
Definition: pg_ext_defs.in.h:24
TimeADT time
Definition: date.h:30
int32 zone
Definition: date.h:31
Definition: date.h:29
Definition: pgtime.h:26