PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
date.h File Reference
#include <math.h>
#include "fmgr.h"
Include dependency graph for date.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TimeTzADT
 

Macros

#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)
 
#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)
 
#define DATE_NOBEGIN(j)   ((j) = DATEVAL_NOBEGIN)
 
#define DATE_IS_NOBEGIN(j)   ((j) == DATEVAL_NOBEGIN)
 
#define DATE_NOEND(j)   ((j) = DATEVAL_NOEND)
 
#define DATE_IS_NOEND(j)   ((j) == DATEVAL_NOEND)
 
#define DATE_NOT_FINITE(j)   (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
 
#define MAX_TIME_PRECISION   6
 
#define DatumGetDateADT(X)   ((DateADT) DatumGetInt32(X))
 
#define DatumGetTimeADT(X)   ((TimeADT) DatumGetInt64(X))
 
#define DatumGetTimeTzADTP(X)   ((TimeTzADT *) DatumGetPointer(X))
 
#define DateADTGetDatum(X)   Int32GetDatum(X)
 
#define TimeADTGetDatum(X)   Int64GetDatum(X)
 
#define TimeTzADTPGetDatum(X)   PointerGetDatum(X)
 
#define PG_GETARG_DATEADT(n)   DatumGetDateADT(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TIMEADT(n)   DatumGetTimeADT(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TIMETZADT_P(n)   DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_DATEADT(x)   return DateADTGetDatum(x)
 
#define PG_RETURN_TIMEADT(x)   return TimeADTGetDatum(x)
 
#define PG_RETURN_TIMETZADT_P(x)   return TimeTzADTPGetDatum(x)
 

Typedefs

typedef int32 DateADT
 
typedef int64 TimeADT
 

Functions

int32 anytime_typmod_check (bool istz, int32 typmod)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
void EncodeSpecialDate (DateADT dt, char *str)
 
DateADT GetSQLCurrentDate (void)
 
TimeTzADTGetSQLCurrentTime (int32 typmod)
 
TimeADT GetSQLLocalTime (int32 typmod)
 

Macro Definition Documentation

#define DATE_IS_NOBEGIN (   j)    ((j) == DATEVAL_NOBEGIN)
#define DATE_IS_NOEND (   j)    ((j) == DATEVAL_NOEND)
#define DATE_NOBEGIN (   j)    ((j) = DATEVAL_NOBEGIN)

Definition at line 38 of file date.h.

Referenced by abstime_date(), date_in(), timestamp_date(), and timestamptz_date().

#define DATE_NOEND (   j)    ((j) = DATEVAL_NOEND)

Definition at line 40 of file date.h.

Referenced by abstime_date(), date_in(), timestamp_date(), and timestamptz_date().

#define DATE_NOT_FINITE (   j)    (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)

Definition at line 35 of file date.h.

Referenced by leftmostvalue_date().

#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)

Definition at line 36 of file date.h.

#define DatumGetDateADT (   X)    ((DateADT) DatumGetInt32(X))
#define DatumGetTimeADT (   X)    ((TimeADT) DatumGetInt64(X))

Definition at line 53 of file date.h.

Referenced by convert_timevalue_to_scalar(), and gbt_num_compress().

#define DatumGetTimeTzADTP (   X)    ((TimeTzADT *) DatumGetPointer(X))

Definition at line 54 of file date.h.

Referenced by convert_timevalue_to_scalar(), and gbt_timetz_compress().

#define MAX_TIME_PRECISION   6

Definition at line 50 of file date.h.

Referenced by AdjustTimeForTypmod(), anytime_typmod_check(), EncodeTimeOnly(), and time_transform().

#define PG_RETURN_DATEADT (   x)    return DateADTGetDatum(x)
#define TimeADTGetDatum (   X)    Int64GetDatum(X)

Definition at line 57 of file date.h.

Referenced by ExecEvalSQLValueFunction(), gbt_num_fetch(), and leftmostvalue_time().

#define TimeTzADTPGetDatum (   X)    PointerGetDatum(X)

Definition at line 58 of file date.h.

Referenced by ExecEvalSQLValueFunction(), and leftmostvalue_timetz().

Typedef Documentation

Definition at line 22 of file date.h.

Definition at line 24 of file date.h.

Function Documentation

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 74 of file date.c.

References ereport, errcode(), errmsg(), ERROR, MAX_TIME_PRECISION, and WARNING.

