Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* timestamp.h
|
2013-04-20 17:04:41 +02:00
|
|
|
* Definitions for the SQL "timestamp" and "interval" types.
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/timestamp.h
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TIMESTAMP_H
|
|
|
|
#define TIMESTAMP_H
|
|
|
|
|
2011-09-09 19:23:41 +02:00
|
|
|
#include "datatype/timestamp.h"
|
2000-06-09 03:11:16 +02:00
|
|
|
#include "fmgr.h"
|
2004-05-21 07:08:06 +02:00
|
|
|
#include "pgtime.h"
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2002-08-04 08:42:18 +02:00
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
/*
|
|
|
|
* Macros for fmgr-callable functions.
|
|
|
|
*
|
2017-02-23 20:04:43 +01:00
|
|
|
* For Timestamp, we make use of the same support routines as for int64.
|
|
|
|
* Therefore Timestamp is pass-by-reference if and only if int64 is!
|
2000-06-09 03:11:16 +02:00
|
|
|
*/
|
2002-04-21 21:52:18 +02:00
|
|
|
#define DatumGetTimestamp(X) ((Timestamp) DatumGetInt64(X))
|
|
|
|
#define DatumGetTimestampTz(X) ((TimestampTz) DatumGetInt64(X))
|
|
|
|
#define DatumGetIntervalP(X) ((Interval *) DatumGetPointer(X))
|
|
|
|
|
|
|
|
#define TimestampGetDatum(X) Int64GetDatum(X)
|
|
|
|
#define TimestampTzGetDatum(X) Int64GetDatum(X)
|
|
|
|
#define IntervalPGetDatum(X) PointerGetDatum(X)
|
|
|
|
|
2008-03-21 02:31:43 +01:00
|
|
|
#define PG_GETARG_TIMESTAMP(n) DatumGetTimestamp(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_GETARG_TIMESTAMPTZ(n) DatumGetTimestampTz(PG_GETARG_DATUM(n))
|
2002-04-21 21:52:18 +02:00
|
|
|
#define PG_GETARG_INTERVAL_P(n) DatumGetIntervalP(PG_GETARG_DATUM(n))
|
|
|
|
|
2008-03-21 02:31:43 +01:00
|
|
|
#define PG_RETURN_TIMESTAMP(x) return TimestampGetDatum(x)
|
|
|
|
#define PG_RETURN_TIMESTAMPTZ(x) return TimestampTzGetDatum(x)
|
2002-04-21 21:52:18 +02:00
|
|
|
#define PG_RETURN_INTERVAL_P(x) return IntervalPGetDatum(x)
|
2002-04-23 17:45:30 +02:00
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2002-08-04 08:42:18 +02:00
|
|
|
#define TIMESTAMP_MASK(b) (1 << (b))
|
|
|
|
#define INTERVAL_MASK(b) (1 << (b))
|
|
|
|
|
|
|
|
/* Macros to handle packing and unpacking the typmod field for intervals */
|
|
|
|
#define INTERVAL_FULL_RANGE (0x7FFF)
|
|
|
|
#define INTERVAL_RANGE_MASK (0x7FFF)
|
|
|
|
#define INTERVAL_FULL_PRECISION (0xFFFF)
|
|
|
|
#define INTERVAL_PRECISION_MASK (0xFFFF)
|
|
|
|
#define INTERVAL_TYPMOD(p,r) ((((r) & INTERVAL_RANGE_MASK) << 16) | ((p) & INTERVAL_PRECISION_MASK))
|
|
|
|
#define INTERVAL_PRECISION(t) ((t) & INTERVAL_PRECISION_MASK)
|
|
|
|
#define INTERVAL_RANGE(t) (((t) >> 16) & INTERVAL_RANGE_MASK)
|
|
|
|
|
2008-01-23 22:26:13 +01:00
|
|
|
#define TimestampTzPlusMilliseconds(tz,ms) ((tz) + ((ms) * (int64) 1000))
|
2006-06-21 00:52:00 +02:00
|
|
|
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2005-06-30 00:51:57 +02:00
|
|
|
/* Set at postmaster start */
|
|
|
|
extern TimestampTz PgStartTime;
|
2009-06-11 16:49:15 +02:00
|
|
|
|
2008-05-04 23:13:36 +02:00
|
|
|
/* Set at configuration reload */
|
|
|
|
extern TimestampTz PgReloadTime;
|
2005-06-30 00:51:57 +02:00
|
|
|
|
|
|
|
|
2000-06-09 03:11:16 +02:00
|
|
|
/* Internal routines (not fmgr-callable) */
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2016-08-17 02:33:01 +02:00
|
|
|
extern int32 anytimestamp_typmod_check(bool istz, int32 typmod);
|
|
|
|
|
2005-06-30 00:51:57 +02:00
|
|
|
extern TimestampTz GetCurrentTimestamp(void);
|
2016-08-17 02:33:01 +02:00
|
|
|
extern TimestampTz GetSQLCurrentTimestamp(int32 typmod);
|
|
|
|
extern Timestamp GetSQLLocalTimestamp(int32 typmod);
|
2006-06-21 00:52:00 +02:00
|
|
|
extern void TimestampDifference(TimestampTz start_time, TimestampTz stop_time,
|
2006-10-04 02:30:14 +02:00
|
|
|
long *secs, int *microsecs);
|
2007-04-30 05:23:49 +02:00
|
|
|
extern bool TimestampDifferenceExceeds(TimestampTz start_time,
|
2007-11-15 22:14:46 +01:00
|
|
|
TimestampTz stop_time,
|
|
|
|
int msec);
|
2006-06-21 00:52:00 +02:00
|
|
|
|
2008-02-17 03:09:32 +01:00
|
|
|
extern TimestampTz time_t_to_timestamptz(pg_time_t tm);
|
|
|
|
extern pg_time_t timestamptz_to_time_t(TimestampTz t);
|
2005-08-12 20:23:56 +02:00
|
|
|
|
2007-04-30 23:01:53 +02:00
|
|
|
extern const char *timestamptz_to_str(TimestampTz t);
|
|
|
|
|
2017-06-21 20:39:04 +02:00
|
|
|
extern int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *dt);
|
|
|
|
extern int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm,
|
2012-03-15 20:17:19 +01:00
|
|
|
fsec_t *fsec, const char **tzn, pg_tz *attimezone);
|
2002-04-21 21:52:18 +02:00
|
|
|
extern void dt2time(Timestamp dt, int *hour, int *min, int *sec, fsec_t *fsec);
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2017-06-21 20:39:04 +02:00
|
|
|
extern int interval2tm(Interval span, struct pg_tm *tm, fsec_t *fsec);
|
|
|
|
extern int tm2interval(struct pg_tm *tm, fsec_t fsec, Interval *span);
|
2001-09-06 05:22:42 +02:00
|
|
|
|
2001-09-28 10:09:14 +02:00
|
|
|
extern Timestamp SetEpochTimestamp(void);
|
2017-06-21 20:39:04 +02:00
|
|
|
extern void GetEpochTime(struct pg_tm *tm);
|
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:26:26 +01:00
|
|
|
|
2004-02-14 21:16:18 +01:00
|
|
|
extern int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2);
|
2004-08-29 07:07:03 +02:00
|
|
|
|
2004-02-14 21:16:18 +01:00
|
|
|
/* timestamp comparison works for timestamptz also */
|
|
|
|
#define timestamptz_cmp_internal(dt1,dt2) timestamp_cmp_internal(dt1, dt2)
|
|
|
|
|
2007-02-16 04:39:46 +01:00
|
|
|
extern int isoweek2j(int year, int week);
|
2007-11-15 22:14:46 +01:00
|
|
|
extern void isoweek2date(int woy, int *year, int *mon, int *mday);
|
2012-09-04 04:52:34 +02:00
|
|
|
extern void isoweekdate2date(int isoweek, int wday, int *year, int *mon, int *mday);
|
2000-08-29 06:41:48 +02:00
|
|
|
extern int date2isoweek(int year, int mon, int mday);
|
2003-12-25 04:36:24 +01:00
|
|
|
extern int date2isoyear(int year, int mon, int mday);
|
2007-02-16 04:39:46 +01:00
|
|
|
extern int date2isoyearday(int year, int mon, int mday);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* TIMESTAMP_H */
|