PostgreSQL Source Code  git master
date.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <float.h>
#include <time.h>
#include "access/hash.h"
#include "access/xact.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "parser/scansup.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.h"
#include "utils/nabstime.h"
#include "utils/sortsupport.h"
Include dependency graph for date.c:

Go to the source code of this file.

Macros

#define TIMEADT_GT(t1, t2)   (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
 
#define TIMEADT_LT(t1, t2)   (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
 
#define TIMETZ_GT(t1, t2)   DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
 
#define TIMETZ_LT(t1, t2)   DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
 

Functions

static int time2tm (TimeADT time, struct pg_tm *tm, fsec_t *fsec)
 
static int timetz2tm (TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
 
static int tm2time (struct pg_tm *tm, fsec_t fsec, TimeADT *result)
 
static int tm2timetz (struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
 
static void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 
static int32 anytime_typmodin (bool istz, ArrayType *ta)
 
int32 anytime_typmod_check (bool istz, int32 typmod)
 
static char * anytime_typmodout (bool istz, int32 typmod)
 
Datum date_in (PG_FUNCTION_ARGS)
 
Datum date_out (PG_FUNCTION_ARGS)
 
Datum date_recv (PG_FUNCTION_ARGS)
 
Datum date_send (PG_FUNCTION_ARGS)
 
Datum make_date (PG_FUNCTION_ARGS)
 
void EncodeSpecialDate (DateADT dt, char *str)
 
DateADT GetSQLCurrentDate (void)
 
TimeTzADTGetSQLCurrentTime (int32 typmod)
 
TimeADT GetSQLLocalTime (int32 typmod)
 
Datum date_eq (PG_FUNCTION_ARGS)
 
Datum date_ne (PG_FUNCTION_ARGS)
 
Datum date_lt (PG_FUNCTION_ARGS)
 
Datum date_le (PG_FUNCTION_ARGS)
 
Datum date_gt (PG_FUNCTION_ARGS)
 
Datum date_ge (PG_FUNCTION_ARGS)
 
Datum date_cmp (PG_FUNCTION_ARGS)
 
static int date_fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum date_sortsupport (PG_FUNCTION_ARGS)
 
Datum date_finite (PG_FUNCTION_ARGS)
 
Datum date_larger (PG_FUNCTION_ARGS)
 
Datum date_smaller (PG_FUNCTION_ARGS)
 
Datum date_mi (PG_FUNCTION_ARGS)
 
Datum date_pli (PG_FUNCTION_ARGS)
 
Datum date_mii (PG_FUNCTION_ARGS)
 
static Timestamp date2timestamp (DateADT dateVal)
 
static TimestampTz date2timestamptz (DateADT dateVal)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
Datum date_eq_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamp (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_le_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ge_timestamp (PG_FUNCTION_ARGS)
 
Datum date_cmp_timestamp (PG_FUNCTION_ARGS)
 
Datum date_eq_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_le_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_ge_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_cmp_timestamptz (PG_FUNCTION_ARGS)
 
Datum timestamp_eq_date (PG_FUNCTION_ARGS)
 
Datum timestamp_ne_date (PG_FUNCTION_ARGS)
 
Datum timestamp_lt_date (PG_FUNCTION_ARGS)
 
Datum timestamp_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamp_le_date (PG_FUNCTION_ARGS)
 
Datum timestamp_ge_date (PG_FUNCTION_ARGS)
 
Datum timestamp_cmp_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_eq_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_ne_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_lt_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_le_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_ge_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_cmp_date (PG_FUNCTION_ARGS)
 
Datum date_pl_interval (PG_FUNCTION_ARGS)
 
Datum date_mi_interval (PG_FUNCTION_ARGS)
 
Datum date_timestamp (PG_FUNCTION_ARGS)
 
Datum timestamp_date (PG_FUNCTION_ARGS)
 
Datum date_timestamptz (PG_FUNCTION_ARGS)
 
Datum timestamptz_date (PG_FUNCTION_ARGS)
 
Datum abstime_date (PG_FUNCTION_ARGS)
 
Datum time_in (PG_FUNCTION_ARGS)
 
Datum time_out (PG_FUNCTION_ARGS)
 
Datum time_recv (PG_FUNCTION_ARGS)
 
Datum time_send (PG_FUNCTION_ARGS)
 
Datum timetypmodin (PG_FUNCTION_ARGS)
 
Datum timetypmodout (PG_FUNCTION_ARGS)
 
Datum make_time (PG_FUNCTION_ARGS)
 
Datum time_transform (PG_FUNCTION_ARGS)
 
Datum time_scale (PG_FUNCTION_ARGS)
 
Datum time_eq (PG_FUNCTION_ARGS)
 
Datum time_ne (PG_FUNCTION_ARGS)
 
Datum time_lt (PG_FUNCTION_ARGS)
 
Datum time_le (PG_FUNCTION_ARGS)
 
Datum time_gt (PG_FUNCTION_ARGS)
 
Datum time_ge (PG_FUNCTION_ARGS)
 
Datum time_cmp (PG_FUNCTION_ARGS)
 
Datum time_hash (PG_FUNCTION_ARGS)
 
Datum time_hash_extended (PG_FUNCTION_ARGS)
 
Datum time_larger (PG_FUNCTION_ARGS)
 
Datum time_smaller (PG_FUNCTION_ARGS)
 
Datum overlaps_time (PG_FUNCTION_ARGS)
 
Datum timestamp_time (PG_FUNCTION_ARGS)
 
Datum timestamptz_time (PG_FUNCTION_ARGS)
 
Datum datetime_timestamp (PG_FUNCTION_ARGS)
 
Datum time_interval (PG_FUNCTION_ARGS)
 
Datum interval_time (PG_FUNCTION_ARGS)
 
Datum time_mi_time (PG_FUNCTION_ARGS)
 
Datum time_pl_interval (PG_FUNCTION_ARGS)
 
Datum time_mi_interval (PG_FUNCTION_ARGS)
 
Datum time_part (PG_FUNCTION_ARGS)
 
Datum timetz_in (PG_FUNCTION_ARGS)
 
Datum timetz_out (PG_FUNCTION_ARGS)
 
Datum timetz_recv (PG_FUNCTION_ARGS)
 
Datum timetz_send (PG_FUNCTION_ARGS)
 
Datum timetztypmodin (PG_FUNCTION_ARGS)
 
Datum timetztypmodout (PG_FUNCTION_ARGS)
 
Datum timetz_scale (PG_FUNCTION_ARGS)
 
static int timetz_cmp_internal (TimeTzADT *time1, TimeTzADT *time2)
 
Datum timetz_eq (PG_FUNCTION_ARGS)
 
Datum timetz_ne (PG_FUNCTION_ARGS)
 
Datum timetz_lt (PG_FUNCTION_ARGS)
 
Datum timetz_le (PG_FUNCTION_ARGS)
 
Datum timetz_gt (PG_FUNCTION_ARGS)
 
Datum timetz_ge (PG_FUNCTION_ARGS)
 
Datum timetz_cmp (PG_FUNCTION_ARGS)
 
Datum timetz_hash (PG_FUNCTION_ARGS)
 
Datum timetz_hash_extended (PG_FUNCTION_ARGS)
 
Datum timetz_larger (PG_FUNCTION_ARGS)
 
Datum timetz_smaller (PG_FUNCTION_ARGS)
 
Datum timetz_pl_interval (PG_FUNCTION_ARGS)
 
Datum timetz_mi_interval (PG_FUNCTION_ARGS)
 
Datum overlaps_timetz (PG_FUNCTION_ARGS)
 
Datum timetz_time (PG_FUNCTION_ARGS)
 
Datum time_timetz (PG_FUNCTION_ARGS)
 
Datum timestamptz_timetz (PG_FUNCTION_ARGS)
 
Datum datetimetz_timestamptz (PG_FUNCTION_ARGS)
 
Datum timetz_part (PG_FUNCTION_ARGS)
 
Datum timetz_zone (PG_FUNCTION_ARGS)
 
Datum timetz_izone (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ TIMEADT_GT

#define TIMEADT_GT (   t1,
  t2 
)    (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))

Referenced by overlaps_time().

◆ TIMEADT_LT

#define TIMEADT_LT (   t1,
  t2 
)    (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))

Referenced by overlaps_time().

◆ TIMETZ_GT

#define TIMETZ_GT (   t1,
  t2 
)    DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))

Referenced by overlaps_timetz().

◆ TIMETZ_LT

#define TIMETZ_LT (   t1,
  t2 
)    DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))

Referenced by overlaps_timetz().

Function Documentation

◆ abstime_date()

Datum abstime_date ( PG_FUNCTION_ARGS  )

Definition at line 1151 of file date.c.

References abstime2tm(), date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, IS_VALID_DATE, IS_VALID_JULIAN, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

1152 {
1153  AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0);
1154  DateADT result;
1155  struct pg_tm tt,
1156  *tm = &tt;
1157  int tz;
1158 
1159  switch (abstime)
1160  {
1161  case INVALID_ABSTIME:
1162  ereport(ERROR,
1163  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1164  errmsg("cannot convert reserved abstime value to date")));
1165  result = 0; /* keep compiler quiet */
1166  break;
1167 
1168  case NOSTART_ABSTIME:
1169  DATE_NOBEGIN(result);
1170  break;
1171 
1172  case NOEND_ABSTIME:
1173  DATE_NOEND(result);
1174  break;
1175 
1176  default:
1177  abstime2tm(abstime, &tz, tm, NULL);
1178  /* Prevent overflow in Julian-day routines */
1179  if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
1180  ereport(ERROR,
1181  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1182  errmsg("abstime out of range for date")));
1183  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1184  /* Now check for just-out-of-range dates */
1185  if (!IS_VALID_DATE(result))
1186  ereport(ERROR,
1187  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1188  errmsg("abstime out of range for date")));
1189  break;
1190  }
1191 
1192  PG_RETURN_DATEADT(result);
1193 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define NOSTART_ABSTIME
Definition: nabstime.h:78
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define DATE_NOBEGIN(j)
Definition: date.h:38
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
#define INVALID_ABSTIME
Definition: nabstime.h:76
#define IS_VALID_JULIAN(y, m, d)
Definition: timestamp.h:155
int32 AbsoluteTime
Definition: nabstime.h:36
#define ereport(elevel, rest)
Definition: elog.h:122
void abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm *tm, char **tzn)
Definition: nabstime.c:99
int date2j(int y, int m, int d)
Definition: datetime.c:292
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:64
#define NOEND_ABSTIME
Definition: nabstime.h:77
#define DATE_NOEND(j)
Definition: date.h:40

◆ AdjustTimeForTypmod()

static void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)
static

Definition at line 1404 of file date.c.

References MAX_TIME_PRECISION.

Referenced by GetSQLCurrentTime(), GetSQLLocalTime(), time_in(), time_recv(), time_scale(), timetz_in(), timetz_recv(), and timetz_scale().

1405 {
1406  static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1407  INT64CONST(1000000),
1408  INT64CONST(100000),
1409  INT64CONST(10000),
1410  INT64CONST(1000),
1411  INT64CONST(100),
1412  INT64CONST(10),
1413  INT64CONST(1)
1414  };
1415 
1416  static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1417  INT64CONST(500000),
1418  INT64CONST(50000),
1419  INT64CONST(5000),
1420  INT64CONST(500),
1421  INT64CONST(50),
1422  INT64CONST(5),
1423  INT64CONST(0)
1424  };
1425 
1426  if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1427  {
1428  if (*time >= INT64CONST(0))
1429  *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1430  TimeScales[typmod];
1431  else
1432  *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1433  TimeScales[typmod]);
1434  }
1435 }
#define MAX_TIME_PRECISION
Definition: date.h:50

◆ anytime_typmod_check()

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

◆ anytime_typmodin()

static int32 anytime_typmodin ( bool  istz,
ArrayType ta 
)
static

Definition at line 53 of file date.c.

References anytime_typmod_check(), ArrayGetIntegerTypmods(), ereport, errcode(), errmsg(), and ERROR.

Referenced by timetypmodin(), and timetztypmodin().

54 {
55  int32 *tl;
56  int n;
57 
58  tl = ArrayGetIntegerTypmods(ta, &n);
59 
60  /*
61  * we're not too tense about good error message here because grammar
62  * shouldn't allow wrong number of modifiers for TIME
63  */
64  if (n != 1)
65  ereport(ERROR,
66  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
67  errmsg("invalid type modifier")));
68 
69  return anytime_typmod_check(istz, tl[0]);
70 }
int32 anytime_typmod_check(bool istz, int32 typmod)
Definition: date.c:74
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Definition: arrayutils.c:200
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:284
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ anytime_typmodout()

static char* anytime_typmodout ( bool  istz,
int32  typmod 
)
static

Definition at line 96 of file date.c.

References psprintf().

Referenced by timetypmodout(), and timetztypmodout().

