MobilityDB 1.1
timestamp.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * timestamp.h
4 * Definitions for the SQL "timestamp" and "interval" types.
5 *
6 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/utils/timestamp.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef TIMESTAMP_H
14#define TIMESTAMP_H
15
16// MobilityDB
17// #include "datatype/timestamp.h"
18#include "utils/timestamp_def.h"
19#include "pgtime.h"
20
21/*
22 * Macros for fmgr-callable functions.
23 *
24 * For Timestamp, we make use of the same support routines as for int64.
25 * Therefore Timestamp is pass-by-reference if and only if int64 is!
26 */
27#define DatumGetTimestamp(X) ((Timestamp) DatumGetInt64(X))
28#define DatumGetTimestampTz(X) ((TimestampTz) DatumGetInt64(X))
29#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
30
31#define TimestampGetDatum(X) Int64GetDatum(X)
32#define TimestampTzGetDatum(X) Int64GetDatum(X)
33#define IntervalPGetDatum(X) PointerGetDatum(X)
34
35#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n))
36#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n))
37#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n))
38
39#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x)
40#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
41#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
42
43
44#define TIMESTAMP_MASK(b) (1 << (b))
45#define INTERVAL_MASK(b) (1 << (b))
46
47/* Macros to handle packing and unpacking the typmod field for intervals */
48#define INTERVAL_FULL_RANGE (0x7FFF)
49#define INTERVAL_RANGE_MASK (0x7FFF)
50#define INTERVAL_FULL_PRECISION (0xFFFF)
51#define INTERVAL_PRECISION_MASK (0xFFFF)
52#define INTERVAL_TYPMOD(p,r) ((((r) & INTERVAL_RANGE_MASK) << 16) | ((p) & INTERVAL_PRECISION_MASK))
53#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK)
54#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK)
55
56#define TimestampTzPlusMilliseconds(tz,ms) ((tz) + ((ms) * (int64) 1000))
57
58/* Set at postmaster start */
60
61/* Set at configuration reload */
63
64/* Internal routines (not fmgr-callable) */
65
66extern int32 anytimestamp_typmod_check(bool istz, int32 typmod);
67
71extern void TimestampDifference(TimestampTz start_time, TimestampTz stop_time,
72 long *secs, int *microsecs);
74 TimestampTz stop_time);
76 TimestampTz stop_time,
77 int msec);
78
81
82extern const char *timestamptz_to_str(TimestampTz t);
83
84extern int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *dt);
85extern int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm,
86 fsec_t *fsec, const char **tzn, pg_tz *attimezone);
87extern void dt2time(Timestamp dt, int *hour, int *min, int *sec, fsec_t *fsec);
88
89extern int interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec);
90extern int tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span);
91
92extern Timestamp SetEpochTimestamp(void);
93extern void GetEpochTime(struct pg_tm *tm);
94
95extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2);
96
97/* timestamp comparison works for timestamptz also */
98#define timestamptz_cmp_internal(dt1,dt2) timestamp_cmp_internal(dt1, dt2)
99
101 int *overflow);
103 TimestampTz dt2);
104
105extern int isoweek2j(int year, int week);
106extern void isoweek2date(int woy, int *year, int *mon, int *mday);
107extern void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday);
108extern int date2isoweek(int year, int mon, int mday);
109extern int date2isoyear(int year, int mon, int mday);
110extern int date2isoyearday(int year, int mon, int mday);
111
113
114#endif /* TIMESTAMP_H */
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
int64 pg_time_t
Definition: pgtime.h:23
Definition: pg_ext_defs.in.h:24
Definition: pgtime.h:26
Definition: pgtz.h:66
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:338
long TimestampDifferenceMilliseconds(TimestampTz start_time, TimestampTz stop_time)
void isoweek2date(int woy, int *year, int *mon, int *mday)
void GetEpochTime(struct pg_tm *tm)
Definition: timestamp.c:296
int isoweek2j(int year, int week)
TimestampTz time_t_to_timestamptz(pg_time_t tm)
void dt2time(Timestamp dt, int *hour, int *min, int *sec, fsec_t *fsec)
Definition: timestamp.c:69
int date2isoweek(int year, int mon, int mday)
Timestamp SetEpochTimestamp(void)
Definition: timestamp.c:318
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *dt)
Definition: timestamp.c:190
TimestampTz timestamp2timestamptz_opt_overflow(Timestamp timestamp, int *overflow)
int date2isoyearday(int year, int mon, int mday)
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
bool TimestampTimestampTzRequiresRewrite(void)
void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday)
int32 timestamp_cmp_timestamptz_internal(Timestamp timestampVal, TimestampTz dt2)
bool TimestampDifferenceExceeds(TimestampTz start_time, TimestampTz stop_time, int msec)
TimestampTz PgReloadTime
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:95
int32 anytimestamp_typmod_check(bool istz, int32 typmod)
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:54
const char * timestamptz_to_str(TimestampTz t)
Timestamp GetSQLLocalTimestamp(int32 typmod)
int interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec)
Definition: timestamp.c:237
TimestampTz PgStartTime
pg_time_t timestamptz_to_time_t(TimestampTz t)
int tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span)
Definition: timestamp.c:263
int date2isoyear(int year, int mon, int mday)
TimestampTz GetSQLCurrentTimestamp(int32 typmod)