Referenced by anytime_typmodin(), and transformSQLValueFunction().

75 {
76  if (typmod < 0)
77  ereport(ERROR,
78  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
79  errmsg("TIME(%d)%s precision must not be negative",
80  typmod, (istz ? " WITH TIME ZONE" : ""))));
81  if (typmod > MAX_TIME_PRECISION)
82  {
84  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
85  errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
86  typmod, (istz ? " WITH TIME ZONE" : ""),
88  typmod = MAX_TIME_PRECISION;
89  }
90 
91  return typmod;
92 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define MAX_TIME_PRECISION
Definition: date.h:50
double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 658 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

659 {
660  double result;
661 
662  if (DATE_IS_NOBEGIN(dateVal))
663  result = -DBL_MAX;
664  else if (DATE_IS_NOEND(dateVal))
665  result = DBL_MAX;
666  else
667  {
668  /* date is days since 2000, timestamp is microseconds since same... */
669  result = dateVal * (double) USECS_PER_DAY;
670  }
671 
672  return result;
673 }
#define DATE_IS_NOEND(j)
Definition: date.h:41
#define USECS_PER_DAY
Definition: timestamp.h:91
#define DATE_IS_NOBEGIN(j)
Definition: date.h:39
void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 299 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, EARLY, elog, ERROR, and LATE.

Referenced by date_out(), datum_to_json(), and datum_to_jsonb().

300 {
301  if (DATE_IS_NOBEGIN(dt))
302  strcpy(str, EARLY);
303  else if (DATE_IS_NOEND(dt))
304  strcpy(str, LATE);
305  else /* shouldn't happen */
306  elog(ERROR, "invalid argument for EncodeSpecialDate");
307 }
#define DATE_IS_NOEND(j)
Definition: date.h:41
#define LATE
Definition: datetime.h:41
#define ERROR
Definition: elog.h:43
#define DATE_IS_NOBEGIN(j)
Definition: date.h:39
#define elog
Definition: elog.h:219
#define EARLY
Definition: datetime.h:40
DateADT GetSQLCurrentDate ( void  )

Definition at line 314 of file date.c.

References date2j(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), NULL, POSTGRES_EPOCH_JDATE, timestamp2tm(), tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by ExecEvalSQLValueFunction().

315 {
316  TimestampTz ts;
317  struct pg_tm tt,
318  *tm = &tt;
319  fsec_t fsec;
320  int tz;
321 
323 
324  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
325  ereport(ERROR,
326  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
327  errmsg("timestamp out of range")));
328 
329  return date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
330 }
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1757
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:103
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:122
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:708
int date2j(int y, int m, int d)
Definition: datetime.c:292
#define NULL
Definition: c.h:229
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
TimeTzADT* GetSQLCurrentTime ( int32  typmod)

Definition at line 336 of file date.c.

References AdjustTimeForTypmod(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), NULL, palloc(), TimeTzADT::time, timestamp2tm(), tm, and tm2timetz().

Referenced by ExecEvalSQLValueFunction().

337 {
338  TimeTzADT *result;
339  TimestampTz ts;
340  struct pg_tm tt,
341  *tm = &tt;
342  fsec_t fsec;
343  int tz;
344 
346 
347  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
348  ereport(ERROR,
349  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
350  errmsg("timestamp out of range")));
351 
352  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
353  tm2timetz(tm, fsec, tz, result);
354  AdjustTimeForTypmod(&(result->time), typmod);
355  return result;
356 }
TimeADT time
Definition: date.h:28
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1757
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:103
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define ereport(elevel, rest)
Definition: elog.h:122
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:708
#define NULL
Definition: c.h:229
static int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:1937
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: date.h:26
TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 362 of file date.c.

References AdjustTimeForTypmod(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), NULL, timestamp2tm(), tm, and tm2time().

Referenced by ExecEvalSQLValueFunction().

363 {
364  TimeADT result;
365  TimestampTz ts;
366  struct pg_tm tt,
367  *tm = &tt;
368  fsec_t fsec;
369  int tz;
370 
372 
373  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
374  ereport(ERROR,
375  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
376  errmsg("timestamp out of range")));
377 
378  tm2time(tm, fsec, &result);
379  AdjustTimeForTypmod(&result, typmod);
380  return result;
381 }
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1757
static int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1238
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:103
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define ereport(elevel, rest)
Definition: elog.h:122
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:708
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797