97 {
98  const char *tz = istz ? " with time zone" : " without time zone";
99 
100  if (typmod >= 0)
101  return psprintf("(%d)%s", (int) typmod, tz);
102  else
103  return psprintf("%s", tz);
104 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46

◆ date2timestamp()

static Timestamp date2timestamp ( DateADT  dateVal)
static

Definition at line 574 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, ereport, errcode(), errmsg(), ERROR, POSTGRES_EPOCH_JDATE, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, and USECS_PER_DAY.

Referenced by date_cmp_timestamp(), date_eq_timestamp(), date_ge_timestamp(), date_gt_timestamp(), date_le_timestamp(), date_lt_timestamp(), date_mi_interval(), date_ne_timestamp(), date_pl_interval(), date_timestamp(), datetime_timestamp(), timestamp_cmp_date(), timestamp_eq_date(), timestamp_ge_date(), timestamp_gt_date(), timestamp_le_date(), timestamp_lt_date(), and timestamp_ne_date().

575 {
576  Timestamp result;
577 
578  if (DATE_IS_NOBEGIN(dateVal))
579  TIMESTAMP_NOBEGIN(result);
580  else if (DATE_IS_NOEND(dateVal))
581  TIMESTAMP_NOEND(result);
582  else
583  {
584  /*
585  * Date's range is wider than timestamp's, so check for boundaries.
586  * Since dates have the same minimum values as timestamps, only upper
587  * boundary need be checked for overflow.
588  */
589  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
590  ereport(ERROR,
591  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
592  errmsg("date out of range for timestamp")));
593 
594  /* date is days since 2000, timestamp is microseconds since same... */
595  result = dateVal * USECS_PER_DAY;
596  }
597 
598  return result;
599 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:41
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:122
int64 Timestamp
Definition: timestamp.h:38
#define DATE_IS_NOBEGIN(j)
Definition: date.h:39
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ date2timestamp_no_overflow()

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

◆ date2timestamptz()

static TimestampTz date2timestamptz ( DateADT  dateVal)
static

Definition at line 602 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, DetermineTimeZoneOffset(), ereport, errcode(), errmsg(), ERROR, IS_VALID_TIMESTAMP, j2date(), POSTGRES_EPOCH_JDATE, session_timezone, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by date_cmp_timestamptz(), date_eq_timestamptz(), date_ge_timestamptz(), date_gt_timestamptz(), date_le_timestamptz(), date_lt_timestamptz(), date_ne_timestamptz(), date_timestamptz(), timestamptz_cmp_date(), timestamptz_eq_date(), timestamptz_ge_date(), timestamptz_gt_date(), timestamptz_le_date(), timestamptz_lt_date(), and timestamptz_ne_date().

603 {
604  TimestampTz result;
605  struct pg_tm tt,
606  *tm = &tt;
607  int tz;
608 
609  if (DATE_IS_NOBEGIN(dateVal))
610  TIMESTAMP_NOBEGIN(result);
611  else if (DATE_IS_NOEND(dateVal))
612  TIMESTAMP_NOEND(result);
613  else
614  {
615  /*
616  * Date's range is wider than timestamp's, so check for boundaries.
617  * Since dates have the same minimum values as timestamps, only upper
618  * boundary need be checked for overflow.
619  */
620  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
621  ereport(ERROR,
622  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
623  errmsg("date out of range for timestamp")));
624 
625  j2date(dateVal + POSTGRES_EPOCH_JDATE,
626  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
627  tm->tm_hour = 0;
628  tm->tm_min = 0;
629  tm->tm_sec = 0;
631 
632  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
633 
634  /*
635  * Since it is possible to go beyond allowed timestamptz range because
636  * of time zone, check for allowed timestamp range after adding tz.
637  */
638  if (!IS_VALID_TIMESTAMP(result))
639  ereport(ERROR,
640  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
641  errmsg("date out of range for timestamp")));
642  }
643 
644  return result;
645 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:41
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
#define USECS_PER_SEC
Definition: timestamp.h:94
int64 TimestampTz
Definition: timestamp.h:39
int tm_hour
Definition: pgtime.h:29
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1471
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:122
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:317
#define DATE_IS_NOBEGIN(j)
Definition: date.h:39
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:195
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
pg_tz * session_timezone
Definition: pgtz.c:28
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ date_cmp()

Datum date_cmp ( PG_FUNCTION_ARGS  )

Definition at line 443 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_INT32.

Referenced by gbt_datekey_cmp(), and leftmostvalue_date().

444 {
445  DateADT dateVal1 = PG_GETARG_DATEADT(0);
446  DateADT dateVal2 = PG_GETARG_DATEADT(1);
447 
448  if (dateVal1 < dateVal2)
449  PG_RETURN_INT32(-1);
450  else if (dateVal1 > dateVal2)
451  PG_RETURN_INT32(1);
452  PG_RETURN_INT32(0);
453 }
int32 DateADT
Definition: date.h:22
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_DATEADT(n)
Definition: date.h:60

◆ date_cmp_timestamp()

Datum date_cmp_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 753 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_INT32, and timestamp_cmp_internal().

754 {
755  DateADT dateVal = PG_GETARG_DATEADT(0);
757  Timestamp dt1;
758 
759  dt1 = date2timestamp(dateVal);
760 
762 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 837 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_INT32, and timestamptz_cmp_internal.

838 {
839  DateADT dateVal = PG_GETARG_DATEADT(0);
841  TimestampTz dt1;
842 
843  dt1 = date2timestamptz(dateVal);
844 
846 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_eq()

Datum date_eq ( PG_FUNCTION_ARGS  )

Definition at line 389 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dateeq().

390 {
391  DateADT dateVal1 = PG_GETARG_DATEADT(0);
392  DateADT dateVal2 = PG_GETARG_DATEADT(1);
393 
394  PG_RETURN_BOOL(dateVal1 == dateVal2);
395 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_eq_timestamp()

Datum date_eq_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 681 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

682 {
683  DateADT dateVal = PG_GETARG_DATEADT(0);
685  Timestamp dt1;
686 
687  dt1 = date2timestamp(dateVal);
688 
689  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
690 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_eq_timestamptz()

Datum date_eq_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 765 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

766 {
767  DateADT dateVal = PG_GETARG_DATEADT(0);
769  TimestampTz dt1;
770 
771  dt1 = date2timestamptz(dateVal);
772 
774 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_fastcmp()

static int date_fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 456 of file date.c.

References DatumGetDateADT.

Referenced by date_sortsupport().

457 {
458  DateADT a = DatumGetDateADT(x);
459  DateADT b = DatumGetDateADT(y);
460 
461  if (a < b)
462  return -1;
463  else if (a > b)
464  return 1;
465  return 0;
466 }
#define DatumGetDateADT(X)
Definition: date.h:52
int32 DateADT
Definition: date.h:22

◆ date_finite()

Datum date_finite ( PG_FUNCTION_ARGS  )

Definition at line 478 of file date.c.

References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.

479 {
481 
483 }
int32 DateADT
Definition: date.h:22
long date
Definition: pgtypes_date.h:8
#define DATE_NOT_FINITE(j)
Definition: date.h:42
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_ge()

Datum date_ge ( PG_FUNCTION_ARGS  )

Definition at line 434 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datege().

435 {
436  DateADT dateVal1 = PG_GETARG_DATEADT(0);
437  DateADT dateVal2 = PG_GETARG_DATEADT(1);
438 
439  PG_RETURN_BOOL(dateVal1 >= dateVal2);
440 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_ge_timestamp()

Datum date_ge_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 741 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

742 {
743  DateADT dateVal = PG_GETARG_DATEADT(0);
745  Timestamp dt1;
746 
747  dt1 = date2timestamp(dateVal);
748 
749  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
750 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_ge_timestamptz()

Datum date_ge_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 825 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

826 {
827  DateADT dateVal = PG_GETARG_DATEADT(0);
829  TimestampTz dt1;
830 
831  dt1 = date2timestamptz(dateVal);
832 
834 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_gt()

Datum date_gt ( PG_FUNCTION_ARGS  )

Definition at line 425 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dategt().

426 {
427  DateADT dateVal1 = PG_GETARG_DATEADT(0);
428  DateADT dateVal2 = PG_GETARG_DATEADT(1);
429 
430  PG_RETURN_BOOL(dateVal1 > dateVal2);
431 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_gt_timestamp()

Datum date_gt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 717 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

718 {
719  DateADT dateVal = PG_GETARG_DATEADT(0);
721  Timestamp dt1;
722 
723  dt1 = date2timestamp(dateVal);
724 
725  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
726 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_gt_timestamptz()

Datum date_gt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 801 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

802 {
803  DateADT dateVal = PG_GETARG_DATEADT(0);
805  TimestampTz dt1;
806 
807  dt1 = date2timestamptz(dateVal);
808 
810 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_in()

Datum date_in ( PG_FUNCTION_ARGS  )

Definition at line 116 of file date.c.

References date2j(), DATE_NOBEGIN, DATE_NOEND, DateTimeParseError(), DecodeDateTime(), DTERR_BAD_FORMAT, DTK_CURRENT, DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_LATE, ereport, errcode(), errmsg(), ERROR, GetCurrentDateTime(), GetEpochTime(), IS_VALID_DATE, IS_VALID_JULIAN, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, generate_unaccent_rules::str, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

117 {
118  char *str = PG_GETARG_CSTRING(0);
119  DateADT date;
120  fsec_t fsec;
121  struct pg_tm tt,
122  *tm = &tt;
123  int tzp;
124  int dtype;
125  int nf;
126  int dterr;
127  char *field[MAXDATEFIELDS];
128  int ftype[MAXDATEFIELDS];
129  char workbuf[MAXDATELEN + 1];
130 
131  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
132  field, ftype, MAXDATEFIELDS, &nf);
133  if (dterr == 0)
134  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
135  if (dterr != 0)
136  DateTimeParseError(dterr, str, "date");
137 
138  switch (dtype)
139  {
140  case DTK_DATE:
141  break;
142 
143  case DTK_CURRENT:
144  ereport(ERROR,
145  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
146  errmsg("date/time value \"current\" is no longer supported")));
147 
148  GetCurrentDateTime(tm);
149  break;
150 
151  case DTK_EPOCH:
152  GetEpochTime(tm);
153  break;
154 
155  case DTK_LATE:
156  DATE_NOEND(date);
157  PG_RETURN_DATEADT(date);
158 
159  case DTK_EARLY:
160  DATE_NOBEGIN(date);
161  PG_RETURN_DATEADT(date);
162 
163  default:
164  DateTimeParseError(DTERR_BAD_FORMAT, str, "date");
165  break;
166  }
167 
168  /* Prevent overflow in Julian-day routines */
169  if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
170  ereport(ERROR,
171  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
172  errmsg("date out of range: \"%s\"", str)));
173 
174  date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
175 
176  /* Now check for just-out-of-range dates */
177  if (!IS_VALID_DATE(date))
178  ereport(ERROR,
179  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
180  errmsg("date out of range: \"%s\"", str)));
181 
182  PG_RETURN_DATEADT(date);
183 }
#define MAXDATELEN
Definition: datetime.h:203
#define DTERR_BAD_FORMAT
Definition: datetime.h:282
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:370
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3765
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
long date
Definition: pgtypes_date.h:8
Definition: pgtime.h:25
#define DTK_CURRENT
Definition: datetime.h:152
static struct pg_tm tm
Definition: localtime.c:107
#define DATE_NOBEGIN(j)
Definition: date.h:38
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:783
#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 IS_VALID_JULIAN(y, m, d)
Definition: timestamp.h:155
#define ereport(elevel, rest)
Definition: elog.h:122
#define DTK_LATE
Definition: datetime.h:154
int date2j(int y, int m, int d)
Definition: datetime.c:292
#define DTK_EARLY
Definition: datetime.h:153
#define MAXDATEFIELDS
Definition: datetime.h:205
#define DTK_EPOCH
Definition: datetime.h:155
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
void GetEpochTime(struct pg_tm *tm)
Definition: timestamp.c:1984
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:64
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:562
#define DTK_DATE
Definition: datetime.h:145
#define DATE_NOEND(j)
Definition: date.h:40

◆ date_larger()

Datum date_larger ( PG_FUNCTION_ARGS  )

Definition at line 486 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

487 {
488  DateADT dateVal1 = PG_GETARG_DATEADT(0);
489  DateADT dateVal2 = PG_GETARG_DATEADT(1);
490 
491  PG_RETURN_DATEADT((dateVal1 > dateVal2) ? dateVal1 : dateVal2);
492 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_DATEADT(x)
Definition: date.h:64

◆ date_le()

Datum date_le ( PG_FUNCTION_ARGS  )

Definition at line 416 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datele().

417 {
418  DateADT dateVal1 = PG_GETARG_DATEADT(0);
419  DateADT dateVal2 = PG_GETARG_DATEADT(1);
420 
421  PG_RETURN_BOOL(dateVal1 <= dateVal2);
422 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_le_timestamp()

Datum date_le_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 729 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

730 {
731  DateADT dateVal = PG_GETARG_DATEADT(0);
733  Timestamp dt1;
734 
735  dt1 = date2timestamp(dateVal);
736 
737  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
738 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_le_timestamptz()

Datum date_le_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 813 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

814 {
815  DateADT dateVal = PG_GETARG_DATEADT(0);
817  TimestampTz dt1;
818 
819  dt1 = date2timestamptz(dateVal);
820 
822 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_lt()

Datum date_lt ( PG_FUNCTION_ARGS  )

Definition at line 407 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datelt().

408 {
409  DateADT dateVal1 = PG_GETARG_DATEADT(0);
410  DateADT dateVal2 = PG_GETARG_DATEADT(1);
411 
412  PG_RETURN_BOOL(dateVal1 < dateVal2);
413 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_lt_timestamp()

Datum date_lt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 705 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

706 {
707  DateADT dateVal = PG_GETARG_DATEADT(0);
709  Timestamp dt1;
710 
711  dt1 = date2timestamp(dateVal);
712 
713  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
714 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_lt_timestamptz()

Datum date_lt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 789 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

790 {
791  DateADT dateVal = PG_GETARG_DATEADT(0);
793  TimestampTz dt1;
794 
795  dt1 = date2timestamptz(dateVal);
796 
798 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_mi()

Datum date_mi ( PG_FUNCTION_ARGS  )

Definition at line 506 of file date.c.

References DATE_NOT_FINITE, ereport, errcode(), errmsg(), ERROR, PG_GETARG_DATEADT, and PG_RETURN_INT32.

Referenced by date_dist(), gbt_date_penalty(), and gdb_date_dist().

507 {
508  DateADT dateVal1 = PG_GETARG_DATEADT(0);
509  DateADT dateVal2 = PG_GETARG_DATEADT(1);
510 
511  if (DATE_NOT_FINITE(dateVal1) || DATE_NOT_FINITE(dateVal2))
512  ereport(ERROR,
513  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
514  errmsg("cannot subtract infinite dates")));
515 
516  PG_RETURN_INT32((int32) (dateVal1 - dateVal2));
517 }
int32 DateADT
Definition: date.h:22
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:284
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:42
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ date_mi_interval()

Datum date_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1044 of file date.c.

References date2timestamp(), DirectFunctionCall2, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_mi_interval(), and TimestampGetDatum.

1045 {
1046  DateADT dateVal = PG_GETARG_DATEADT(0);
1047  Interval *span = PG_GETARG_INTERVAL_P(1);
1048  Timestamp dateStamp;
1049 
1050  dateStamp = date2timestamp(dateVal);
1051 
1053  TimestampGetDatum(dateStamp),
1054  PointerGetDatum(span));
1055 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:22
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum timestamp_mi_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:2874
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define TimestampGetDatum(X)
Definition: timestamp.h:31
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ date_mii()

Datum date_mii ( PG_FUNCTION_ARGS  )

Definition at line 547 of file date.c.

References DATE_NOT_FINITE, days, ereport, errcode(), errmsg(), ERROR, IS_VALID_DATE, PG_GETARG_DATEADT, PG_GETARG_INT32, and PG_RETURN_DATEADT.

548 {
549  DateADT dateVal = PG_GETARG_DATEADT(0);
551  DateADT result;
552 
553  if (DATE_NOT_FINITE(dateVal))
554  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
555 
556  result = dateVal - days;
557 
558  /* Check for integer overflow and out-of-allowed-range */
559  if ((days >= 0 ? (result > dateVal) : (result < dateVal)) ||
560  !IS_VALID_DATE(result))
561  ereport(ERROR,
562  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
563  errmsg("date out of range")));
564 
565  PG_RETURN_DATEADT(result);
566 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:284
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:42
const char *const days[]
Definition: datetime.c:69
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_DATEADT(x)
Definition: date.h:64

◆ date_ne()

Datum date_ne ( PG_FUNCTION_ARGS  )

Definition at line 398 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

399 {
400  DateADT dateVal1 = PG_GETARG_DATEADT(0);
401  DateADT dateVal2 = PG_GETARG_DATEADT(1);
402 
403  PG_RETURN_BOOL(dateVal1 != dateVal2);
404 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_ne_timestamp()

Datum date_ne_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 693 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

694 {
695  DateADT dateVal = PG_GETARG_DATEADT(0);
697  Timestamp dt1;
698 
699  dt1 = date2timestamp(dateVal);
700 
701  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
702 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ date_ne_timestamptz()

Datum date_ne_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 777 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

778 {
779  DateADT dateVal = PG_GETARG_DATEADT(0);
781  TimestampTz dt1;
782 
783  dt1 = date2timestamptz(dateVal);
784 
786 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_out()

Datum date_out ( PG_FUNCTION_ARGS  )

Definition at line 189 of file date.c.

References buf, DATE_NOT_FINITE, DateStyle, EncodeDateOnly(), EncodeSpecialDate(), j2date(), MAXDATELEN, PG_GETARG_DATEADT, PG_RETURN_CSTRING, POSTGRES_EPOCH_JDATE, pstrdup(), tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

190 {
192  char *result;
193  struct pg_tm tt,
194  *tm = &tt;
195  char buf[MAXDATELEN + 1];
196 
197  if (DATE_NOT_FINITE(date))
198  EncodeSpecialDate(date, buf);
199  else
200  {
202  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
203  EncodeDateOnly(tm, DateStyle, buf);
204  }
205 
206  result = pstrdup(buf);
207  PG_RETURN_CSTRING(result);
208 }
#define MAXDATELEN
Definition: datetime.h:203
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition: datetime.c:3884
int32 DateADT
Definition: date.h:22
char * pstrdup(const char *in)
Definition: mcxt.c:1076
long date
Definition: pgtypes_date.h:8
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define DATE_NOT_FINITE(j)
Definition: date.h:42
int tm_mday
Definition: pgtime.h:30
static char * buf
Definition: pg_test_fsync.c:67
int tm_mon
Definition: pgtime.h:31
void EncodeSpecialDate(DateADT dt, char *str)
Definition: date.c:299
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:317
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
int DateStyle
Definition: globals.c:107
int tm_year
Definition: pgtime.h:32
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ date_pl_interval()

Datum date_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 1024 of file date.c.

References date2timestamp(), DirectFunctionCall2, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_pl_interval(), and TimestampGetDatum.

1025 {
1026  DateADT dateVal = PG_GETARG_DATEADT(0);
1027  Interval *span = PG_GETARG_INTERVAL_P(1);
1028  Timestamp dateStamp;
1029 
1030  dateStamp = date2timestamp(dateVal);
1031 
1033  TimestampGetDatum(dateStamp),
1034  PointerGetDatum(span));
1035 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:22
#define PointerGetDatum(X)
Definition: postgres.h:562
Datum timestamp_pl_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:2795
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define TimestampGetDatum(X)
Definition: timestamp.h:31
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ date_pli()

Datum date_pli ( PG_FUNCTION_ARGS  )

Definition at line 523 of file date.c.

References DATE_NOT_FINITE, days, ereport, errcode(), errmsg(), ERROR, IS_VALID_DATE, PG_GETARG_DATEADT, PG_GETARG_INT32, and PG_RETURN_DATEADT.

Referenced by daterange_canonical().

524 {
525  DateADT dateVal = PG_GETARG_DATEADT(0);
527  DateADT result;
528 
529  if (DATE_NOT_FINITE(dateVal))
530  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
531 
532  result = dateVal + days;
533 
534  /* Check for integer overflow and out-of-allowed-range */
535  if ((days >= 0 ? (result < dateVal) : (result > dateVal)) ||
536  !IS_VALID_DATE(result))
537  ereport(ERROR,
538  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
539  errmsg("date out of range")));
540 
541  PG_RETURN_DATEADT(result);
542 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:284
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:42
const char *const days[]
Definition: datetime.c:69
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_RETURN_DATEADT(x)
Definition: date.h:64

◆ date_recv()

Datum date_recv ( PG_FUNCTION_ARGS  )

Definition at line 214 of file date.c.

References buf, DATE_NOT_FINITE, ereport, errcode(), errmsg(), ERROR, IS_VALID_DATE, PG_GETARG_POINTER, PG_RETURN_DATEADT, and pq_getmsgint().

215 {
217  DateADT result;
218 
219  result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
220 
221  /* Limit to the same range that date_in() accepts. */
222  if (DATE_NOT_FINITE(result))
223  /* ok */ ;
224  else if (!IS_VALID_DATE(result))
225  ereport(ERROR,
226  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
227  errmsg("date out of range")));
228 
229  PG_RETURN_DATEADT(result);
230 }
int32 DateADT
Definition: date.h:22
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:42
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define PG_RETURN_DATEADT(x)
Definition: date.h:64

◆ date_send()

Datum date_send ( PG_FUNCTION_ARGS  )

Definition at line 236 of file date.c.

References buf, PG_GETARG_DATEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

237 {
240 
241  pq_begintypsend(&buf);
242  pq_sendint32(&buf, date);
244 }
int32 DateADT
Definition: date.h:22
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
long date
Definition: pgtypes_date.h:8
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_DATEADT(n)
Definition: date.h:60

◆ date_smaller()

Datum date_smaller ( PG_FUNCTION_ARGS  )

Definition at line 495 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

496 {
497  DateADT dateVal1 = PG_GETARG_DATEADT(0);
498  DateADT dateVal2 = PG_GETARG_DATEADT(1);
499 
500  PG_RETURN_DATEADT((dateVal1 < dateVal2) ? dateVal1 : dateVal2);
501 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define PG_RETURN_DATEADT(x)
Definition: date.h:64

◆ date_sortsupport()

Datum date_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 469 of file date.c.

References SortSupportData::comparator, date_fastcmp(), PG_GETARG_POINTER, and PG_RETURN_VOID.

470 {
472 
473  ssup->comparator = date_fastcmp;
474  PG_RETURN_VOID();
475 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static int date_fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: date.c:456
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_RETURN_VOID()
Definition: fmgr.h:309

◆ date_timestamp()

Datum date_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1061 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1062 {
1063  DateADT dateVal = PG_GETARG_DATEADT(0);
1064  Timestamp result;
1065 
1066  result = date2timestamp(dateVal);
1067 
1068  PG_RETURN_TIMESTAMP(result);
1069 }
int32 DateADT
Definition: date.h:22
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1105 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1106 {
1107  DateADT dateVal = PG_GETARG_DATEADT(0);
1108  TimestampTz result;
1109 
1110  result = date2timestamptz(dateVal);
1111 
1112  PG_RETURN_TIMESTAMP(result);
1113 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1725 of file date.c.

References date2timestamp(), ereport, errcode(), errmsg(), ERROR, IS_VALID_TIMESTAMP, PG_GETARG_DATEADT, PG_GETARG_TIMEADT, PG_RETURN_TIMESTAMP, and TIMESTAMP_NOT_FINITE.

1726 {
1728  TimeADT time = PG_GETARG_TIMEADT(1);
1729  Timestamp result;
1730 
1731  result = date2timestamp(date);
1732  if (!TIMESTAMP_NOT_FINITE(result))
1733  {
1734  result += time;
1735  if (!IS_VALID_TIMESTAMP(result))
1736  ereport(ERROR,
1737  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1738  errmsg("timestamp out of range")));
1739  }
1740 
1741  PG_RETURN_TIMESTAMP(result);
1742 }
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
long date
Definition: pgtypes_date.h:8
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
int64 TimeADT
Definition: date.h:24
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:195
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 2508 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, ereport, errcode(), errmsg(), ERROR, IS_VALID_TIMESTAMP, PG_GETARG_DATEADT, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMESTAMP, POSTGRES_EPOCH_JDATE, TimeTzADT::time, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, USECS_PER_DAY, USECS_PER_SEC, and TimeTzADT::zone.

2509 {
2511  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2512  TimestampTz result;
2513 
2514  if (DATE_IS_NOBEGIN(date))
2515  TIMESTAMP_NOBEGIN(result);
2516  else if (DATE_IS_NOEND(date))
2517  TIMESTAMP_NOEND(result);
2518  else
2519  {
2520  /*
2521  * Date's range is wider than timestamp's, so check for boundaries.
2522  * Since dates have the same minimum values as timestamps, only upper
2523  * boundary need be checked for overflow.
2524  */
2526  ereport(ERROR,
2527  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2528  errmsg("date out of range for timestamp")));
2529  result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
2530 
2531  /*
2532  * Since it is possible to go beyond allowed timestamptz range because
2533  * of time zone, check for allowed timestamp range after adding tz.
2534  */
2535  if (!IS_VALID_TIMESTAMP(result))
2536  ereport(ERROR,
2537  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2538  errmsg("date out of range for timestamp")));
2539  }
2540 
2541  PG_RETURN_TIMESTAMP(result);
2542 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:41
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
TimeADT time
Definition: date.h:28
#define USECS_PER_SEC
Definition: timestamp.h:94
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
int errcode(int sqlerrcode)
Definition: elog.c:575
long date
Definition: pgtypes_date.h:8
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:122
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
#define DATE_IS_NOBEGIN(j)
Definition: date.h:39
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:195
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
Definition: date.h:26

◆ EncodeSpecialDate()

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

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 314 of file date.c.

References date2j(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), 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:1758
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#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:701
int date2j(int y, int m, int d)
Definition: datetime.c:292
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ GetSQLCurrentTime()

TimeTzADT* GetSQLCurrentTime ( int32  typmod)

Definition at line 336 of file date.c.

References AdjustTimeForTypmod(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), 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:1758
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#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:701
static int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:1943
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: date.h:26

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 362 of file date.c.

References AdjustTimeForTypmod(), ereport, errcode(), errmsg(), ERROR, GetCurrentTransactionStartTimestamp(), 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:1758
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:107
#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:701
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ interval_time()

Datum interval_time ( PG_FUNCTION_ARGS  )

Definition at line 1771 of file date.c.

References days, PG_GETARG_INTERVAL_P, PG_RETURN_TIMEADT, Interval::time, and USECS_PER_DAY.

1772 {
1773  Interval *span = PG_GETARG_INTERVAL_P(0);
1774  TimeADT result;
1775  int64 days;
1776 
1777  result = span->time;
1778  if (result >= USECS_PER_DAY)
1779  {
1780  days = result / USECS_PER_DAY;
1781  result -= days * USECS_PER_DAY;
1782  }
1783  else if (result < 0)
1784  {
1785  days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
1786  result += days * USECS_PER_DAY;
1787  }
1788 
1789  PG_RETURN_TIMEADT(result);
1790 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
TimeOffset time
Definition: timestamp.h:45
const char *const days[]
Definition: datetime.c:69
int64 TimeADT
Definition: date.h:24
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ make_date()

Datum make_date ( PG_FUNCTION_ARGS  )

Definition at line 250 of file date.c.

References date2j(), DTK_DATE_M, ereport, errcode(), errmsg(), ERROR, IS_VALID_DATE, IS_VALID_JULIAN, PG_GETARG_INT32, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, pg_tm::tm_mday, pg_tm::tm_mon, pg_tm::tm_year, and ValidateDate().

251 {
252  struct pg_tm tm;
253  DateADT date;
254  int dterr;
255  bool bc = false;
256 
260 
261  /* Handle negative years as BC */
262  if (tm.tm_year < 0)
263  {
264  bc = true;
265  tm.tm_year = -tm.tm_year;
266  }
267 
268  dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
269 
270  if (dterr != 0)
271  ereport(ERROR,
272  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
273  errmsg("date field value out of range: %d-%02d-%02d",
274  tm.tm_year, tm.tm_mon, tm.tm_mday)));
275 
276  /* Prevent overflow in Julian-day routines */
278  ereport(ERROR,
279  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
280  errmsg("date out of range: %d-%02d-%02d",
281  tm.tm_year, tm.tm_mon, tm.tm_mday)));
282 
284 
285  /* Now check for just-out-of-range dates */
286  if (!IS_VALID_DATE(date))
287  ereport(ERROR,
288  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
289  errmsg("date out of range: %d-%02d-%02d",
290  tm.tm_year, tm.tm_mon, tm.tm_mday)));
291 
292  PG_RETURN_DATEADT(date);
293 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
int32 DateADT
Definition: date.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
long date
Definition: pgtypes_date.h:8
Definition: pgtime.h:25
#define DTK_DATE_M
Definition: datetime.h:194
static struct pg_tm tm
Definition: localtime.c:107
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
#define IS_VALID_JULIAN(y, m, d)
Definition: timestamp.h:155
#define ereport(elevel, rest)
Definition: elog.h:122
int date2j(int y, int m, int d)
Definition: datetime.c:292
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:64
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
Definition: datetime.c:2479

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1342 of file date.c.

References ereport, errcode(), errmsg(), ERROR, HOURS_PER_DAY, MINS_PER_HOUR, PG_GETARG_FLOAT8, PG_GETARG_INT32, PG_RETURN_TIMEADT, rint(), SECS_PER_MINUTE, pg_tm::tm_hour, pg_tm::tm_min, and USECS_PER_SEC.

1343 {
1344  int tm_hour = PG_GETARG_INT32(0);
1345  int tm_min = PG_GETARG_INT32(1);
1346  double sec = PG_GETARG_FLOAT8(2);
1347  TimeADT time;
1348 
1349  /* This should match the checks in DecodeTimeOnly */
1350  if (tm_hour < 0 || tm_min < 0 || tm_min > MINS_PER_HOUR - 1 ||
1351  sec < 0 || sec > SECS_PER_MINUTE ||
1352  tm_hour > HOURS_PER_DAY ||
1353  /* test for > 24:00:00 */
1354  (tm_hour == HOURS_PER_DAY && (tm_min > 0 || sec > 0)))
1355  ereport(ERROR,
1356  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
1357  errmsg("time field value out of range: %d:%02d:%02g",
1358  tm_hour, tm_min, sec)));
1359 
1360  /* This should match tm2time */
1361  time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1362  * USECS_PER_SEC) + rint(sec * USECS_PER_SEC);
1363 
1364  PG_RETURN_TIMEADT(time);
1365 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define ERROR
Definition: elog.h:43
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int64 TimeADT
Definition: date.h:24
double rint(double x)
Definition: rint.c:22
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
int tm_min
Definition: pgtime.h:28

◆ overlaps_time()

Datum overlaps_time ( PG_FUNCTION_ARGS  )

Definition at line 1542 of file date.c.

References PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMEADT_GT, and TIMEADT_LT.

1543 {
1544  /*
1545  * The arguments are TimeADT, but we leave them as generic Datums to avoid
1546  * dereferencing nulls (TimeADT is pass-by-reference!)
1547  */
1548  Datum ts1 = PG_GETARG_DATUM(0);
1549  Datum te1 = PG_GETARG_DATUM(1);
1550  Datum ts2 = PG_GETARG_DATUM(2);
1551  Datum te2 = PG_GETARG_DATUM(3);
1552  bool ts1IsNull = PG_ARGISNULL(0);
1553  bool te1IsNull = PG_ARGISNULL(1);
1554  bool ts2IsNull = PG_ARGISNULL(2);
1555  bool te2IsNull = PG_ARGISNULL(3);
1556 
1557 #define TIMEADT_GT(t1,t2) \
1558  (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
1559 #define TIMEADT_LT(t1,t2) \
1560  (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
1561 
1562  /*
1563  * If both endpoints of interval 1 are null, the result is null (unknown).
1564  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
1565  * take ts1 as the lesser endpoint.
1566  */
1567  if (ts1IsNull)
1568  {
1569  if (te1IsNull)
1570  PG_RETURN_NULL();
1571  /* swap null for non-null */
1572  ts1 = te1;
1573  te1IsNull = true;
1574  }
1575  else if (!te1IsNull)
1576  {
1577  if (TIMEADT_GT(ts1, te1))
1578  {
1579  Datum tt = ts1;
1580 
1581  ts1 = te1;
1582  te1 = tt;
1583  }
1584  }
1585 
1586  /* Likewise for interval 2. */
1587  if (ts2IsNull)
1588  {
1589  if (te2IsNull)
1590  PG_RETURN_NULL();
1591  /* swap null for non-null */
1592  ts2 = te2;
1593  te2IsNull = true;
1594  }
1595  else if (!te2IsNull)
1596  {
1597  if (TIMEADT_GT(ts2, te2))
1598  {
1599  Datum tt = ts2;
1600 
1601  ts2 = te2;
1602  te2 = tt;
1603  }
1604  }
1605 
1606  /*
1607  * At this point neither ts1 nor ts2 is null, so we can consider three
1608  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
1609  */
1610  if (TIMEADT_GT(ts1, ts2))
1611  {
1612  /*
1613  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
1614  * in the presence of nulls it's not quite completely so.
1615  */
1616  if (te2IsNull)
1617  PG_RETURN_NULL();
1618  if (TIMEADT_LT(ts1, te2))
1619  PG_RETURN_BOOL(true);
1620  if (te1IsNull)
1621  PG_RETURN_NULL();
1622 
1623  /*
1624  * If te1 is not null then we had ts1 <= te1 above, and we just found
1625  * ts1 >= te2, hence te1 >= te2.
1626  */
1627  PG_RETURN_BOOL(false);
1628  }
1629  else if (TIMEADT_LT(ts1, ts2))
1630  {
1631  /* This case is ts2 < te1 OR te2 < te1 */
1632  if (te1IsNull)
1633  PG_RETURN_NULL();
1634  if (TIMEADT_LT(ts2, te1))
1635  PG_RETURN_BOOL(true);
1636  if (te2IsNull)
1637  PG_RETURN_NULL();
1638 
1639  /*
1640  * If te2 is not null then we had ts2 <= te2 above, and we just found
1641  * ts2 >= te1, hence te2 >= te1.
1642  */
1643  PG_RETURN_BOOL(false);
1644  }
1645  else
1646  {
1647  /*
1648  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
1649  * rather silly way of saying "true if both are nonnull, else null".
1650  */
1651  if (te1IsNull || te2IsNull)
1652  PG_RETURN_NULL();
1653  PG_RETURN_BOOL(true);
1654  }
1655 
1656 #undef TIMEADT_GT
1657 #undef TIMEADT_LT
1658 }
#define TIMEADT_LT(t1, t2)
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
uintptr_t Datum
Definition: postgres.h:372
#define PG_ARGISNULL(n)
Definition: fmgr.h:174
#define TIMEADT_GT(t1, t2)
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ overlaps_timetz()

Datum overlaps_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2317 of file date.c.

References PG_ARGISNULL, PG_GETARG_DATUM, PG_RETURN_BOOL, PG_RETURN_NULL, TIMETZ_GT, and TIMETZ_LT.

2318 {
2319  /*
2320  * The arguments are TimeTzADT *, but we leave them as generic Datums for
2321  * convenience of notation --- and to avoid dereferencing nulls.
2322  */
2323  Datum ts1 = PG_GETARG_DATUM(0);
2324  Datum te1 = PG_GETARG_DATUM(1);
2325  Datum ts2 = PG_GETARG_DATUM(2);
2326  Datum te2 = PG_GETARG_DATUM(3);
2327  bool ts1IsNull = PG_ARGISNULL(0);
2328  bool te1IsNull = PG_ARGISNULL(1);
2329  bool ts2IsNull = PG_ARGISNULL(2);
2330  bool te2IsNull = PG_ARGISNULL(3);
2331 
2332 #define TIMETZ_GT(t1,t2) \
2333  DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
2334 #define TIMETZ_LT(t1,t2) \
2335  DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
2336 
2337  /*
2338  * If both endpoints of interval 1 are null, the result is null (unknown).
2339  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
2340  * take ts1 as the lesser endpoint.
2341  */
2342  if (ts1IsNull)
2343  {
2344  if (te1IsNull)
2345  PG_RETURN_NULL();
2346  /* swap null for non-null */
2347  ts1 = te1;
2348  te1IsNull = true;
2349  }
2350  else if (!te1IsNull)
2351  {
2352  if (TIMETZ_GT(ts1, te1))
2353  {
2354  Datum tt = ts1;
2355 
2356  ts1 = te1;
2357  te1 = tt;
2358  }
2359  }
2360 
2361  /* Likewise for interval 2. */
2362  if (ts2IsNull)
2363  {
2364  if (te2IsNull)
2365  PG_RETURN_NULL();
2366  /* swap null for non-null */
2367  ts2 = te2;
2368  te2IsNull = true;
2369  }
2370  else if (!te2IsNull)
2371  {
2372  if (TIMETZ_GT(ts2, te2))
2373  {
2374  Datum tt = ts2;
2375 
2376  ts2 = te2;
2377  te2 = tt;
2378  }
2379  }
2380 
2381  /*
2382  * At this point neither ts1 nor ts2 is null, so we can consider three
2383  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
2384  */
2385  if (TIMETZ_GT(ts1, ts2))
2386  {
2387  /*
2388  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
2389  * in the presence of nulls it's not quite completely so.
2390  */
2391  if (te2IsNull)
2392  PG_RETURN_NULL();
2393  if (TIMETZ_LT(ts1, te2))
2394  PG_RETURN_BOOL(true);
2395  if (te1IsNull)
2396  PG_RETURN_NULL();
2397 
2398  /*
2399  * If te1 is not null then we had ts1 <= te1 above, and we just found
2400  * ts1 >= te2, hence te1 >= te2.
2401  */
2402  PG_RETURN_BOOL(false);
2403  }
2404  else if (TIMETZ_LT(ts1, ts2))
2405  {
2406  /* This case is ts2 < te1 OR te2 < te1 */
2407  if (te1IsNull)
2408  PG_RETURN_NULL();
2409  if (TIMETZ_LT(ts2, te1))
2410  PG_RETURN_BOOL(true);
2411  if (te2IsNull)
2412  PG_RETURN_NULL();
2413 
2414  /*
2415  * If te2 is not null then we had ts2 <= te2 above, and we just found
2416  * ts2 >= te1, hence te2 >= te1.
2417  */
2418  PG_RETURN_BOOL(false);
2419  }
2420  else
2421  {
2422  /*
2423  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
2424  * rather silly way of saying "true if both are nonnull, else null".
2425  */
2426  if (te1IsNull || te2IsNull)
2427  PG_RETURN_NULL();
2428  PG_RETURN_BOOL(true);
2429  }
2430 
2431 #undef TIMETZ_GT
2432 #undef TIMETZ_LT
2433 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
#define TIMETZ_LT(t1, t2)
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
uintptr_t Datum
Definition: postgres.h:372
#define PG_ARGISNULL(n)
Definition: fmgr.h:174
#define PG_RETURN_NULL()
Definition: fmgr.h:305
#define TIMETZ_GT(t1, t2)

◆ time2tm()

static int time2tm ( TimeADT  time,
struct pg_tm tm,
fsec_t fsec 
)
static

Definition at line 1253 of file date.c.

References pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, and USECS_PER_SEC.

Referenced by time_out(), time_part(), and time_timetz().

1254 {
1255  tm->tm_hour = time / USECS_PER_HOUR;
1256  time -= tm->tm_hour * USECS_PER_HOUR;
1257  tm->tm_min = time / USECS_PER_MINUTE;
1258  time -= tm->tm_min * USECS_PER_MINUTE;
1259  tm->tm_sec = time / USECS_PER_SEC;
1260  time -= tm->tm_sec * USECS_PER_SEC;
1261  *fsec = time;
1262  return 0;
1263 }
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define USECS_PER_MINUTE
Definition: timestamp.h:93
#define USECS_PER_HOUR
Definition: timestamp.h:92
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ time_cmp()

Datum time_cmp ( PG_FUNCTION_ARGS  )

Definition at line 1493 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_INT32.

Referenced by gbt_timekey_cmp(), and leftmostvalue_time().

1494 {
1495  TimeADT time1 = PG_GETARG_TIMEADT(0);
1496  TimeADT time2 = PG_GETARG_TIMEADT(1);
1497 
1498  if (time1 < time2)
1499  PG_RETURN_INT32(-1);
1500  if (time1 > time2)
1501  PG_RETURN_INT32(1);
1502  PG_RETURN_INT32(0);
1503 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_eq()

Datum time_eq ( PG_FUNCTION_ARGS  )

Definition at line 1439 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

1440 {
1441  TimeADT time1 = PG_GETARG_TIMEADT(0);
1442  TimeADT time2 = PG_GETARG_TIMEADT(1);
1443 
1444  PG_RETURN_BOOL(time1 == time2);
1445 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_ge()

Datum time_ge ( PG_FUNCTION_ARGS  )

Definition at line 1484 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

1485 {
1486  TimeADT time1 = PG_GETARG_TIMEADT(0);
1487  TimeADT time2 = PG_GETARG_TIMEADT(1);
1488 
1489  PG_RETURN_BOOL(time1 >= time2);
1490 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_gt()

Datum time_gt ( PG_FUNCTION_ARGS  )

Definition at line 1475 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

1476 {
1477  TimeADT time1 = PG_GETARG_TIMEADT(0);
1478  TimeADT time2 = PG_GETARG_TIMEADT(1);
1479 
1480  PG_RETURN_BOOL(time1 > time2);
1481 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_hash()

Datum time_hash ( PG_FUNCTION_ARGS  )

Definition at line 1506 of file date.c.

References hashint8().

1507 {
1508  return hashint8(fcinfo);
1509 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:80

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1512 of file date.c.

References hashint8extended().

1513 {
1514  return hashint8extended(fcinfo);
1515 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:100

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

Definition at line 1201 of file date.c.

References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_TIMEADT, generate_unaccent_rules::str, tm, and tm2time().

1202 {
1203  char *str = PG_GETARG_CSTRING(0);
1204 
1205 #ifdef NOT_USED
1206  Oid typelem = PG_GETARG_OID(1);
1207 #endif
1208  int32 typmod = PG_GETARG_INT32(2);
1209  TimeADT result;
1210  fsec_t fsec;
1211  struct pg_tm tt,
1212  *tm = &tt;
1213  int tz;
1214  int nf;
1215  int dterr;
1216  char workbuf[MAXDATELEN + 1];
1217  char *field[MAXDATEFIELDS];
1218  int dtype;
1219  int ftype[MAXDATEFIELDS];
1220 
1221  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1222  field, ftype, MAXDATEFIELDS, &nf);
1223  if (dterr == 0)
1224  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1225  if (dterr != 0)
1226  DateTimeParseError(dterr, str, "time");
1227 
1228  tm2time(tm, fsec, &result);
1229  AdjustTimeForTypmod(&result, typmod);
1230 
1231  PG_RETURN_TIMEADT(result);
1232 }
#define MAXDATELEN
Definition: datetime.h:203
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3765
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
static int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1238
Definition: pgtime.h:25
unsigned int Oid
Definition: postgres_ext.h:31
int DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:1744
signed int int32
Definition: c.h:284
static struct pg_tm tm
Definition: localtime.c:107
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
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 MAXDATEFIELDS
Definition: datetime.h:205
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:562

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1748 of file date.c.

References Interval::day, Interval::month, palloc(), PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and Interval::time.

1749 {
1750  TimeADT time = PG_GETARG_TIMEADT(0);
1751  Interval *result;
1752 
1753  result = (Interval *) palloc(sizeof(Interval));
1754 
1755  result->time = time;
1756  result->day = 0;
1757  result->month = 0;
1758 
1759  PG_RETURN_INTERVAL_P(result);
1760 }
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
int32 day
Definition: timestamp.h:47
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:24
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
void * palloc(Size size)
Definition: mcxt.c:848

◆ time_larger()

Datum time_larger ( PG_FUNCTION_ARGS  )

Definition at line 1518 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1519 {
1520  TimeADT time1 = PG_GETARG_TIMEADT(0);
1521  TimeADT time2 = PG_GETARG_TIMEADT(1);
1522 
1523  PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2);
1524 }
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_le()

Datum time_le ( PG_FUNCTION_ARGS  )

Definition at line 1466 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

1467 {
1468  TimeADT time1 = PG_GETARG_TIMEADT(0);
1469  TimeADT time2 = PG_GETARG_TIMEADT(1);
1470 
1471  PG_RETURN_BOOL(time1 <= time2);
1472 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_lt()

Datum time_lt ( PG_FUNCTION_ARGS  )

Definition at line 1457 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

1458 {
1459  TimeADT time1 = PG_GETARG_TIMEADT(0);
1460  TimeADT time2 = PG_GETARG_TIMEADT(1);
1461 
1462  PG_RETURN_BOOL(time1 < time2);
1463 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_mi_interval()

Datum time_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1833 of file date.c.

References PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, Interval::time, and USECS_PER_DAY.

1834 {
1835  TimeADT time = PG_GETARG_TIMEADT(0);
1836  Interval *span = PG_GETARG_INTERVAL_P(1);
1837  TimeADT result;
1838 
1839  result = time - span->time;
1840  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1841  if (result < INT64CONST(0))
1842  result += USECS_PER_DAY;
1843 
1844  PG_RETURN_TIMEADT(result);
1845 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:24
#define USECS_PER_DAY
Definition: timestamp.h:91
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_mi_time()

Datum time_mi_time ( PG_FUNCTION_ARGS  )

Definition at line 1796 of file date.c.

References Interval::day, Interval::month, palloc(), PG_GETARG_TIMEADT, PG_RETURN_INTERVAL_P, and Interval::time.

Referenced by gbt_time_dist(), gbt_time_penalty(), and time_dist().

1797 {
1798  TimeADT time1 = PG_GETARG_TIMEADT(0);
1799  TimeADT time2 = PG_GETARG_TIMEADT(1);
1800  Interval *result;
1801 
1802  result = (Interval *) palloc(sizeof(Interval));
1803 
1804  result->month = 0;
1805  result->day = 0;
1806  result->time = time1 - time2;
1807 
1808  PG_RETURN_INTERVAL_P(result);
1809 }
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
int32 day
Definition: timestamp.h:47
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:24
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
void * palloc(Size size)
Definition: mcxt.c:848

◆ time_ne()

Datum time_ne ( PG_FUNCTION_ARGS  )

Definition at line 1448 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

1449 {
1450  TimeADT time1 = PG_GETARG_TIMEADT(0);
1451  TimeADT time2 = PG_GETARG_TIMEADT(1);
1452 
1453  PG_RETURN_BOOL(time1 != time2);
1454 }
int64 TimeADT
Definition: date.h:24
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_out()

Datum time_out ( PG_FUNCTION_ARGS  )

Definition at line 1266 of file date.c.

References buf, DateStyle, EncodeTimeOnly(), MAXDATELEN, PG_GETARG_TIMEADT, PG_RETURN_CSTRING, pstrdup(), time2tm(), and tm.

1267 {
1268  TimeADT time = PG_GETARG_TIMEADT(0);
1269  char *result;
1270  struct pg_tm tt,
1271  *tm = &tt;
1272  fsec_t fsec;
1273  char buf[MAXDATELEN + 1];
1274 
1275  time2tm(time, tm, &fsec);
1276  EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1277 
1278  result = pstrdup(buf);
1279  PG_RETURN_CSTRING(result);
1280 }
#define MAXDATELEN
Definition: datetime.h:203
char * pstrdup(const char *in)
Definition: mcxt.c:1076
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3969
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
static char * buf
Definition: pg_test_fsync.c:67
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
int DateStyle
Definition: globals.c:107
static int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1253

◆ time_part()

Datum time_part ( PG_FUNCTION_ARGS  )

Definition at line 1852 of file date.c.

References DecodeSpecial(), DecodeUnits(), downcase_truncate_identifier(), DTK_CENTURY, DTK_DAY, DTK_DECADE, DTK_EPOCH, DTK_HOUR, DTK_ISOYEAR, DTK_MICROSEC, DTK_MILLENNIUM, DTK_MILLISEC, DTK_MINUTE, DTK_MONTH, DTK_QUARTER, DTK_SECOND, DTK_TZ, DTK_TZ_HOUR, DTK_TZ_MINUTE, DTK_YEAR, ereport, errcode(), errmsg(), ERROR, PG_GETARG_TEXT_PP, PG_GETARG_TIMEADT, PG_RETURN_FLOAT8, RESERV, time2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, generate_unaccent_rules::type, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

1853 {
1854  text *units = PG_GETARG_TEXT_PP(0);
1855  TimeADT time = PG_GETARG_TIMEADT(1);
1856  float8 result;
1857  int type,
1858  val;
1859  char *lowunits;
1860 
1861  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
1862  VARSIZE_ANY_EXHDR(units),
1863  false);
1864 
1865  type = DecodeUnits(0, lowunits, &val);
1866  if (type == UNKNOWN_FIELD)
1867  type = DecodeSpecial(0, lowunits, &val);
1868 
1869  if (type == UNITS)
1870  {
1871  fsec_t fsec;
1872  struct pg_tm tt,
1873  *tm = &tt;
1874 
1875  time2tm(time, tm, &fsec);
1876 
1877  switch (val)
1878  {
1879  case DTK_MICROSEC:
1880  result = tm->tm_sec * 1000000.0 + fsec;
1881  break;
1882 
1883  case DTK_MILLISEC:
1884  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
1885  break;
1886 
1887  case DTK_SECOND:
1888  result = tm->tm_sec + fsec / 1000000.0;
1889  break;
1890 
1891  case DTK_MINUTE:
1892  result = tm->tm_min;
1893  break;
1894 
1895  case DTK_HOUR:
1896  result = tm->tm_hour;
1897  break;
1898 
1899  case DTK_TZ:
1900  case DTK_TZ_MINUTE:
1901  case DTK_TZ_HOUR:
1902  case DTK_DAY:
1903  case DTK_MONTH:
1904  case DTK_QUARTER:
1905  case DTK_YEAR:
1906  case DTK_DECADE:
1907  case DTK_CENTURY:
1908  case DTK_MILLENNIUM:
1909  case DTK_ISOYEAR:
1910  default:
1911  ereport(ERROR,
1912  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1913  errmsg("\"time\" units \"%s\" not recognized",
1914  lowunits)));
1915  result = 0;
1916  }
1917  }
1918  else if (type == RESERV && val == DTK_EPOCH)
1919  {
1920  result = time / 1000000.0;
1921  }
1922  else
1923  {
1924  ereport(ERROR,
1925  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1926  errmsg("\"time\" units \"%s\" not recognized",
1927  lowunits)));
1928  result = 0;
1929  }
1930 
1931  PG_RETURN_FLOAT8(result);
1932 }
#define DTK_TZ_HOUR
Definition: datetime.h:180
#define DTK_CENTURY
Definition: datetime.h:172
#define UNITS
Definition: datetime.h:108
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define DTK_YEAR
Definition: datetime.h:170
int tm_hour
Definition: pgtime.h:29
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:131
#define DTK_QUARTER
Definition: datetime.h:169
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define DTK_MILLENNIUM
Definition: datetime.h:173
int errcode(int sqlerrcode)
Definition: elog.c:575
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3728
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static struct pg_tm tm
Definition: localtime.c:107
#define DTK_MONTH
Definition: datetime.h:168
#define DTK_MILLISEC
Definition: datetime.h:174
#define DTK_DECADE
Definition: datetime.h:171
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:165
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:429
#define DTK_SECOND
Definition: datetime.h:163
#define DTK_ISOYEAR
Definition: datetime.h:182
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
#define DTK_TZ_MINUTE
Definition: datetime.h:181
#define ereport(elevel, rest)
Definition: elog.h:122
#define DTK_MINUTE
Definition: datetime.h:164
#define DTK_MICROSEC
Definition: datetime.h:175
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
#define DTK_DAY
Definition: datetime.h:166
#define RESERV
Definition: datetime.h:91
int DecodeSpecial(int field, char *lowtoken, int *val)
Definition: datetime.c:3039
#define DTK_EPOCH
Definition: datetime.h:155
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
int errmsg(const char *fmt,...)
Definition: elog.c:797
static int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1253
Definition: c.h:487
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:689

◆ time_pl_interval()

Datum time_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 1815 of file date.c.

References PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_TIMEADT, Interval::time, and USECS_PER_DAY.

1816 {
1817  TimeADT time = PG_GETARG_TIMEADT(0);
1818  Interval *span = PG_GETARG_INTERVAL_P(1);
1819  TimeADT result;
1820 
1821  result = time + span->time;
1822  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1823  if (result < INT64CONST(0))
1824  result += USECS_PER_DAY;
1825 
1826  PG_RETURN_TIMEADT(result);
1827 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:24
#define USECS_PER_DAY
Definition: timestamp.h:91
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_recv()

Datum time_recv ( PG_FUNCTION_ARGS  )

Definition at line 1286 of file date.c.

References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMEADT, pq_getmsgint64(), and USECS_PER_DAY.

1287 {
1289 
1290 #ifdef NOT_USED
1291  Oid typelem = PG_GETARG_OID(1);
1292 #endif
1293  int32 typmod = PG_GETARG_INT32(2);
1294  TimeADT result;
1295 
1296  result = pq_getmsgint64(buf);
1297 
1298  if (result < INT64CONST(0) || result > USECS_PER_DAY)
1299  ereport(ERROR,
1300  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1301  errmsg("time out of range")));
1302 
1303  AdjustTimeForTypmod(&result, typmod);
1304 
1305  PG_RETURN_TIMEADT(result);
1306 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:284
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
int64 TimeADT
Definition: date.h:24
#define USECS_PER_DAY
Definition: timestamp.h:91
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1384 of file date.c.

References AdjustTimeForTypmod(), PG_GETARG_INT32, PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1385 {
1386  TimeADT time = PG_GETARG_TIMEADT(0);
1387  int32 typmod = PG_GETARG_INT32(1);
1388  TimeADT result;
1389 
1390  result = time;
1391  AdjustTimeForTypmod(&result, typmod);
1392 
1393  PG_RETURN_TIMEADT(result);
1394 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
signed int int32
Definition: c.h:284
int64 TimeADT
Definition: date.h:24
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1312 of file date.c.

References buf, PG_GETARG_TIMEADT, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint64().

1313 {
1314  TimeADT time = PG_GETARG_TIMEADT(0);
1316 
1317  pq_begintypsend(&buf);
1318  pq_sendint64(&buf, time);
1320 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
static void pq_sendint64(StringInfo buf, int64 i)
Definition: pqformat.h:156
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_smaller()

Datum time_smaller ( PG_FUNCTION_ARGS  )

Definition at line 1527 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1528 {
1529  TimeADT time1 = PG_GETARG_TIMEADT(0);
1530  TimeADT time2 = PG_GETARG_TIMEADT(1);
1531 
1532  PG_RETURN_TIMEADT((time1 < time2) ? time1 : time2);
1533 }
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2450 of file date.c.

References DetermineTimeZoneOffset(), GetCurrentDateTime(), palloc(), PG_GETARG_TIMEADT, PG_RETURN_TIMETZADT_P, session_timezone, TimeTzADT::time, time2tm(), tm, and TimeTzADT::zone.

2451 {
2452  TimeADT time = PG_GETARG_TIMEADT(0);
2453  TimeTzADT *result;
2454  struct pg_tm tt,
2455  *tm = &tt;
2456  fsec_t fsec;
2457  int tz;
2458 
2459  GetCurrentDateTime(tm);
2460  time2tm(time, tm, &fsec);
2462 
2463  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2464 
2465  result->time = time;
2466  result->zone = tz;
2467 
2468  PG_RETURN_TIMETZADT_P(result);
2469 }
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:370
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
int32 zone
Definition: date.h:29
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1471
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
#define PG_GETARG_TIMEADT(n)
Definition: date.h:61
void * palloc(Size size)
Definition: mcxt.c:848
static int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1253
pg_tz * session_timezone
Definition: pgtz.c:28
Definition: date.h:26

◆ time_transform()

Datum time_transform ( PG_FUNCTION_ARGS  )

Definition at line 1373 of file date.c.

References MAX_TIME_PRECISION, PG_GETARG_POINTER, PG_RETURN_POINTER, and TemporalTransform().

1374 {
1376  (Node *) PG_GETARG_POINTER(0)));
1377 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Definition: nodes.h:511
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Node * TemporalTransform(int32 max_precis, Node *node)
Definition: datetime.c:4486
#define MAX_TIME_PRECISION
Definition: date.h:50

◆ timestamp_cmp_date()

Datum timestamp_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 921 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_INT32, and timestamp_cmp_internal().

922 {
924  DateADT dateVal = PG_GETARG_DATEADT(1);
925  Timestamp dt2;
926 
927  dt2 = date2timestamp(dateVal);
928 
930 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

Definition at line 1075 of file date.c.

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

1076 {
1078  DateADT result;
1079  struct pg_tm tt,
1080  *tm = &tt;
1081  fsec_t fsec;
1082 
1083  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1084  DATE_NOBEGIN(result);
1085  else if (TIMESTAMP_IS_NOEND(timestamp))
1086  DATE_NOEND(result);
1087  else
1088  {
1089  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1090  ereport(ERROR,
1091  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1092  errmsg("timestamp out of range")));
1093 
1094  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1095  }
1096 
1097  PG_RETURN_DATEADT(result);
1098 }
int32 DateADT
Definition: date.h:22
int64 timestamp
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define DATE_NOBEGIN(j)
Definition: date.h:38
#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
int64 Timestamp
Definition: timestamp.h:38
int date2j(int y, int m, int d)
Definition: datetime.c:292
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:115
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:64
#define DATE_NOEND(j)
Definition: date.h:40

◆ timestamp_eq_date()

Datum timestamp_eq_date ( PG_FUNCTION_ARGS  )

Definition at line 849 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

850 {
852  DateADT dateVal = PG_GETARG_DATEADT(1);
853  Timestamp dt2;
854 
855  dt2 = date2timestamp(dateVal);
856 
857  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
858 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_ge_date()

Datum timestamp_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 909 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

910 {
912  DateADT dateVal = PG_GETARG_DATEADT(1);
913  Timestamp dt2;
914 
915  dt2 = date2timestamp(dateVal);
916 
917  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
918 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_gt_date()

Datum timestamp_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 885 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

886 {
888  DateADT dateVal = PG_GETARG_DATEADT(1);
889  Timestamp dt2;
890 
891  dt2 = date2timestamp(dateVal);
892 
893  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
894 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_le_date()

Datum timestamp_le_date ( PG_FUNCTION_ARGS  )

Definition at line 897 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

898 {
900  DateADT dateVal = PG_GETARG_DATEADT(1);
901  Timestamp dt2;
902 
903  dt2 = date2timestamp(dateVal);
904 
905  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
906 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_lt_date()

Datum timestamp_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 873 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

874 {
876  DateADT dateVal = PG_GETARG_DATEADT(1);
877  Timestamp dt2;
878 
879  dt2 = date2timestamp(dateVal);
880 
881  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
882 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_ne_date()

Datum timestamp_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 861 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, PG_RETURN_BOOL, and timestamp_cmp_internal().

862 {
864  DateADT dateVal = PG_GETARG_DATEADT(1);
865  Timestamp dt2;
866 
867  dt2 = date2timestamp(dateVal);
868 
869  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
870 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2023
int32 DateADT
Definition: date.h:22
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
int64 Timestamp
Definition: timestamp.h:38
static Timestamp date2timestamp(DateADT dateVal)
Definition: date.c:574
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

Definition at line 1664 of file date.c.

References ereport, errcode(), errmsg(), ERROR, MINS_PER_HOUR, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

1665 {
1667  TimeADT result;
1668  struct pg_tm tt,
1669  *tm = &tt;
1670  fsec_t fsec;
1671 
1672  if (TIMESTAMP_NOT_FINITE(timestamp))
1673  PG_RETURN_NULL();
1674 
1675  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1676  ereport(ERROR,
1677  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1678  errmsg("timestamp out of range")));
1679 
1680  /*
1681  * Could also do this with time = (timestamp / USECS_PER_DAY *
1682  * USECS_PER_DAY) - timestamp;
1683  */
1684  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1685  USECS_PER_SEC) + fsec;
1686 
1687  PG_RETURN_TIMEADT(result);
1688 }
#define USECS_PER_SEC
Definition: timestamp.h:94
int64 timestamp
int tm_hour
Definition: pgtime.h:29
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:107
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
#define ereport(elevel, rest)
Definition: elog.h:122
int64 Timestamp
Definition: timestamp.h:38
int errmsg(const char *fmt,...)
Definition: elog.c:797
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ timestamptz_cmp_date()

Datum timestamptz_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 1005 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_INT32, and timestamptz_cmp_internal.

1006 {
1008  DateADT dateVal = PG_GETARG_DATEADT(1);
1009  TimestampTz dt2;
1010 
1011  dt2 = date2timestamptz(dateVal);
1012 
1014 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_date()

Datum timestamptz_date ( PG_FUNCTION_ARGS  )

Definition at line 1120 of file date.c.

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereport, errcode(), errmsg(), ERROR, PG_GETARG_TIMESTAMP, PG_RETURN_DATEADT, POSTGRES_EPOCH_JDATE, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

1121 {
1123  DateADT result;
1124  struct pg_tm tt,
1125  *tm = &tt;
1126  fsec_t fsec;
1127  int tz;
1128 
1129  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1130  DATE_NOBEGIN(result);
1131  else if (TIMESTAMP_IS_NOEND(timestamp))
1132  DATE_NOEND(result);
1133  else
1134  {
1135  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1136  ereport(ERROR,
1137  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1138  errmsg("timestamp out of range")));
1139 
1140  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1141  }
1142 
1143  PG_RETURN_DATEADT(result);
1144 }
int32 DateADT
Definition: date.h:22
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define DATE_NOBEGIN(j)
Definition: date.h:38
#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
int date2j(int y, int m, int d)
Definition: datetime.c:292
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:115
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:64
#define DATE_NOEND(j)
Definition: date.h:40

◆ timestamptz_eq_date()

Datum timestamptz_eq_date ( PG_FUNCTION_ARGS  )

Definition at line 933 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

934 {
936  DateADT dateVal = PG_GETARG_DATEADT(1);
937  TimestampTz dt2;
938 
939  dt2 = date2timestamptz(dateVal);
940 
942 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_ge_date()

Datum timestamptz_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 993 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

994 {
996  DateADT dateVal = PG_GETARG_DATEADT(1);
997  TimestampTz dt2;
998 
999  dt2 = date2timestamptz(dateVal);
1000 
1001  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0);
1002 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_gt_date()

Datum timestamptz_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 969 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

970 {
972  DateADT dateVal = PG_GETARG_DATEADT(1);
973  TimestampTz dt2;
974 
975  dt2 = date2timestamptz(dateVal);
976 
978 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_le_date()

Datum timestamptz_le_date ( PG_FUNCTION_ARGS  )

Definition at line 981 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

982 {
984  DateADT dateVal = PG_GETARG_DATEADT(1);
985  TimestampTz dt2;
986 
987  dt2 = date2timestamptz(dateVal);
988 
990 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_lt_date()

Datum timestamptz_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 957 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

958 {
960  DateADT dateVal = PG_GETARG_DATEADT(1);
961  TimestampTz dt2;
962 
963  dt2 = date2timestamptz(dateVal);
964 
966 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_ne_date()

Datum timestamptz_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 945 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

946 {
948  DateADT dateVal = PG_GETARG_DATEADT(1);
949  TimestampTz dt2;
950 
951  dt2 = date2timestamptz(dateVal);
952 
954 }
int32 DateADT
Definition: date.h:22
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:60
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:602
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_time()

Datum timestamptz_time ( PG_FUNCTION_ARGS  )

Definition at line 1694 of file date.c.

References ereport, errcode(), errmsg(), ERROR, MINS_PER_HOUR, PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMEADT, SECS_PER_MINUTE, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

1695 {
1697  TimeADT result;
1698  struct pg_tm tt,
1699  *tm = &tt;
1700  int tz;
1701  fsec_t fsec;
1702 
1703  if (TIMESTAMP_NOT_FINITE(timestamp))
1704  PG_RETURN_NULL();
1705 
1706  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1707  ereport(ERROR,
1708  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1709  errmsg("timestamp out of range")));
1710 
1711  /*
1712  * Could also do this with time = (timestamp / USECS_PER_DAY *
1713  * USECS_PER_DAY) - timestamp;
1714  */
1715  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1716  USECS_PER_SEC) + fsec;
1717 
1718  PG_RETURN_TIMEADT(result);
1719 }
#define USECS_PER_SEC
Definition: timestamp.h:94
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
int tm_hour
Definition: pgtime.h:29
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:107
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:24
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ timestamptz_timetz()

Datum timestamptz_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2476 of file date.c.

References ereport, errcode(), errmsg(), ERROR, palloc(), PG_GETARG_TIMESTAMP, PG_RETURN_NULL, PG_RETURN_TIMETZADT_P, timestamp2tm(), TIMESTAMP_NOT_FINITE, tm, and tm2timetz().

2477 {
2479  TimeTzADT *result;
2480  struct pg_tm tt,
2481  *tm = &tt;
2482  int tz;
2483  fsec_t fsec;
2484 
2485  if (TIMESTAMP_NOT_FINITE(timestamp))
2486  PG_RETURN_NULL();
2487 
2488  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2489  ereport(ERROR,
2490  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2491  errmsg("timestamp out of range")));
2492 
2493  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2494 
2495  tm2timetz(tm, fsec, tz, result);
2496 
2497  PG_RETURN_TIMETZADT_P(result);
2498 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
int errcode(int sqlerrcode)
Definition: elog.c:575
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:122
static int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:1943
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: date.h:26
#define PG_RETURN_NULL()
Definition: fmgr.h:305

◆ timetypmodin()

Datum timetypmodin ( PG_FUNCTION_ARGS  )

Definition at line 1323 of file date.c.

References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

1324 {
1326 
1327  PG_RETURN_INT32(anytime_typmodin(false, ta));
1328 }
static int32 anytime_typmodin(bool istz, ArrayType *ta)
Definition: date.c:53
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:248

◆ timetypmodout()

Datum timetypmodout ( PG_FUNCTION_ARGS  )

Definition at line 1331 of file date.c.

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

1332 {
1333  int32 typmod = PG_GETARG_INT32(0);
1334 
1335  PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1336 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
signed int int32
Definition: c.h:284
static char * anytime_typmodout(bool istz, int32 typmod)
Definition: date.c:96
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322

◆ timetz2tm()

static int timetz2tm ( TimeTzADT time,
struct pg_tm tm,
fsec_t fsec,
int *  tzp 
)
static

Definition at line 2077 of file date.c.

References TimeTzADT::time, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, USECS_PER_SEC, and TimeTzADT::zone.

Referenced by timetz_out(), and timetz_part().

2078 {
2079  TimeOffset trem = time->time;
2080 
2081  tm->tm_hour = trem / USECS_PER_HOUR;
2082  trem -= tm->tm_hour * USECS_PER_HOUR;
2083  tm->tm_min = trem / USECS_PER_MINUTE;
2084  trem -= tm->tm_min * USECS_PER_MINUTE;
2085  tm->tm_sec = trem / USECS_PER_SEC;
2086  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2087 
2088  if (tzp != NULL)
2089  *tzp = time->zone;
2090 
2091  return 0;
2092 }
TimeADT time
Definition: date.h:28
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define USECS_PER_MINUTE
Definition: timestamp.h:93
int32 zone
Definition: date.h:29
#define USECS_PER_HOUR
Definition: timestamp.h:92
int64 TimeOffset
Definition: timestamp.h:40
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ timetz_cmp()

Datum timetz_cmp ( PG_FUNCTION_ARGS  )

Definition at line 2198 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().

Referenced by leftmostvalue_timetz().

2199 {
2200  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2201  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2202 
2203  PG_RETURN_INT32(timetz_cmp_internal(time1, time2));
2204 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
Definition: date.h:26

◆ timetz_cmp_internal()

static int timetz_cmp_internal ( TimeTzADT time1,
TimeTzADT time2 
)
static

Definition at line 2117 of file date.c.

References TimeTzADT::time, USECS_PER_SEC, and TimeTzADT::zone.

Referenced by timetz_cmp(), timetz_eq(), timetz_ge(), timetz_gt(), timetz_larger(), timetz_le(), timetz_lt(), timetz_ne(), and timetz_smaller().

2118 {
2119  TimeOffset t1,
2120  t2;
2121 
2122  /* Primary sort is by true (GMT-equivalent) time */
2123  t1 = time1->time + (time1->zone * USECS_PER_SEC);
2124  t2 = time2->time + (time2->zone * USECS_PER_SEC);
2125 
2126  if (t1 > t2)
2127  return 1;
2128  if (t1 < t2)
2129  return -1;
2130 
2131  /*
2132  * If same GMT time, sort by timezone; we only want to say that two
2133  * timetz's are equal if both the time and zone parts are equal.
2134  */
2135  if (time1->zone > time2->zone)
2136  return 1;
2137  if (time1->zone < time2->zone)
2138  return -1;
2139 
2140  return 0;
2141 }
TimeADT time
Definition: date.h:28
#define USECS_PER_SEC
Definition: timestamp.h:94
int32 zone
Definition: date.h:29
int64 TimeOffset
Definition: timestamp.h:40

◆ timetz_eq()

Datum timetz_eq ( PG_FUNCTION_ARGS  )

Definition at line 2144 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2145 {
2146  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2147  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2148 
2149  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) == 0);
2150 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_ge()

Datum timetz_ge ( PG_FUNCTION_ARGS  )

Definition at line 2189 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2190 {
2191  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2192  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2193 
2194  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0);
2195 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_gt()

Datum timetz_gt ( PG_FUNCTION_ARGS  )

Definition at line 2180 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2181 {
2182  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2183  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2184 
2185  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0);
2186 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_hash()

Datum timetz_hash ( PG_FUNCTION_ARGS  )

Definition at line 2207 of file date.c.

References DatumGetUInt32, DirectFunctionCall1, hash_uint32(), hashint8(), Int64GetDatumFast, PG_GETARG_TIMETZADT_P, PG_RETURN_UINT32, TimeTzADT::time, and TimeTzADT::zone.

2208 {
2209  TimeTzADT *key = PG_GETARG_TIMETZADT_P(0);
2210  uint32 thash;
2211 
2212  /*
2213  * To avoid any problems with padding bytes in the struct, we figure the
2214  * field hashes separately and XOR them.
2215  */
2217  Int64GetDatumFast(key->time)));
2218  thash ^= DatumGetUInt32(hash_uint32(key->zone));
2219  PG_RETURN_UINT32(thash);
2220 }
#define DatumGetUInt32(X)
Definition: postgres.h:492
TimeADT time
Definition: date.h:28
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:80
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:315
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
unsigned int uint32
Definition: c.h:296
Datum hash_uint32(uint32 k)
Definition: hashfunc.c:853
#define Int64GetDatumFast(X)
Definition: postgres.h:781
Definition: date.h:26

◆ timetz_hash_extended()

Datum timetz_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 2223 of file date.c.

References DatumGetInt64, DatumGetUInt64, DirectFunctionCall2, hash_uint32_extended(), hashint8extended(), Int64GetDatumFast, PG_GETARG_DATUM, PG_GETARG_TIMETZADT_P, PG_RETURN_UINT64, TimeTzADT::time, and TimeTzADT::zone.

2224 {
2225  TimeTzADT *key = PG_GETARG_TIMETZADT_P(0);
2226  Datum seed = PG_GETARG_DATUM(1);
2227  uint64 thash;
2228 
2229  /* Same approach as timetz_hash */
2231  Int64GetDatumFast(key->time),
2232  seed));
2234  DatumGetInt64(seed)));
2235  PG_RETURN_UINT64(thash);
2236 }
TimeADT time
Definition: date.h:28
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfunc.c:874
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:100
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:328
int32 zone
Definition: date.h:29
#define DatumGetInt64(X)
Definition: postgres.h:613
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
uintptr_t Datum
Definition: postgres.h:372
#define Int64GetDatumFast(X)
Definition: postgres.h:781
#define DatumGetUInt64(X)
Definition: postgres.h:640
Definition: date.h:26
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:587

◆ timetz_in()

Datum timetz_in ( PG_FUNCTION_ARGS  )

Definition at line 1953 of file date.c.

References AdjustTimeForTypmod(), DateTimeParseError(), DecodeTimeOnly(), MAXDATEFIELDS, MAXDATELEN, palloc(), ParseDateTime(), PG_GETARG_CSTRING, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_TIMETZADT_P, generate_unaccent_rules::str, TimeTzADT::time, tm, and tm2timetz().

1954 {
1955  char *str = PG_GETARG_CSTRING(0);
1956 
1957 #ifdef NOT_USED
1958  Oid typelem = PG_GETARG_OID(1);
1959 #endif
1960  int32 typmod = PG_GETARG_INT32(2);
1961  TimeTzADT *result;
1962  fsec_t fsec;
1963  struct pg_tm tt,
1964  *tm = &tt;
1965  int tz;
1966  int nf;
1967  int dterr;
1968  char workbuf[MAXDATELEN + 1];
1969  char *field[MAXDATEFIELDS];
1970  int dtype;
1971  int ftype[MAXDATEFIELDS];
1972 
1973  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1974  field, ftype, MAXDATEFIELDS, &nf);
1975  if (dterr == 0)
1976  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1977  if (dterr != 0)
1978  DateTimeParseError(dterr, str, "time with time zone");
1979 
1980  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
1981  tm2timetz(tm, fsec, tz, result);
1982  AdjustTimeForTypmod(&(result->time), typmod);
1983 
1984  PG_RETURN_TIMETZADT_P(result);
1985 }
#define MAXDATELEN
Definition: datetime.h:203
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3765
TimeADT time
Definition: date.h:28
Definition: pgtime.h:25
unsigned int Oid
Definition: postgres_ext.h:31
int DecodeTimeOnly(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:1744
signed int int32
Definition: c.h:284
static struct pg_tm tm
Definition: localtime.c:107
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
int32 fsec_t
Definition: timestamp.h:41
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define MAXDATEFIELDS
Definition: datetime.h:205
static int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:1943
void * palloc(Size size)
Definition: mcxt.c:848
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:562
Definition: date.h:26

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

Definition at line 2731 of file date.c.

References DatumGetCString, Interval::day, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, interval_out(), Interval::month, palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, PointerGetDatum, TimeTzADT::time, Interval::time, USECS_PER_DAY, USECS_PER_SEC, and TimeTzADT::zone.

2732 {
2734  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2735  TimeTzADT *result;
2736  int tz;
2737 
2738  if (zone->month != 0 || zone->day != 0)
2739  ereport(ERROR,
2740  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2741  errmsg("interval time zone \"%s\" must not include months or days",
2743  PointerGetDatum(zone))))));
2744 
2745  tz = -(zone->time / USECS_PER_SEC);
2746 
2747  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2748 
2749  result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2750  while (result->time < INT64CONST(0))
2751  result->time += USECS_PER_DAY;
2752  while (result->time >= USECS_PER_DAY)
2753  result->time -= USECS_PER_DAY;
2754 
2755  result->zone = tz;
2756 
2757  PG_RETURN_TIMETZADT_P(result);
2758 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
#define USECS_PER_SEC
Definition: timestamp.h:94
#define PointerGetDatum(X)
Definition: postgres.h:562
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:958
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:585
int32 day
Definition: timestamp.h:47
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:572
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:122
int32 month
Definition: timestamp.h:48
Definition: zic.c:92
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: date.h:26

◆ timetz_larger()

Datum timetz_larger ( PG_FUNCTION_ARGS  )

Definition at line 2239 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2240 {
2241  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2242  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2243  TimeTzADT *result;
2244 
2245  if (timetz_cmp_internal(time1, time2) > 0)
2246  result = time1;
2247  else
2248  result = time2;
2249  PG_RETURN_TIMETZADT_P(result);
2250 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
Definition: date.h:26

◆ timetz_le()

Datum timetz_le ( PG_FUNCTION_ARGS  )

Definition at line 2171 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2172 {
2173  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2174  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2175 
2176  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0);
2177 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_lt()

Datum timetz_lt ( PG_FUNCTION_ARGS  )

Definition at line 2162 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2163 {
2164  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2165  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2166 
2167  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) < 0);
2168 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_mi_interval()

Datum timetz_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 2292 of file date.c.

References palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, TimeTzADT::time, Interval::time, USECS_PER_DAY, and TimeTzADT::zone.

2293 {
2294  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2295  Interval *span = PG_GETARG_INTERVAL_P(1);
2296  TimeTzADT *result;
2297 
2298  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2299 
2300  result->time = time->time - span->time;
2301  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2302  if (result->time < INT64CONST(0))
2303  result->time += USECS_PER_DAY;
2304 
2305  result->zone = time->zone;
2306 
2307  PG_RETURN_TIMETZADT_P(result);
2308 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:848
Definition: date.h:26

◆ timetz_ne()

Datum timetz_ne ( PG_FUNCTION_ARGS  )

Definition at line 2153 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2154 {
2155  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2156  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2157 
2158  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) != 0);
2159 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Definition: date.h:26

◆ timetz_out()

Datum timetz_out ( PG_FUNCTION_ARGS  )

Definition at line 1988 of file date.c.

References buf, DateStyle, EncodeTimeOnly(), MAXDATELEN, PG_GETARG_TIMETZADT_P, PG_RETURN_CSTRING, pstrdup(), timetz2tm(), and tm.

1989 {
1990  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
1991  char *result;
1992  struct pg_tm tt,
1993  *tm = &tt;
1994  fsec_t fsec;
1995  int tz;
1996  char buf[MAXDATELEN + 1];
1997 
1998  timetz2tm(time, tm, &fsec, &tz);
1999  EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2000 
2001  result = pstrdup(buf);
2002  PG_RETURN_CSTRING(result);
2003 }
#define MAXDATELEN
Definition: datetime.h:203
char * pstrdup(const char *in)
Definition: mcxt.c:1076
static int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2077
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3969
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:107
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
int32 fsec_t
Definition: timestamp.h:41
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
int DateStyle
Definition: globals.c:107
Definition: date.h:26

◆ timetz_part()

Datum timetz_part ( PG_FUNCTION_ARGS  )

Definition at line 2549 of file date.c.

References DecodeSpecial(), DecodeUnits(), downcase_truncate_identifier(), DTK_CENTURY, DTK_DAY, DTK_DECADE, DTK_EPOCH, DTK_HOUR, DTK_MICROSEC, DTK_MILLENNIUM, DTK_MILLISEC, DTK_MINUTE, DTK_MONTH, DTK_QUARTER, DTK_SECOND, DTK_TZ, DTK_TZ_HOUR, DTK_TZ_MINUTE, DTK_YEAR, ereport, errcode(), errmsg(), ERROR, FMODULO, PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, PG_RETURN_FLOAT8, RESERV, SECS_PER_HOUR, SECS_PER_MINUTE, TimeTzADT::time, timetz2tm(), tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, generate_unaccent_rules::type, UNITS, UNKNOWN_FIELD, val, VARDATA_ANY, VARSIZE_ANY_EXHDR, and TimeTzADT::zone.

2550 {
2551  text *units = PG_GETARG_TEXT_PP(0);
2552  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2553  float8 result;
2554  int type,
2555  val;
2556  char *lowunits;
2557 
2558  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
2559  VARSIZE_ANY_EXHDR(units),
2560  false);
2561 
2562  type = DecodeUnits(0, lowunits, &val);
2563  if (type == UNKNOWN_FIELD)
2564  type = DecodeSpecial(0, lowunits, &val);
2565 
2566  if (type == UNITS)
2567  {
2568  double dummy;
2569  int tz;
2570  fsec_t fsec;
2571  struct pg_tm tt,
2572  *tm = &tt;
2573 
2574  timetz2tm(time, tm, &fsec, &tz);
2575 
2576  switch (val)
2577  {
2578  case DTK_TZ:
2579  result = -tz;
2580  break;
2581 
2582  case DTK_TZ_MINUTE:
2583  result = -tz;
2584  result /= SECS_PER_MINUTE;
2585  FMODULO(result, dummy, (double) SECS_PER_MINUTE);
2586  break;
2587 
2588  case DTK_TZ_HOUR:
2589  dummy = -tz;
2590  FMODULO(dummy, result, (double) SECS_PER_HOUR);
2591  break;
2592 
2593  case DTK_MICROSEC:
2594  result = tm->tm_sec * 1000000.0 + fsec;
2595  break;
2596 
2597  case DTK_MILLISEC:
2598  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2599  break;
2600 
2601  case DTK_SECOND:
2602  result = tm->tm_sec + fsec / 1000000.0;
2603  break;
2604 
2605  case DTK_MINUTE:
2606  result = tm->tm_min;
2607  break;
2608 
2609  case DTK_HOUR:
2610  result = tm->tm_hour;
2611  break;
2612 
2613  case DTK_DAY:
2614  case DTK_MONTH:
2615  case DTK_QUARTER:
2616  case DTK_YEAR:
2617  case DTK_DECADE:
2618  case DTK_CENTURY:
2619  case DTK_MILLENNIUM:
2620  default:
2621  ereport(ERROR,
2622  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2623  errmsg("\"time with time zone\" units \"%s\" not recognized",
2624  lowunits)));
2625  result = 0;
2626  }
2627  }
2628  else if (type == RESERV && val == DTK_EPOCH)
2629  {
2630  result = time->time / 1000000.0 + time->zone;
2631  }
2632  else
2633  {
2634  ereport(ERROR,
2635  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2636  errmsg("\"time with time zone\" units \"%s\" not recognized",
2637  lowunits)));
2638  result = 0;
2639  }
2640 
2641  PG_RETURN_FLOAT8(result);
2642 }
#define DTK_TZ_HOUR
Definition: datetime.h:180
#define DTK_CENTURY
Definition: datetime.h:172
#define UNITS
Definition: datetime.h:108
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
TimeADT time
Definition: date.h:28
#define DTK_YEAR
Definition: datetime.h:170
int tm_hour
Definition: pgtime.h:29
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:131
#define DTK_QUARTER
Definition: datetime.h:169
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
#define FMODULO(t, q, u)
Definition: datetime.h:240
static int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2077
#define DTK_MILLENNIUM
Definition: datetime.h:173
int errcode(int sqlerrcode)
Definition: elog.c:575
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3728
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static struct pg_tm tm
Definition: localtime.c:107
#define DTK_MONTH
Definition: datetime.h:168
#define DTK_MILLISEC
Definition: datetime.h:174
#define DTK_DECADE
Definition: datetime.h:171
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:165
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:429
#define DTK_SECOND
Definition: datetime.h:163
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
#define DTK_TZ_MINUTE
Definition: datetime.h:181
#define ereport(elevel, rest)
Definition: elog.h:122
#define SECS_PER_HOUR
Definition: timestamp.h:87
#define DTK_MINUTE
Definition: datetime.h:164
#define DTK_MICROSEC
Definition: datetime.h:175
#define DTK_DAY
Definition: datetime.h:166
#define RESERV
Definition: datetime.h:91
int DecodeSpecial(int field, char *lowtoken, int *val)
Definition: datetime.c:3039
#define DTK_EPOCH
Definition: datetime.h:155
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: c.h:487
int tm_sec
Definition: pgtime.h:27
Definition: date.h:26
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:689

◆ timetz_pl_interval()

Datum timetz_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 2270 of file date.c.

References palloc(), PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, TimeTzADT::time, Interval::time, USECS_PER_DAY, and TimeTzADT::zone.

2271 {
2272  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2273  Interval *span = PG_GETARG_INTERVAL_P(1);
2274  TimeTzADT *result;
2275 
2276  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2277 
2278  result->time = time->time + span->time;
2279  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2280  if (result->time < INT64CONST(0))
2281  result->time += USECS_PER_DAY;
2282 
2283  result->zone = time->zone;
2284 
2285  PG_RETURN_TIMETZADT_P(result);
2286 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:848
Definition: date.h:26

◆ timetz_recv()

Datum timetz_recv ( PG_FUNCTION_ARGS  )

Definition at line 2009 of file date.c.

References AdjustTimeForTypmod(), buf, ereport, errcode(), errmsg(), ERROR, palloc(), PG_GETARG_INT32, PG_GETARG_OID, PG_GETARG_POINTER, PG_RETURN_TIMETZADT_P, pq_getmsgint(), pq_getmsgint64(), TimeTzADT::time, TZDISP_LIMIT, USECS_PER_DAY, and TimeTzADT::zone.

2010 {
2012 
2013 #ifdef NOT_USED
2014  Oid typelem = PG_GETARG_OID(1);
2015 #endif
2016  int32 typmod = PG_GETARG_INT32(2);
2017  TimeTzADT *result;
2018 
2019  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2020 
2021  result->time = pq_getmsgint64(buf);
2022 
2023  if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2024  ereport(ERROR,
2025  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2026  errmsg("time out of range")));
2027 
2028  result->zone = pq_getmsgint(buf, sizeof(result->zone));
2029 
2030  /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2031  if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2032  ereport(ERROR,
2033  (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
2034  errmsg("time zone displacement out of range")));
2035 
2036  AdjustTimeForTypmod(&(result->time), typmod);
2037 
2038  PG_RETURN_TIMETZADT_P(result);
2039 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:284
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:29
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
#define USECS_PER_DAY
Definition: timestamp.h:91
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
#define ereport(elevel, rest)
Definition: elog.h:122
#define TZDISP_LIMIT
Definition: timestamp.h:104
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
Definition: date.h:26

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2099 of file date.c.

References AdjustTimeForTypmod(), palloc(), PG_GETARG_INT32, PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, TimeTzADT::time, and TimeTzADT::zone.

2100 {
2101  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2102  int32 typmod = PG_GETARG_INT32(1);
2103  TimeTzADT *result;
2104 
2105  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2106 
2107  result->time = time->time;
2108  result->zone = time->zone;
2109 
2110  AdjustTimeForTypmod(&(result->time), typmod);
2111 
2112  PG_RETURN_TIMETZADT_P(result);
2113 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
TimeADT time
Definition: date.h:28
signed int int32
Definition: c.h:284
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
static void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1404
void * palloc(Size size)
Definition: mcxt.c:848
Definition: date.h:26

◆ timetz_send()

Datum timetz_send ( PG_FUNCTION_ARGS  )

Definition at line 2045 of file date.c.

References buf, PG_GETARG_TIMETZADT_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint32(), pq_sendint64(), TimeTzADT::time, and TimeTzADT::zone.

2046 {
2047  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2049 
2050  pq_begintypsend(&buf);
2051  pq_sendint64(&buf, time->time);
2052  pq_sendint32(&buf, time->zone);
2054 }
TimeADT time
Definition: date.h:28
static void pq_sendint32(StringInfo buf, int32 i)
Definition: pqformat.h:148
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
static void pq_sendint64(StringInfo buf, int64 i)
Definition: pqformat.h:156
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
int32 zone
Definition: date.h:29
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
Definition: date.h:26

◆ timetz_smaller()

Datum timetz_smaller ( PG_FUNCTION_ARGS  )

Definition at line 2253 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2254 {
2255  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2256  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2257  TimeTzADT *result;
2258 
2259  if (timetz_cmp_internal(time1, time2) < 0)
2260  result = time1;
2261  else
2262  result = time2;
2263  PG_RETURN_TIMETZADT_P(result);
2264 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2117
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
Definition: date.h:26

◆ timetz_time()

Datum timetz_time ( PG_FUNCTION_ARGS  )

Definition at line 2437 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and TimeTzADT::time.

2438 {
2439  TimeTzADT *timetz = PG_GETARG_TIMETZADT_P(0);
2440  TimeADT result;
2441 
2442  /* swallow the time zone and just return the time */
2443  result = timetz->time;
2444 
2445  PG_RETURN_TIMEADT(result);
2446 }
TimeADT time
Definition: date.h:28
#define PG_RETURN_TIMEADT(x)
Definition: date.h:65
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
int64 TimeADT
Definition: date.h:24
Definition: date.h:26

◆ timetz_zone()

Datum timetz_zone ( PG_FUNCTION_ARGS  )

Definition at line 2649 of file date.c.

References DecodeTimezoneAbbrev(), DetermineTimeZoneAbbrevOffset(), downcase_truncate_identifier(), DTZ, DYNTZ, ereport, errcode(), errmsg(), ERROR, now(), palloc(), PG_GETARG_TEXT_PP, PG_GETARG_TIMETZADT_P, pg_localtime(), PG_RETURN_TIMETZADT_P, pg_tzset(), text_to_cstring_buffer(), TimeTzADT::time, tm, pg_tm::tm_gmtoff, generate_unaccent_rules::type, TZ, TZ_STRLEN_MAX, USECS_PER_DAY, USECS_PER_SEC, val, and TimeTzADT::zone.

2650 {
2651  text *zone = PG_GETARG_TEXT_PP(0);
2653  TimeTzADT *result;
2654  int tz;
2655  char tzname[TZ_STRLEN_MAX + 1];
2656  char *lowzone;
2657  int type,
2658  val;
2659  pg_tz *tzp;
2660 
2661  /*
2662  * Look up the requested timezone. First we look in the timezone
2663  * abbreviation table (to handle cases like "EST"), and if that fails, we
2664  * look in the timezone database (to handle cases like
2665  * "America/New_York"). (This matches the order in which timestamp input
2666  * checks the cases; it's important because the timezone database unwisely
2667  * uses a few zone names that are identical to offset abbreviations.)
2668  */
2669  text_to_cstring_buffer(zone, tzname, sizeof(tzname));
2670 
2671  /* DecodeTimezoneAbbrev requires lowercase input */
2672  lowzone = downcase_truncate_identifier(tzname,
2673  strlen(tzname),
2674  false);
2675 
2676  type = DecodeTimezoneAbbrev(0, lowzone, &val, &tzp);
2677 
2678  if (type == TZ || type == DTZ)
2679  {
2680  /* fixed-offset abbreviation */
2681  tz = -val;
2682  }
2683  else if (type == DYNTZ)
2684  {
2685  /* dynamic-offset abbreviation, resolve using current time */
2686  pg_time_t now = (pg_time_t) time(NULL);
2687  struct pg_tm *tm;
2688 
2689  tm = pg_localtime(&now, tzp);
2690  tz = DetermineTimeZoneAbbrevOffset(tm, tzname, tzp);
2691  }
2692  else
2693  {
2694  /* try it as a full zone name */
2695  tzp = pg_tzset(tzname);
2696  if (tzp)
2697  {
2698  /* Get the offset-from-GMT that is valid today for the zone */
2699  pg_time_t now = (pg_time_t) time(NULL);
2700  struct pg_tm *tm;
2701 
2702  tm = pg_localtime(&now, tzp);
2703  tz = -tm->tm_gmtoff;
2704  }
2705  else
2706  {
2707  ereport(ERROR,
2708  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2709  errmsg("time zone \"%s\" not recognized", tzname)));
2710  tz = 0; /* keep compiler quiet */
2711  }
2712  }
2713 
2714  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2715 
2716  result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
2717  while (result->time < INT64CONST(0))
2718  result->time += USECS_PER_DAY;
2719  while (result->time >= USECS_PER_DAY)
2720  result->time -= USECS_PER_DAY;
2721 
2722  result->zone = tz;
2723 
2724  PG_RETURN_TIMETZADT_P(result);
2725 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:66
int64 pg_time_t
Definition: pgtime.h:23
TimeADT time
Definition: date.h:28
#define USECS_PER_SEC
Definition: timestamp.h:94
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:131
int errcode(int sqlerrcode)
Definition: elog.c:575
#define TZ
Definition: datetime.h:96
long int tm_gmtoff
Definition: pgtime.h:36
Definition: pgtime.h:25
void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
Definition: varlena.c:213
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
static struct pg_tm tm
Definition: localtime.c:107
pg_tz * pg_tzset(const char *tzname)
Definition: pgtz.c:243
#define TZ_STRLEN_MAX
Definition: pgtime.h:44
#define ERROR
Definition: elog.h:43
int DecodeTimezoneAbbrev(int field, char *lowtoken, int *offset, pg_tz **tz)
Definition: datetime.c:2984
int32 zone
Definition: date.h:29
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:62
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:122
Definition: pgtz.h:59
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1314
#define DTZ
Definition: datetime.h:97
Definition: zic.c:92
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define DYNTZ
Definition: datetime.h:98
Definition: c.h:487
Definition: date.h:26
int DetermineTimeZoneAbbrevOffset(struct pg_tm *tm, const char *abbr, pg_tz *tzp)
Definition: datetime.c:1629
long val
Definition: informix.c:689
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534

◆ timetztypmodin()

Datum timetztypmodin (