PostgreSQL Source Code  git master
date.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include "access/xact.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "nodes/supportnodes.h"
#include "parser/scansup.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/datetime.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 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)
 
Timestamp date2timestamp_opt_overflow (DateADT dateVal, int *overflow)
 
static TimestampTz date2timestamp (DateADT dateVal)
 
TimestampTz date2timestamptz_opt_overflow (DateADT dateVal, int *overflow)
 
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 in_range_date_interval (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 time_in (PG_FUNCTION_ARGS)
 
int tm2time (struct pg_tm *tm, fsec_t fsec, TimeADT *result)
 
bool time_overflows (int hour, int min, int sec, fsec_t fsec)
 
bool float_time_overflows (int hour, int min, double sec)
 
int time2tm (TimeADT time, struct pg_tm *tm, fsec_t *fsec)
 
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_support (PG_FUNCTION_ARGS)
 
Datum time_scale (PG_FUNCTION_ARGS)
 
void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 
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 in_range_time_interval (PG_FUNCTION_ARGS)
 
Datum time_part (PG_FUNCTION_ARGS)
 
int tm2timetz (struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
 
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)
 
int timetz2tm (TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
 
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 in_range_timetz_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

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)

Definition at line 1498 of file date.c.

References MAX_TIME_PRECISION.

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

1499 {
1500  static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1501  INT64CONST(1000000),
1502  INT64CONST(100000),
1503  INT64CONST(10000),
1504  INT64CONST(1000),
1505  INT64CONST(100),
1506  INT64CONST(10),
1507  INT64CONST(1)
1508  };
1509 
1510  static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1511  INT64CONST(500000),
1512  INT64CONST(50000),
1513  INT64CONST(5000),
1514  INT64CONST(500),
1515  INT64CONST(50),
1516  INT64CONST(5),
1517  INT64CONST(0)
1518  };
1519 
1520  if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1521  {
1522  if (*time >= INT64CONST(0))
1523  *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1524  TimeScales[typmod];
1525  else
1526  *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1527  TimeScales[typmod]);
1528  }
1529 }
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 68 of file date.c.

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

Referenced by anytime_typmodin(), and transformSQLValueFunction().

69 {
70  if (typmod < 0)
71  ereport(ERROR,
72  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
73  errmsg("TIME(%d)%s precision must not be negative",
74  typmod, (istz ? " WITH TIME ZONE" : ""))));
75  if (typmod > MAX_TIME_PRECISION)
76  {
78  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
79  errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
80  typmod, (istz ? " WITH TIME ZONE" : ""),
82  typmod = MAX_TIME_PRECISION;
83  }
84 
85  return typmod;
86 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define ERROR
Definition: elog.h:43
#define WARNING
Definition: elog.h:40
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ anytime_typmodin()

static int32 anytime_typmodin ( bool  istz,
ArrayType ta 
)
static

Definition at line 47 of file date.c.

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

Referenced by timetypmodin(), and timetztypmodin().

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

◆ anytime_typmodout()

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

Definition at line 90 of file date.c.

References psprintf().

Referenced by timetypmodout(), and timetztypmodout().

91 {
92  const char *tz = istz ? " with time zone" : " without time zone";
93 
94  if (typmod >= 0)
95  return psprintf("(%d)%s", (int) typmod, tz);
96  else
97  return psprintf("%s", tz);
98 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46

◆ date2timestamp()

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 708 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

709 {
710  double result;
711 
712  if (DATE_IS_NOBEGIN(dateVal))
713  result = -DBL_MAX;
714  else if (DATE_IS_NOEND(dateVal))
715  result = DBL_MAX;
716  else
717  {
718  /* date is days since 2000, timestamp is microseconds since same... */
719  result = dateVal * (double) USECS_PER_DAY;
720  }
721 
722  return result;
723 }
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define USECS_PER_DAY
Definition: timestamp.h:91
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40

◆ date2timestamp_opt_overflow()

Timestamp date2timestamp_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 563 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 cmpDateToTimestamp(), and date2timestamp().

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

◆ date2timestamptz()

◆ date2timestamptz_opt_overflow()

TimestampTz date2timestamptz_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 617 of file date.c.

References Assert, DATE_IS_NOBEGIN, DATE_IS_NOEND, DetermineTimeZoneOffset(), END_TIMESTAMP, ereport, errcode(), errmsg(), ERROR, IS_VALID_TIMESTAMP, j2date(), MIN_TIMESTAMP, 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 cmpDateToTimestampTz(), and date2timestamptz().

618 {
619  TimestampTz result;
620  struct pg_tm tt,
621  *tm = &tt;
622  int tz;
623 
624  if (DATE_IS_NOBEGIN(dateVal))
625  TIMESTAMP_NOBEGIN(result);
626  else if (DATE_IS_NOEND(dateVal))
627  TIMESTAMP_NOEND(result);
628  else
629  {
630  /*
631  * Date's range is wider than timestamp's, so check for boundaries.
632  * Since dates have the same minimum values as timestamps, only upper
633  * boundary need be checked for overflow.
634  */
635  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
636  {
637  if (overflow)
638  {
639  *overflow = 1;
640  return (TimestampTz) 0;
641  }
642  else
643  {
644  ereport(ERROR,
645  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
646  errmsg("date out of range for timestamp")));
647  }
648  }
649 
650  j2date(dateVal + POSTGRES_EPOCH_JDATE,
651  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
652  tm->tm_hour = 0;
653  tm->tm_min = 0;
654  tm->tm_sec = 0;
656 
657  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
658 
659  /*
660  * Since it is possible to go beyond allowed timestamptz range because
661  * of time zone, check for allowed timestamp range after adding tz.
662  */
663  if (!IS_VALID_TIMESTAMP(result))
664  {
665  if (overflow)
666  {
667  if (result < MIN_TIMESTAMP)
668  *overflow = -1;
669  else
670  {
671  Assert(result >= END_TIMESTAMP);
672  *overflow = 1;
673  }
674  return (TimestampTz) 0;
675  }
676  else
677  {
678  ereport(ERROR,
679  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
680  errmsg("date out of range for timestamp")));
681  }
682  }
683  }
684 
685  return result;
686 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28
#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:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#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:1433
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define MIN_TIMESTAMP
Definition: timestamp.h:184
#define USECS_PER_DAY
Definition: timestamp.h:91
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:294
#define END_TIMESTAMP
Definition: timestamp.h:186
#define ereport(elevel,...)
Definition: elog.h:144
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40
#define Assert(condition)
Definition: c.h:745
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:195
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
#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 429 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_INT32.

Referenced by compareDatetime(), gbt_datekey_cmp(), and leftmostvalue_date().

430 {
431  DateADT dateVal1 = PG_GETARG_DATEADT(0);
432  DateADT dateVal2 = PG_GETARG_DATEADT(1);
433 
434  if (dateVal1 < dateVal2)
435  PG_RETURN_INT32(-1);
436  else if (dateVal1 > dateVal2)
437  PG_RETURN_INT32(1);
438  PG_RETURN_INT32(0);
439 }
int32 DateADT
Definition: date.h:23
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_DATEADT(n)
Definition: date.h:61

◆ date_cmp_timestamp()

Datum date_cmp_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 803 of file date.c.

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

804 {
805  DateADT dateVal = PG_GETARG_DATEADT(0);
807  Timestamp dt1;
808 
809  dt1 = date2timestamp(dateVal);
810 
812 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 887 of file date.c.

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

888 {
889  DateADT dateVal = PG_GETARG_DATEADT(0);
891  TimestampTz dt1;
892 
893  dt1 = date2timestamptz(dateVal);
894 
896 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#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 375 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dateeq().

376 {
377  DateADT dateVal1 = PG_GETARG_DATEADT(0);
378  DateADT dateVal2 = PG_GETARG_DATEADT(1);
379 
380  PG_RETURN_BOOL(dateVal1 == dateVal2);
381 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_eq_timestamp()

Datum date_eq_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 731 of file date.c.

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

732 {
733  DateADT dateVal = PG_GETARG_DATEADT(0);
735  Timestamp dt1;
736 
737  dt1 = date2timestamp(dateVal);
738 
739  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
740 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_eq_timestamptz()

Datum date_eq_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 815 of file date.c.

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

816 {
817  DateADT dateVal = PG_GETARG_DATEADT(0);
819  TimestampTz dt1;
820 
821  dt1 = date2timestamptz(dateVal);
822 
824 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 442 of file date.c.

References DatumGetDateADT.

Referenced by date_sortsupport().

443 {
444  DateADT a = DatumGetDateADT(x);
445  DateADT b = DatumGetDateADT(y);
446 
447  if (a < b)
448  return -1;
449  else if (a > b)
450  return 1;
451  return 0;
452 }
#define DatumGetDateADT(X)
Definition: date.h:53
int32 DateADT
Definition: date.h:23

◆ date_finite()

Datum date_finite ( PG_FUNCTION_ARGS  )

Definition at line 464 of file date.c.

References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.

465 {
467 
469 }
int32 DateADT
Definition: date.h:23
long date
Definition: pgtypes_date.h:9
#define DATE_NOT_FINITE(j)
Definition: date.h:43
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_ge()

Datum date_ge ( PG_FUNCTION_ARGS  )

Definition at line 420 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datege().

421 {
422  DateADT dateVal1 = PG_GETARG_DATEADT(0);
423  DateADT dateVal2 = PG_GETARG_DATEADT(1);
424 
425  PG_RETURN_BOOL(dateVal1 >= dateVal2);
426 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_ge_timestamp()

Datum date_ge_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 791 of file date.c.

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

792 {
793  DateADT dateVal = PG_GETARG_DATEADT(0);
795  Timestamp dt1;
796 
797  dt1 = date2timestamp(dateVal);
798 
799  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
800 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_ge_timestamptz()

Datum date_ge_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 875 of file date.c.

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

876 {
877  DateADT dateVal = PG_GETARG_DATEADT(0);
879  TimestampTz dt1;
880 
881  dt1 = date2timestamptz(dateVal);
882 
884 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 411 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dategt().

412 {
413  DateADT dateVal1 = PG_GETARG_DATEADT(0);
414  DateADT dateVal2 = PG_GETARG_DATEADT(1);
415 
416  PG_RETURN_BOOL(dateVal1 > dateVal2);
417 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_gt_timestamp()

Datum date_gt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 767 of file date.c.

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

768 {
769  DateADT dateVal = PG_GETARG_DATEADT(0);
771  Timestamp dt1;
772 
773  dt1 = date2timestamp(dateVal);
774 
775  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
776 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_gt_timestamptz()

Datum date_gt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 851 of file date.c.

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

852 {
853  DateADT dateVal = PG_GETARG_DATEADT(0);
855  TimestampTz dt1;
856 
857  dt1 = date2timestamptz(dateVal);
858 
860 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 110 of file date.c.

References date2j(), DATE_NOBEGIN, DATE_NOEND, DateTimeParseError(), DecodeDateTime(), DTERR_BAD_FORMAT, DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_LATE, ereport, errcode(), errmsg(), ERROR, 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.

111 {
112  char *str = PG_GETARG_CSTRING(0);
113  DateADT date;
114  fsec_t fsec;
115  struct pg_tm tt,
116  *tm = &tt;
117  int tzp;
118  int dtype;
119  int nf;
120  int dterr;
121  char *field[MAXDATEFIELDS];
122  int ftype[MAXDATEFIELDS];
123  char workbuf[MAXDATELEN + 1];
124 
125  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
126  field, ftype, MAXDATEFIELDS, &nf);
127  if (dterr == 0)
128  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
129  if (dterr != 0)
130  DateTimeParseError(dterr, str, "date");
131 
132  switch (dtype)
133  {
134  case DTK_DATE:
135  break;
136 
137  case DTK_EPOCH:
138  GetEpochTime(tm);
139  break;
140 
141  case DTK_LATE:
142  DATE_NOEND(date);
143  PG_RETURN_DATEADT(date);
144 
145  case DTK_EARLY:
146  DATE_NOBEGIN(date);
147  PG_RETURN_DATEADT(date);
148 
149  default:
150  DateTimeParseError(DTERR_BAD_FORMAT, str, "date");
151  break;
152  }
153 
154  /* Prevent overflow in Julian-day routines */
155  if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
156  ereport(ERROR,
157  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
158  errmsg("date out of range: \"%s\"", str)));
159 
160  date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
161 
162  /* Now check for just-out-of-range dates */
163  if (!IS_VALID_DATE(date))
164  ereport(ERROR,
165  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
166  errmsg("date out of range: \"%s\"", str)));
167 
168  PG_RETURN_DATEADT(date);
169 }
#define MAXDATELEN
Definition: datetime.h:201
#define DTERR_BAD_FORMAT
Definition: datetime.h:280
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3723
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:610
long date
Definition: pgtypes_date.h:9
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOBEGIN(j)
Definition: date.h:39
#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:758
#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 DTK_LATE
Definition: datetime.h:152
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
#define DTK_EARLY
Definition: datetime.h:151
#define MAXDATEFIELDS
Definition: datetime.h:203
#define DTK_EPOCH
Definition: datetime.h:153
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
void GetEpochTime(struct pg_tm *tm)
Definition: timestamp.c:2010
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:65
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:537
#define DTK_DATE
Definition: datetime.h:145
#define DATE_NOEND(j)
Definition: date.h:41

◆ date_larger()

Datum date_larger ( PG_FUNCTION_ARGS  )

Definition at line 472 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

473 {
474  DateADT dateVal1 = PG_GETARG_DATEADT(0);
475  DateADT dateVal2 = PG_GETARG_DATEADT(1);
476 
477  PG_RETURN_DATEADT((dateVal1 > dateVal2) ? dateVal1 : dateVal2);
478 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_le()

Datum date_le ( PG_FUNCTION_ARGS  )

Definition at line 402 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datele().

403 {
404  DateADT dateVal1 = PG_GETARG_DATEADT(0);
405  DateADT dateVal2 = PG_GETARG_DATEADT(1);
406 
407  PG_RETURN_BOOL(dateVal1 <= dateVal2);
408 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_le_timestamp()

Datum date_le_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 779 of file date.c.

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

780 {
781  DateADT dateVal = PG_GETARG_DATEADT(0);
783  Timestamp dt1;
784 
785  dt1 = date2timestamp(dateVal);
786 
787  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
788 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_le_timestamptz()

Datum date_le_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 863 of file date.c.

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

864 {
865  DateADT dateVal = PG_GETARG_DATEADT(0);
867  TimestampTz dt1;
868 
869  dt1 = date2timestamptz(dateVal);
870 
872 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 393 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datelt().

394 {
395  DateADT dateVal1 = PG_GETARG_DATEADT(0);
396  DateADT dateVal2 = PG_GETARG_DATEADT(1);
397 
398  PG_RETURN_BOOL(dateVal1 < dateVal2);
399 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_lt_timestamp()

Datum date_lt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 755 of file date.c.

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

756 {
757  DateADT dateVal = PG_GETARG_DATEADT(0);
759  Timestamp dt1;
760 
761  dt1 = date2timestamp(dateVal);
762 
763  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
764 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_lt_timestamptz()

Datum date_lt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 839 of file date.c.

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

840 {
841  DateADT dateVal = PG_GETARG_DATEADT(0);
843  TimestampTz dt1;
844 
845  dt1 = date2timestamptz(dateVal);
846 
848 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 492 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().

493 {
494  DateADT dateVal1 = PG_GETARG_DATEADT(0);
495  DateADT dateVal2 = PG_GETARG_DATEADT(1);
496 
497  if (DATE_NOT_FINITE(dateVal1) || DATE_NOT_FINITE(dateVal2))
498  ereport(ERROR,
499  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
500  errmsg("cannot subtract infinite dates")));
501 
502  PG_RETURN_INT32((int32) (dateVal1 - dateVal2));
503 }
int32 DateADT
Definition: date.h:23
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:43
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824

◆ date_mi_interval()

Datum date_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1122 of file date.c.

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

1123 {
1124  DateADT dateVal = PG_GETARG_DATEADT(0);
1125  Interval *span = PG_GETARG_INTERVAL_P(1);
1126  Timestamp dateStamp;
1127 
1128  dateStamp = date2timestamp(dateVal);
1129 
1131  TimestampGetDatum(dateStamp),
1132  PointerGetDatum(span));
1133 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:23
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum timestamp_mi_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:2903
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define TimestampGetDatum(X)
Definition: timestamp.h:31
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ date_mii()

Datum date_mii ( PG_FUNCTION_ARGS  )

Definition at line 533 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.

534 {
535  DateADT dateVal = PG_GETARG_DATEADT(0);
537  DateADT result;
538 
539  if (DATE_NOT_FINITE(dateVal))
540  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
541 
542  result = dateVal - days;
543 
544  /* Check for integer overflow and out-of-allowed-range */
545  if ((days >= 0 ? (result > dateVal) : (result < dateVal)) ||
546  !IS_VALID_DATE(result))
547  ereport(ERROR,
548  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
549  errmsg("date out of range")));
550 
551  PG_RETURN_DATEADT(result);
552 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:43
const char *const days[]
Definition: datetime.c:68
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_ne()

Datum date_ne ( PG_FUNCTION_ARGS  )

Definition at line 384 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

385 {
386  DateADT dateVal1 = PG_GETARG_DATEADT(0);
387  DateADT dateVal2 = PG_GETARG_DATEADT(1);
388 
389  PG_RETURN_BOOL(dateVal1 != dateVal2);
390 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ date_ne_timestamp()

Datum date_ne_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 743 of file date.c.

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

744 {
745  DateADT dateVal = PG_GETARG_DATEADT(0);
747  Timestamp dt1;
748 
749  dt1 = date2timestamp(dateVal);
750 
751  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
752 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_ne_timestamptz()

Datum date_ne_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 827 of file date.c.

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

828 {
829  DateADT dateVal = PG_GETARG_DATEADT(0);
831  TimestampTz dt1;
832 
833  dt1 = date2timestamptz(dateVal);
834 
836 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 175 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.

176 {
178  char *result;
179  struct pg_tm tt,
180  *tm = &tt;
181  char buf[MAXDATELEN + 1];
182 
183  if (DATE_NOT_FINITE(date))
184  EncodeSpecialDate(date, buf);
185  else
186  {
188  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
189  EncodeDateOnly(tm, DateStyle, buf);
190  }
191 
192  result = pstrdup(buf);
193  PG_RETURN_CSTRING(result);
194 }
#define MAXDATELEN
Definition: datetime.h:201
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition: datetime.c:3842
int32 DateADT
Definition: date.h:23
char * pstrdup(const char *in)
Definition: mcxt.c:1186
long date
Definition: pgtypes_date.h:9
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOT_FINITE(j)
Definition: date.h:43
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:285
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:294
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
int DateStyle
Definition: globals.c:115
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 1102 of file date.c.

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

1103 {
1104  DateADT dateVal = PG_GETARG_DATEADT(0);
1105  Interval *span = PG_GETARG_INTERVAL_P(1);
1106  Timestamp dateStamp;
1107 
1108  dateStamp = date2timestamp(dateVal);
1109 
1111  TimestampGetDatum(dateStamp),
1112  PointerGetDatum(span));
1113 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:23
#define PointerGetDatum(X)
Definition: postgres.h:556
Datum timestamp_pl_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:2824
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define TimestampGetDatum(X)
Definition: timestamp.h:31
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ date_pli()

Datum date_pli ( PG_FUNCTION_ARGS  )

Definition at line 509 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().

510 {
511  DateADT dateVal = PG_GETARG_DATEADT(0);
513  DateADT result;
514 
515  if (DATE_NOT_FINITE(dateVal))
516  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
517 
518  result = dateVal + days;
519 
520  /* Check for integer overflow and out-of-allowed-range */
521  if ((days >= 0 ? (result < dateVal) : (result > dateVal)) ||
522  !IS_VALID_DATE(result))
523  ereport(ERROR,
524  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
525  errmsg("date out of range")));
526 
527  PG_RETURN_DATEADT(result);
528 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:43
const char *const days[]
Definition: datetime.c:68
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_recv()

Datum date_recv ( PG_FUNCTION_ARGS  )

Definition at line 200 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().

201 {
203  DateADT result;
204 
205  result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
206 
207  /* Limit to the same range that date_in() accepts. */
208  if (DATE_NOT_FINITE(result))
209  /* ok */ ;
210  else if (!IS_VALID_DATE(result))
211  ereport(ERROR,
212  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
213  errmsg("date out of range")));
214 
215  PG_RETURN_DATEADT(result);
216 }
int32 DateADT
Definition: date.h:23
StringInfoData * StringInfo
Definition: stringinfo.h:44
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define IS_VALID_DATE(d)
Definition: timestamp.h:190
#define ERROR
Definition: elog.h:43
#define DATE_NOT_FINITE(j)
Definition: date.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_send()

Datum date_send ( PG_FUNCTION_ARGS  )

Definition at line 222 of file date.c.

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

223 {
226 
227  pq_begintypsend(&buf);
228  pq_sendint32(&buf, date);
230 }
int32 DateADT
Definition: date.h:23
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
long date
Definition: pgtypes_date.h:9
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_DATEADT(n)
Definition: date.h:61

◆ date_smaller()

Datum date_smaller ( PG_FUNCTION_ARGS  )

Definition at line 481 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

482 {
483  DateADT dateVal1 = PG_GETARG_DATEADT(0);
484  DateADT dateVal2 = PG_GETARG_DATEADT(1);
485 
486  PG_RETURN_DATEADT((dateVal1 < dateVal2) ? dateVal1 : dateVal2);
487 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_sortsupport()

Datum date_sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 455 of file date.c.

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

456 {
458 
459  ssup->comparator = date_fastcmp;
460  PG_RETURN_VOID();
461 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
static int date_fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: date.c:442
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:106
#define PG_RETURN_VOID()
Definition: fmgr.h:348

◆ date_timestamp()

Datum date_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1139 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1140 {
1141  DateADT dateVal = PG_GETARG_DATEADT(0);
1142  Timestamp result;
1143 
1144  result = date2timestamp(dateVal);
1145 
1146  PG_RETURN_TIMESTAMP(result);
1147 }
int32 DateADT
Definition: date.h:23
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1183 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1184 {
1185  DateADT dateVal = PG_GETARG_DATEADT(0);
1186  TimestampTz result;
1187 
1188  result = date2timestamptz(dateVal);
1189 
1190  PG_RETURN_TIMESTAMP(result);
1191 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1819 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.

1820 {
1822  TimeADT time = PG_GETARG_TIMEADT(1);
1823  Timestamp result;
1824 
1825  result = date2timestamp(date);
1826  if (!TIMESTAMP_NOT_FINITE(result))
1827  {
1828  result += time;
1829  if (!IS_VALID_TIMESTAMP(result))
1830  ereport(ERROR,
1831  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1832  errmsg("timestamp out of range")));
1833  }
1834 
1835  PG_RETURN_TIMESTAMP(result);
1836 }
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:610
long date
Definition: pgtypes_date.h:9
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
#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:824
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 2681 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.

2682 {
2684  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2685  TimestampTz result;
2686 
2687  if (DATE_IS_NOBEGIN(date))
2688  TIMESTAMP_NOBEGIN(result);
2689  else if (DATE_IS_NOEND(date))
2690  TIMESTAMP_NOEND(result);
2691  else
2692  {
2693  /*
2694  * Date's range is wider than timestamp's, so check for boundaries.
2695  * Since dates have the same minimum values as timestamps, only upper
2696  * boundary need be checked for overflow.
2697  */
2699  ereport(ERROR,
2700  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2701  errmsg("date out of range for timestamp")));
2702  result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
2703 
2704  /*
2705  * Since it is possible to go beyond allowed timestamptz range because
2706  * of time zone, check for allowed timestamp range after adding tz.
2707  */
2708  if (!IS_VALID_TIMESTAMP(result))
2709  ereport(ERROR,
2710  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2711  errmsg("date out of range for timestamp")));
2712  }
2713 
2714  PG_RETURN_TIMESTAMP(result);
2715 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
TimeADT time
Definition: date.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
int errcode(int sqlerrcode)
Definition: elog.c:610
long date
Definition: pgtypes_date.h:9
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define USECS_PER_DAY
Definition: timestamp.h:91
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define ereport(elevel,...)
Definition: elog.h:144
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40
#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:824
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
Definition: date.h:27

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 285 of file date.c.

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

Referenced by date_out(), and JsonEncodeDateTime().

286 {
287  if (DATE_IS_NOBEGIN(dt))
288  strcpy(str, EARLY);
289  else if (DATE_IS_NOEND(dt))
290  strcpy(str, LATE);
291  else /* shouldn't happen */
292  elog(ERROR, "invalid argument for EncodeSpecialDate");
293 }
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define LATE
Definition: datetime.h:41
#define ERROR
Definition: elog.h:43
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40
#define elog(elevel,...)
Definition: elog.h:214
#define EARLY
Definition: datetime.h:40

◆ float_time_overflows()

bool float_time_overflows ( int  hour,
int  min,
double  sec 
)

Definition at line 1302 of file date.c.

References HOURS_PER_DAY, MINS_PER_HOUR, SECS_PER_MINUTE, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by make_time(), and make_timestamp_internal().

1303 {
1304  /* Range-check the fields individually. */
1305  if (hour < 0 || hour > HOURS_PER_DAY ||
1306  min < 0 || min >= MINS_PER_HOUR)
1307  return true;
1308 
1309  /*
1310  * "sec", being double, requires extra care. Cope with NaN, and round off
1311  * before applying the range check to avoid unexpected errors due to
1312  * imprecise input. (We assume rint() behaves sanely with infinities.)
1313  */
1314  if (isnan(sec))
1315  return true;
1316  sec = rint(sec * USECS_PER_SEC);
1317  if (sec < 0 || sec > SECS_PER_MINUTE * USECS_PER_SEC)
1318  return true;
1319 
1320  /*
1321  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1322  * that the total time value doesn't exceed 24:00:00. This must match the
1323  * way that callers will convert the fields to a time.
1324  */
1325  if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1326  * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1327  return true;
1328 
1329  return false;
1330 }
#define USECS_PER_SEC
Definition: timestamp.h:94
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 300 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().

301 {
302  TimestampTz ts;
303  struct pg_tm tt,
304  *tm = &tt;
305  fsec_t fsec;
306  int tz;
307 
309 
310  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
311  ereport(ERROR,
312  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
313  errmsg("timestamp out of range")));
314 
315  return date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
316 }
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#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
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:785
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ GetSQLCurrentTime()

TimeTzADT* GetSQLCurrentTime ( int32  typmod)

Definition at line 322 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

323 {
324  TimeTzADT *result;
325  TimestampTz ts;
326  struct pg_tm tt,
327  *tm = &tt;
328  fsec_t fsec;
329  int tz;
330 
332 
333  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
334  ereport(ERROR,
335  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
336  errmsg("timestamp out of range")));
337 
338  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
339  tm2timetz(tm, fsec, tz, result);
340  AdjustTimeForTypmod(&(result->time), typmod);
341  return result;
342 }
TimeADT time
Definition: date.h:29
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2076
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:785
#define ereport(elevel,...)
Definition: elog.h:144
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 348 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

349 {
350  TimeADT result;
351  TimestampTz ts;
352  struct pg_tm tt,
353  *tm = &tt;
354  fsec_t fsec;
355  int tz;
356 
358 
359  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
360  ereport(ERROR,
361  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
362  errmsg("timestamp out of range")));
363 
364  tm2time(tm, fsec, &result);
365  AdjustTimeForTypmod(&result, typmod);
366  return result;
367 }
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:785
#define ereport(elevel,...)
Definition: elog.h:144
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1267
int errmsg(const char *fmt,...)
Definition: elog.c:824
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ in_range_date_interval()

Datum in_range_date_interval ( PG_FUNCTION_ARGS  )

Definition at line 1073 of file date.c.

References BoolGetDatum, date2timestamp(), DirectFunctionCall5, in_range_timestamp_interval(), IntervalPGetDatum, PG_GETARG_BOOL, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, TimestampGetDatum, and val.

1074 {
1076  DateADT base = PG_GETARG_DATEADT(1);
1077  Interval *offset = PG_GETARG_INTERVAL_P(2);
1078  bool sub = PG_GETARG_BOOL(3);
1079  bool less = PG_GETARG_BOOL(4);
1080  Timestamp valStamp;
1081  Timestamp baseStamp;
1082 
1083  valStamp = date2timestamp(val);
1084  baseStamp = date2timestamp(base);
1085 
1087  TimestampGetDatum(valStamp),
1088  TimestampGetDatum(baseStamp),
1089  IntervalPGetDatum(offset),
1090  BoolGetDatum(sub),
1091  BoolGetDatum(less));
1092 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:23
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define IntervalPGetDatum(X)
Definition: timestamp.h:33
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define TimestampGetDatum(X)
Definition: timestamp.h:31
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:632
int64 Timestamp
Definition: timestamp.h:38
#define BoolGetDatum(X)
Definition: postgres.h:402
Datum in_range_timestamp_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:3332
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604
long val
Definition: informix.c:664

◆ in_range_time_interval()

Datum in_range_time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1945 of file date.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOOL, PG_GETARG_INTERVAL_P, PG_GETARG_TIMEADT, PG_RETURN_BOOL, Interval::time, and val.

1946 {
1948  TimeADT base = PG_GETARG_TIMEADT(1);
1949  Interval *offset = PG_GETARG_INTERVAL_P(2);
1950  bool sub = PG_GETARG_BOOL(3);
1951  bool less = PG_GETARG_BOOL(4);
1952  TimeADT sum;
1953 
1954  /*
1955  * Like time_pl_interval/time_mi_interval, we disregard the month and day
1956  * fields of the offset. So our test for negative should too.
1957  */
1958  if (offset->time < 0)
1959  ereport(ERROR,
1960  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1961  errmsg("invalid preceding or following size in window function")));
1962 
1963  /*
1964  * We can't use time_pl_interval/time_mi_interval here, because their
1965  * wraparound behavior would give wrong (or at least undesirable) answers.
1966  * Fortunately the equivalent non-wrapping behavior is trivial, especially
1967  * since we don't worry about integer overflow.
1968  */
1969  if (sub)
1970  sum = base - offset->time;
1971  else
1972  sum = base + offset->time;
1973 
1974  if (less)
1975  PG_RETURN_BOOL(val <= sum);
1976  else
1977  PG_RETURN_BOOL(val >= sum);
1978 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define ERROR
Definition: elog.h:43
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
int errmsg(const char *fmt,...)
Definition: elog.c:824
long val
Definition: informix.c:664

◆ in_range_timetz_interval()

Datum in_range_timetz_interval ( PG_FUNCTION_ARGS  )

Definition at line 2447 of file date.c.

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_BOOL, PG_GETARG_INTERVAL_P, PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, TimeTzADT::time, Interval::time, timetz_cmp_internal(), val, and TimeTzADT::zone.

2448 {
2450  TimeTzADT *base = PG_GETARG_TIMETZADT_P(1);
2451  Interval *offset = PG_GETARG_INTERVAL_P(2);
2452  bool sub = PG_GETARG_BOOL(3);
2453  bool less = PG_GETARG_BOOL(4);
2454  TimeTzADT sum;
2455 
2456  /*
2457  * Like timetz_pl_interval/timetz_mi_interval, we disregard the month and
2458  * day fields of the offset. So our test for negative should too.
2459  */
2460  if (offset->time < 0)
2461  ereport(ERROR,
2462  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
2463  errmsg("invalid preceding or following size in window function")));
2464 
2465  /*
2466  * We can't use timetz_pl_interval/timetz_mi_interval here, because their
2467  * wraparound behavior would give wrong (or at least undesirable) answers.
2468  * Fortunately the equivalent non-wrapping behavior is trivial, especially
2469  * since we don't worry about integer overflow.
2470  */
2471  if (sub)
2472  sum.time = base->time - offset->time;
2473  else
2474  sum.time = base->time + offset->time;
2475  sum.zone = base->zone;
2476 
2477  if (less)
2478  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) <= 0);
2479  else
2480  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) >= 0);
2481 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
TimeADT time
Definition: date.h:29
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: date.h:27
long val
Definition: informix.c:664

◆ interval_time()

Datum interval_time ( PG_FUNCTION_ARGS  )

Definition at line 1865 of file date.c.

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

1866 {
1867  Interval *span = PG_GETARG_INTERVAL_P(0);
1868  TimeADT result;
1869  int64 days;
1870 
1871  result = span->time;
1872  if (result >= USECS_PER_DAY)
1873  {
1874  days = result / USECS_PER_DAY;
1875  result -= days * USECS_PER_DAY;
1876  }
1877  else if (result < 0)
1878  {
1879  days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
1880  result += days * USECS_PER_DAY;
1881  }
1882 
1883  PG_RETURN_TIMEADT(result);
1884 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
TimeOffset time
Definition: timestamp.h:45
const char *const days[]
Definition: datetime.c:68
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ make_date()

Datum make_date ( PG_FUNCTION_ARGS  )

Definition at line 236 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().

237 {
238  struct pg_tm tm;
239  DateADT date;
240  int dterr;
241  bool bc = false;
242 
246 
247  /* Handle negative years as BC */
248  if (tm.tm_year < 0)
249  {
250  bc = true;
251  tm.tm_year = -tm.tm_year;
252  }
253 
254  dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
255 
256  if (dterr != 0)
257  ereport(ERROR,
258  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
259  errmsg("date field value out of range: %d-%02d-%02d",
260  tm.tm_year, tm.tm_mon, tm.tm_mday)));
261 
262  /* Prevent overflow in Julian-day routines */
264  ereport(ERROR,
265  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
266  errmsg("date out of range: %d-%02d-%02d",
267  tm.tm_year, tm.tm_mon, tm.tm_mday)));
268 
270 
271  /* Now check for just-out-of-range dates */
272  if (!IS_VALID_DATE(date))
273  ereport(ERROR,
274  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
275  errmsg("date out of range: %d-%02d-%02d",
276  tm.tm_year, tm.tm_mon, tm.tm_mday)));
277 
278  PG_RETURN_DATEADT(date);
279 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:610
long date
Definition: pgtypes_date.h:9
Definition: pgtime.h:25
#define DTK_DATE_M
Definition: datetime.h:192
static struct pg_tm tm
Definition: localtime.c:102
#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
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
#define PG_RETURN_DATEADT(x)
Definition: date.h:65
int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm *tm)
Definition: datetime.c:2435

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1430 of file date.c.

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

1431 {
1432  int tm_hour = PG_GETARG_INT32(0);
1433  int tm_min = PG_GETARG_INT32(1);
1434  double sec = PG_GETARG_FLOAT8(2);
1435  TimeADT time;
1436 
1437  /* Check for time overflow */
1438  if (float_time_overflows(tm_hour, tm_min, sec))
1439  ereport(ERROR,
1440  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
1441  errmsg("time field value out of range: %d:%02d:%02g",
1442  tm_hour, tm_min, sec)));
1443 
1444  /* This should match tm2time */
1445  time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1446  * USECS_PER_SEC) + (int64) rint(sec * USECS_PER_SEC);
1447 
1448  PG_RETURN_TIMEADT(time);
1449 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:610
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int64 TimeADT
Definition: date.h:25
#define ereport(elevel,...)
Definition: elog.h:144
bool float_time_overflows(int hour, int min, double sec)
Definition: date.c:1302
int errmsg(const char *fmt,...)
Definition: elog.c:824
int tm_min
Definition: pgtime.h:28

◆ overlaps_time()

Datum overlaps_time ( PG_FUNCTION_ARGS  )

Definition at line 1636 of file date.c.

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

1637 {
1638  /*
1639  * The arguments are TimeADT, but we leave them as generic Datums to avoid
1640  * dereferencing nulls (TimeADT is pass-by-reference!)
1641  */
1642  Datum ts1 = PG_GETARG_DATUM(0);
1643  Datum te1 = PG_GETARG_DATUM(1);
1644  Datum ts2 = PG_GETARG_DATUM(2);
1645  Datum te2 = PG_GETARG_DATUM(3);
1646  bool ts1IsNull = PG_ARGISNULL(0);
1647  bool te1IsNull = PG_ARGISNULL(1);
1648  bool ts2IsNull = PG_ARGISNULL(2);
1649  bool te2IsNull = PG_ARGISNULL(3);
1650 
1651 #define TIMEADT_GT(t1,t2) \
1652  (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
1653 #define TIMEADT_LT(t1,t2) \
1654  (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
1655 
1656  /*
1657  * If both endpoints of interval 1 are null, the result is null (unknown).
1658  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
1659  * take ts1 as the lesser endpoint.
1660  */
1661  if (ts1IsNull)
1662  {
1663  if (te1IsNull)
1664  PG_RETURN_NULL();
1665  /* swap null for non-null */
1666  ts1 = te1;
1667  te1IsNull = true;
1668  }
1669  else if (!te1IsNull)
1670  {
1671  if (TIMEADT_GT(ts1, te1))
1672  {
1673  Datum tt = ts1;
1674 
1675  ts1 = te1;
1676  te1 = tt;
1677  }
1678  }
1679 
1680  /* Likewise for interval 2. */
1681  if (ts2IsNull)
1682  {
1683  if (te2IsNull)
1684  PG_RETURN_NULL();
1685  /* swap null for non-null */
1686  ts2 = te2;
1687  te2IsNull = true;
1688  }
1689  else if (!te2IsNull)
1690  {
1691  if (TIMEADT_GT(ts2, te2))
1692  {
1693  Datum tt = ts2;
1694 
1695  ts2 = te2;
1696  te2 = tt;
1697  }
1698  }
1699 
1700  /*
1701  * At this point neither ts1 nor ts2 is null, so we can consider three
1702  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
1703  */
1704  if (TIMEADT_GT(ts1, ts2))
1705  {
1706  /*
1707  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
1708  * in the presence of nulls it's not quite completely so.
1709  */
1710  if (te2IsNull)
1711  PG_RETURN_NULL();
1712  if (TIMEADT_LT(ts1, te2))
1713  PG_RETURN_BOOL(true);
1714  if (te1IsNull)
1715  PG_RETURN_NULL();
1716 
1717  /*
1718  * If te1 is not null then we had ts1 <= te1 above, and we just found
1719  * ts1 >= te2, hence te1 >= te2.
1720  */
1721  PG_RETURN_BOOL(false);
1722  }
1723  else if (TIMEADT_LT(ts1, ts2))
1724  {
1725  /* This case is ts2 < te1 OR te2 < te1 */
1726  if (te1IsNull)
1727  PG_RETURN_NULL();
1728  if (TIMEADT_LT(ts2, te1))
1729  PG_RETURN_BOOL(true);
1730  if (te2IsNull)
1731  PG_RETURN_NULL();
1732 
1733  /*
1734  * If te2 is not null then we had ts2 <= te2 above, and we just found
1735  * ts2 >= te1, hence te2 >= te1.
1736  */
1737  PG_RETURN_BOOL(false);
1738  }
1739  else
1740  {
1741  /*
1742  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
1743  * rather silly way of saying "true if both are nonnull, else null".
1744  */
1745  if (te1IsNull || te2IsNull)
1746  PG_RETURN_NULL();
1747  PG_RETURN_BOOL(true);
1748  }
1749 
1750 #undef TIMEADT_GT
1751 #undef TIMEADT_LT
1752 }
#define TIMEADT_LT(t1, t2)
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
uintptr_t Datum
Definition: postgres.h:367
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define TIMEADT_GT(t1, t2)
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ overlaps_timetz()

Datum overlaps_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2490 of file date.c.

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

2491 {
2492  /*
2493  * The arguments are TimeTzADT *, but we leave them as generic Datums for
2494  * convenience of notation --- and to avoid dereferencing nulls.
2495  */
2496  Datum ts1 = PG_GETARG_DATUM(0);
2497  Datum te1 = PG_GETARG_DATUM(1);
2498  Datum ts2 = PG_GETARG_DATUM(2);
2499  Datum te2 = PG_GETARG_DATUM(3);
2500  bool ts1IsNull = PG_ARGISNULL(0);
2501  bool te1IsNull = PG_ARGISNULL(1);
2502  bool ts2IsNull = PG_ARGISNULL(2);
2503  bool te2IsNull = PG_ARGISNULL(3);
2504 
2505 #define TIMETZ_GT(t1,t2) \
2506  DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
2507 #define TIMETZ_LT(t1,t2) \
2508  DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
2509 
2510  /*
2511  * If both endpoints of interval 1 are null, the result is null (unknown).
2512  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
2513  * take ts1 as the lesser endpoint.
2514  */
2515  if (ts1IsNull)
2516  {
2517  if (te1IsNull)
2518  PG_RETURN_NULL();
2519  /* swap null for non-null */
2520  ts1 = te1;
2521  te1IsNull = true;
2522  }
2523  else if (!te1IsNull)
2524  {
2525  if (TIMETZ_GT(ts1, te1))
2526  {
2527  Datum tt = ts1;
2528 
2529  ts1 = te1;
2530  te1 = tt;
2531  }
2532  }
2533 
2534  /* Likewise for interval 2. */
2535  if (ts2IsNull)
2536  {
2537  if (te2IsNull)
2538  PG_RETURN_NULL();
2539  /* swap null for non-null */
2540  ts2 = te2;
2541  te2IsNull = true;
2542  }
2543  else if (!te2IsNull)
2544  {
2545  if (TIMETZ_GT(ts2, te2))
2546  {
2547  Datum tt = ts2;
2548 
2549  ts2 = te2;
2550  te2 = tt;
2551  }
2552  }
2553 
2554  /*
2555  * At this point neither ts1 nor ts2 is null, so we can consider three
2556  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
2557  */
2558  if (TIMETZ_GT(ts1, ts2))
2559  {
2560  /*
2561  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
2562  * in the presence of nulls it's not quite completely so.
2563  */
2564  if (te2IsNull)
2565  PG_RETURN_NULL();
2566  if (TIMETZ_LT(ts1, te2))
2567  PG_RETURN_BOOL(true);
2568  if (te1IsNull)
2569  PG_RETURN_NULL();
2570 
2571  /*
2572  * If te1 is not null then we had ts1 <= te1 above, and we just found
2573  * ts1 >= te2, hence te1 >= te2.
2574  */
2575  PG_RETURN_BOOL(false);
2576  }
2577  else if (TIMETZ_LT(ts1, ts2))
2578  {
2579  /* This case is ts2 < te1 OR te2 < te1 */
2580  if (te1IsNull)
2581  PG_RETURN_NULL();
2582  if (TIMETZ_LT(ts2, te1))
2583  PG_RETURN_BOOL(true);
2584  if (te2IsNull)
2585  PG_RETURN_NULL();
2586 
2587  /*
2588  * If te2 is not null then we had ts2 <= te2 above, and we just found
2589  * ts2 >= te1, hence te2 >= te1.
2590  */
2591  PG_RETURN_BOOL(false);
2592  }
2593  else
2594  {
2595  /*
2596  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
2597  * rather silly way of saying "true if both are nonnull, else null".
2598  */
2599  if (te1IsNull || te2IsNull)
2600  PG_RETURN_NULL();
2601  PG_RETURN_BOOL(true);
2602  }
2603 
2604 #undef TIMETZ_GT
2605 #undef TIMETZ_LT
2606 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define TIMETZ_LT(t1, t2)
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
uintptr_t Datum
Definition: postgres.h:367
#define PG_ARGISNULL(n)
Definition: fmgr.h:209
#define PG_RETURN_NULL()
Definition: fmgr.h:344
#define TIMETZ_GT(t1, t2)

◆ time2tm()

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

Definition at line 1341 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 JsonEncodeDateTime(), time_out(), time_part(), and time_timetz().

1342 {
1343  tm->tm_hour = time / USECS_PER_HOUR;
1344  time -= tm->tm_hour * USECS_PER_HOUR;
1345  tm->tm_min = time / USECS_PER_MINUTE;
1346  time -= tm->tm_min * USECS_PER_MINUTE;
1347  tm->tm_sec = time / USECS_PER_SEC;
1348  time -= tm->tm_sec * USECS_PER_SEC;
1349  *fsec = time;
1350  return 0;
1351 }
#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 1587 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_INT32.

Referenced by compareDatetime(), gbt_timekey_cmp(), and leftmostvalue_time().

1588 {
1589  TimeADT time1 = PG_GETARG_TIMEADT(0);
1590  TimeADT time2 = PG_GETARG_TIMEADT(1);
1591 
1592  if (time1 < time2)
1593  PG_RETURN_INT32(-1);
1594  if (time1 > time2)
1595  PG_RETURN_INT32(1);
1596  PG_RETURN_INT32(0);
1597 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_eq()

Datum time_eq ( PG_FUNCTION_ARGS  )

Definition at line 1533 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

1534 {
1535  TimeADT time1 = PG_GETARG_TIMEADT(0);
1536  TimeADT time2 = PG_GETARG_TIMEADT(1);
1537 
1538  PG_RETURN_BOOL(time1 == time2);
1539 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_ge()

Datum time_ge ( PG_FUNCTION_ARGS  )

Definition at line 1578 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

1579 {
1580  TimeADT time1 = PG_GETARG_TIMEADT(0);
1581  TimeADT time2 = PG_GETARG_TIMEADT(1);
1582 
1583  PG_RETURN_BOOL(time1 >= time2);
1584 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_gt()

Datum time_gt ( PG_FUNCTION_ARGS  )

Definition at line 1569 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

1570 {
1571  TimeADT time1 = PG_GETARG_TIMEADT(0);
1572  TimeADT time2 = PG_GETARG_TIMEADT(1);
1573 
1574  PG_RETURN_BOOL(time1 > time2);
1575 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_hash()

Datum time_hash ( PG_FUNCTION_ARGS  )

Definition at line 1600 of file date.c.

References hashint8().

1601 {
1602  return hashint8(fcinfo);
1603 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1606 of file date.c.

References hashint8extended().

1607 {
1608  return hashint8extended(fcinfo);
1609 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

Definition at line 1230 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().

1231 {
1232  char *str = PG_GETARG_CSTRING(0);
1233 
1234 #ifdef NOT_USED
1235  Oid typelem = PG_GETARG_OID(1);
1236 #endif
1237  int32 typmod = PG_GETARG_INT32(2);
1238  TimeADT result;
1239  fsec_t fsec;
1240  struct pg_tm tt,
1241  *tm = &tt;
1242  int tz;
1243  int nf;
1244  int dterr;
1245  char workbuf[MAXDATELEN + 1];
1246  char *field[MAXDATEFIELDS];
1247  int dtype;
1248  int ftype[MAXDATEFIELDS];
1249 
1250  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1251  field, ftype, MAXDATEFIELDS, &nf);
1252  if (dterr == 0)
1253  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1254  if (dterr != 0)
1255  DateTimeParseError(dterr, str, "time");
1256 
1257  tm2time(tm, fsec, &result);
1258  AdjustTimeForTypmod(&result, typmod);
1259 
1260  PG_RETURN_TIMEADT(result);
1261 }
#define MAXDATELEN
Definition: datetime.h:201
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3723
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
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:1709
signed int int32
Definition: c.h:362
static struct pg_tm tm
Definition: localtime.c:102
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1267
#define MAXDATEFIELDS
Definition: datetime.h:203
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:537
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1842 of file date.c.

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

1843 {
1844  TimeADT time = PG_GETARG_TIMEADT(0);
1845  Interval *result;
1846 
1847  result = (Interval *) palloc(sizeof(Interval));
1848 
1849  result->time = time;
1850  result->day = 0;
1851  result->month = 0;
1852 
1853  PG_RETURN_INTERVAL_P(result);
1854 }
#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:25
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949

◆ time_larger()

Datum time_larger ( PG_FUNCTION_ARGS  )

Definition at line 1612 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1613 {
1614  TimeADT time1 = PG_GETARG_TIMEADT(0);
1615  TimeADT time2 = PG_GETARG_TIMEADT(1);
1616 
1617  PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2);
1618 }
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_le()

Datum time_le ( PG_FUNCTION_ARGS  )

Definition at line 1560 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

1561 {
1562  TimeADT time1 = PG_GETARG_TIMEADT(0);
1563  TimeADT time2 = PG_GETARG_TIMEADT(1);
1564 
1565  PG_RETURN_BOOL(time1 <= time2);
1566 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_lt()

Datum time_lt ( PG_FUNCTION_ARGS  )

Definition at line 1551 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

1552 {
1553  TimeADT time1 = PG_GETARG_TIMEADT(0);
1554  TimeADT time2 = PG_GETARG_TIMEADT(1);
1555 
1556  PG_RETURN_BOOL(time1 < time2);
1557 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_mi_interval()

Datum time_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1927 of file date.c.

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

1928 {
1929  TimeADT time = PG_GETARG_TIMEADT(0);
1930  Interval *span = PG_GETARG_INTERVAL_P(1);
1931  TimeADT result;
1932 
1933  result = time - span->time;
1934  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1935  if (result < INT64CONST(0))
1936  result += USECS_PER_DAY;
1937 
1938  PG_RETURN_TIMEADT(result);
1939 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_mi_time()

Datum time_mi_time ( PG_FUNCTION_ARGS  )

Definition at line 1890 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().

1891 {
1892  TimeADT time1 = PG_GETARG_TIMEADT(0);
1893  TimeADT time2 = PG_GETARG_TIMEADT(1);
1894  Interval *result;
1895 
1896  result = (Interval *) palloc(sizeof(Interval));
1897 
1898  result->month = 0;
1899  result->day = 0;
1900  result->time = time1 - time2;
1901 
1902  PG_RETURN_INTERVAL_P(result);
1903 }
#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:25
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949

◆ time_ne()

Datum time_ne ( PG_FUNCTION_ARGS  )

Definition at line 1542 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

1543 {
1544  TimeADT time1 = PG_GETARG_TIMEADT(0);
1545  TimeADT time2 = PG_GETARG_TIMEADT(1);
1546 
1547  PG_RETURN_BOOL(time1 != time2);
1548 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_out()

Datum time_out ( PG_FUNCTION_ARGS  )

Definition at line 1354 of file date.c.

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

1355 {
1356  TimeADT time = PG_GETARG_TIMEADT(0);
1357  char *result;
1358  struct pg_tm tt,
1359  *tm = &tt;
1360  fsec_t fsec;
1361  char buf[MAXDATELEN + 1];
1362 
1363  time2tm(time, tm, &fsec);
1364  EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1365 
1366  result = pstrdup(buf);
1367  PG_RETURN_CSTRING(result);
1368 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3927
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1341
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
static char * buf
Definition: pg_test_fsync.c:67
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
int DateStyle
Definition: globals.c:115

◆ time_overflows()

bool time_overflows ( int  hour,
int  min,
int  sec,
fsec_t  fsec 
)

Definition at line 1278 of file date.c.

References HOURS_PER_DAY, MINS_PER_HOUR, SECS_PER_MINUTE, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by DecodeDateTime(), and DecodeTimeOnly().

1279 {
1280  /* Range-check the fields individually. */
1281  if (hour < 0 || hour > HOURS_PER_DAY ||
1282  min < 0 || min >= MINS_PER_HOUR ||
1283  sec < 0 || sec > SECS_PER_MINUTE ||
1284  fsec < 0 || fsec > USECS_PER_SEC)
1285  return true;
1286 
1287  /*
1288  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1289  * that the total time value doesn't exceed 24:00:00.
1290  */
1291  if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1292  + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1293  return true;
1294 
1295  return false;
1296 }
#define USECS_PER_SEC
Definition: timestamp.h:94
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ time_part()

Datum time_part ( PG_FUNCTION_ARGS  )

Definition at line 1985 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.

1986 {
1987  text *units = PG_GETARG_TEXT_PP(0);
1988  TimeADT time = PG_GETARG_TIMEADT(1);
1989  float8 result;
1990  int type,
1991  val;
1992  char *lowunits;
1993 
1994  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
1995  VARSIZE_ANY_EXHDR(units),
1996  false);
1997 
1998  type = DecodeUnits(0, lowunits, &val);
1999  if (type == UNKNOWN_FIELD)
2000  type = DecodeSpecial(0, lowunits, &val);
2001 
2002  if (type == UNITS)
2003  {
2004  fsec_t fsec;
2005  struct pg_tm tt,
2006  *tm = &tt;
2007 
2008  time2tm(time, tm, &fsec);
2009 
2010  switch (val)
2011  {
2012  case DTK_MICROSEC:
2013  result = tm->tm_sec * 1000000.0 + fsec;
2014  break;
2015 
2016  case DTK_MILLISEC:
2017  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2018  break;
2019 
2020  case DTK_SECOND:
2021  result = tm->tm_sec + fsec / 1000000.0;
2022  break;
2023 
2024  case DTK_MINUTE:
2025  result = tm->tm_min;
2026  break;
2027 
2028  case DTK_HOUR:
2029  result = tm->tm_hour;
2030  break;
2031 
2032  case DTK_TZ:
2033  case DTK_TZ_MINUTE:
2034  case DTK_TZ_HOUR:
2035  case DTK_DAY:
2036  case DTK_MONTH:
2037  case DTK_QUARTER:
2038  case DTK_YEAR:
2039  case DTK_DECADE:
2040  case DTK_CENTURY:
2041  case DTK_MILLENNIUM:
2042  case DTK_ISOYEAR:
2043  default:
2044  ereport(ERROR,
2045  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2046  errmsg("\"time\" units \"%s\" not recognized",
2047  lowunits)));
2048  result = 0;
2049  }
2050  }
2051  else if (type == RESERV && val == DTK_EPOCH)
2052  {
2053  result = time / 1000000.0;
2054  }
2055  else
2056  {
2057  ereport(ERROR,
2058  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2059  errmsg("\"time\" units \"%s\" not recognized",
2060  lowunits)));
2061  result = 0;
2062  }
2063 
2064  PG_RETURN_FLOAT8(result);
2065 }
#define DTK_TZ_HOUR
Definition: datetime.h:178
#define DTK_CENTURY
Definition: datetime.h:170
#define UNITS
Definition: datetime.h:108
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define DTK_YEAR
Definition: datetime.h:168
int tm_hour
Definition: pgtime.h:29
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:130
#define DTK_QUARTER
Definition: datetime.h:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define DTK_MILLENNIUM
Definition: datetime.h:171
int errcode(int sqlerrcode)
Definition: elog.c:610
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1341
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3686
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:102
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define DTK_SECOND
Definition: datetime.h:161
#define DTK_ISOYEAR
Definition: datetime.h:180
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define DTK_TZ_MINUTE
Definition: datetime.h:179
#define DTK_MINUTE
Definition: datetime.h:162
#define DTK_MICROSEC
Definition: datetime.h:173
#define ereport(elevel,...)
Definition: elog.h:144
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
#define DTK_DAY
Definition: datetime.h:164
#define RESERV
Definition: datetime.h:91
int DecodeSpecial(int field, char *lowtoken, int *val)
Definition: datetime.c:2995
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: c.h:562
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:664

◆ time_pl_interval()

Datum time_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 1909 of file date.c.

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

1910 {
1911  TimeADT time = PG_GETARG_TIMEADT(0);
1912  Interval *span = PG_GETARG_INTERVAL_P(1);
1913  TimeADT result;
1914 
1915  result = time + span->time;
1916  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1917  if (result < INT64CONST(0))
1918  result += USECS_PER_DAY;
1919 
1920  PG_RETURN_TIMEADT(result);
1921 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_recv()

Datum time_recv ( PG_FUNCTION_ARGS  )

Definition at line 1374 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.

1375 {
1377 
1378 #ifdef NOT_USED
1379  Oid typelem = PG_GETARG_OID(1);
1380 #endif
1381  int32 typmod = PG_GETARG_INT32(2);
1382  TimeADT result;
1383 
1384  result = pq_getmsgint64(buf);
1385 
1386  if (result < INT64CONST(0) || result > USECS_PER_DAY)
1387  ereport(ERROR,
1388  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1389  errmsg("time out of range")));
1390 
1391  AdjustTimeForTypmod(&result, typmod);
1392 
1393  PG_RETURN_TIMEADT(result);
1394 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
StringInfoData * StringInfo
Definition: stringinfo.h:44
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1478 of file date.c.

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

1479 {
1480  TimeADT time = PG_GETARG_TIMEADT(0);
1481  int32 typmod = PG_GETARG_INT32(1);
1482  TimeADT result;
1483 
1484  result = time;
1485  AdjustTimeForTypmod(&result, typmod);
1486 
1487  PG_RETURN_TIMEADT(result);
1488 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
signed int int32
Definition: c.h:362
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1400 of file date.c.

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

1401 {
1402  TimeADT time = PG_GETARG_TIMEADT(0);
1404 
1405  pq_begintypsend(&buf);
1406  pq_sendint64(&buf, time);
1408 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static char * buf
Definition: pg_test_fsync.c:67
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_smaller()

Datum time_smaller ( PG_FUNCTION_ARGS  )

Definition at line 1621 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1622 {
1623  TimeADT time1 = PG_GETARG_TIMEADT(0);
1624  TimeADT time2 = PG_GETARG_TIMEADT(1);
1625 
1626  PG_RETURN_TIMEADT((time1 < time2) ? time1 : time2);
1627 }
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_support()

Datum time_support ( PG_FUNCTION_ARGS  )

Definition at line 1458 of file date.c.

References SupportRequestSimplify::fcall, IsA, MAX_TIME_PRECISION, PG_GETARG_POINTER, PG_RETURN_POINTER, and TemporalSimplify().

1459 {
1460  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1461  Node *ret = NULL;
1462 
1463  if (IsA(rawreq, SupportRequestSimplify))
1464  {
1466 
1467  ret = TemporalSimplify(MAX_TIME_PRECISION, (Node *) req->fcall);
1468  }
1469 
1470  PG_RETURN_POINTER(ret);
1471 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Definition: nodes.h:529
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Node * TemporalSimplify(int32 max_precis, Node *node)
Definition: datetime.c:4452
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2623 of file date.c.

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

Referenced by castTimeToTimeTz().

2624 {
2625  TimeADT time = PG_GETARG_TIMEADT(0);
2626  TimeTzADT *result;
2627  struct pg_tm tt,
2628  *tm = &tt;
2629  fsec_t fsec;
2630  int tz;
2631 
2632  GetCurrentDateTime(tm);
2633  time2tm(time, tm, &fsec);
2635 
2636  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2637 
2638  result->time = time;
2639  result->zone = tz;
2640 
2641  PG_RETURN_TIMETZADT_P(result);
2642 }
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:345
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1341
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int32 zone
Definition: date.h:30
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1433
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timestamp_cmp_date()

Datum timestamp_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 971 of file date.c.

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

972 {
974  DateADT dateVal = PG_GETARG_DATEADT(1);
975  Timestamp dt2;
976 
977  dt2 = date2timestamp(dateVal);
978 
980 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

Definition at line 1153 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.

1154 {
1156  DateADT result;
1157  struct pg_tm tt,
1158  *tm = &tt;
1159  fsec_t fsec;
1160 
1161  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1162  DATE_NOBEGIN(result);
1163  else if (TIMESTAMP_IS_NOEND(timestamp))
1164  DATE_NOEND(result);
1165  else
1166  {
1167  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1168  ereport(ERROR,
1169  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1170  errmsg("timestamp out of range")));
1171 
1172  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1173  }
1174 
1175  PG_RETURN_DATEADT(result);
1176 }
int32 DateADT
Definition: date.h:23
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOBEGIN(j)
Definition: date.h:39
#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
int64 Timestamp
Definition: timestamp.h:38
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
#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:65
#define DATE_NOEND(j)
Definition: date.h:41

◆ timestamp_eq_date()

Datum timestamp_eq_date ( PG_FUNCTION_ARGS  )

Definition at line 899 of file date.c.

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

900 {
902  DateADT dateVal = PG_GETARG_DATEADT(1);
903  Timestamp dt2;
904 
905  dt2 = date2timestamp(dateVal);
906 
907  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
908 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_ge_date()

Datum timestamp_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 959 of file date.c.

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

960 {
962  DateADT dateVal = PG_GETARG_DATEADT(1);
963  Timestamp dt2;
964 
965  dt2 = date2timestamp(dateVal);
966 
967  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
968 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_gt_date()

Datum timestamp_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 935 of file date.c.

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

936 {
938  DateADT dateVal = PG_GETARG_DATEADT(1);
939  Timestamp dt2;
940 
941  dt2 = date2timestamp(dateVal);
942 
943  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
944 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_le_date()

Datum timestamp_le_date ( PG_FUNCTION_ARGS  )

Definition at line 947 of file date.c.

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

948 {
950  DateADT dateVal = PG_GETARG_DATEADT(1);
951  Timestamp dt2;
952 
953  dt2 = date2timestamp(dateVal);
954 
955  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
956 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_lt_date()

Datum timestamp_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 923 of file date.c.

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

924 {
926  DateADT dateVal = PG_GETARG_DATEADT(1);
927  Timestamp dt2;
928 
929  dt2 = date2timestamp(dateVal);
930 
931  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
932 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_ne_date()

Datum timestamp_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 911 of file date.c.

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

912 {
914  DateADT dateVal = PG_GETARG_DATEADT(1);
915  Timestamp dt2;
916 
917  dt2 = date2timestamp(dateVal);
918 
919  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
920 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2052
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:604

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

Definition at line 1758 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.

1759 {
1761  TimeADT result;
1762  struct pg_tm tt,
1763  *tm = &tt;
1764  fsec_t fsec;
1765 
1766  if (TIMESTAMP_NOT_FINITE(timestamp))
1767  PG_RETURN_NULL();
1768 
1769  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1770  ereport(ERROR,
1771  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1772  errmsg("timestamp out of range")));
1773 
1774  /*
1775  * Could also do this with time = (timestamp / USECS_PER_DAY *
1776  * USECS_PER_DAY) - timestamp;
1777  */
1778  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1779  USECS_PER_SEC) + fsec;
1780 
1781  PG_RETURN_TIMEADT(result);
1782 }
#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:1784
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:102
#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:25
int64 Timestamp
Definition: timestamp.h:38
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ timestamptz_cmp_date()

Datum timestamptz_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 1055 of file date.c.

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

1056 {
1058  DateADT dateVal = PG_GETARG_DATEADT(1);
1059  TimestampTz dt2;
1060 
1061  dt2 = date2timestamptz(dateVal);
1062 
1064 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#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 1198 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.

1199 {
1201  DateADT result;
1202  struct pg_tm tt,
1203  *tm = &tt;
1204  fsec_t fsec;
1205  int tz;
1206 
1207  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1208  DATE_NOBEGIN(result);
1209  else if (TIMESTAMP_IS_NOEND(timestamp))
1210  DATE_NOEND(result);
1211  else
1212  {
1213  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1214  ereport(ERROR,
1215  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1216  errmsg("timestamp out of range")));
1217 
1218  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1219  }
1220 
1221  PG_RETURN_DATEADT(result);
1222 }
int32 DateADT
Definition: date.h:23
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOBEGIN(j)
Definition: date.h:39
#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
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:824
#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:65
#define DATE_NOEND(j)
Definition: date.h:41

◆ timestamptz_eq_date()

Datum timestamptz_eq_date ( PG_FUNCTION_ARGS  )

Definition at line 983 of file date.c.

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

984 {
986  DateADT dateVal = PG_GETARG_DATEADT(1);
987  TimestampTz dt2;
988 
989  dt2 = date2timestamptz(dateVal);
990 
992 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 1043 of file date.c.

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

1044 {
1046  DateADT dateVal = PG_GETARG_DATEADT(1);
1047  TimestampTz dt2;
1048 
1049  dt2 = date2timestamptz(dateVal);
1050 
1051  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0);
1052 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 1019 of file date.c.

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

1020 {
1022  DateADT dateVal = PG_GETARG_DATEADT(1);
1023  TimestampTz dt2;
1024 
1025  dt2 = date2timestamptz(dateVal);
1026 
1028 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 1031 of file date.c.

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

1032 {
1034  DateADT dateVal = PG_GETARG_DATEADT(1);
1035  TimestampTz dt2;
1036 
1037  dt2 = date2timestamptz(dateVal);
1038 
1039  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) <= 0);
1040 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 1007 of file date.c.

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

1008 {
1010  DateADT dateVal = PG_GETARG_DATEADT(1);
1011  TimestampTz dt2;
1012 
1013  dt2 = date2timestamptz(dateVal);
1014 
1016 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 995 of file date.c.

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

996 {
998  DateADT dateVal = PG_GETARG_DATEADT(1);
999  TimestampTz dt2;
1000 
1001  dt2 = date2timestamptz(dateVal);
1002 
1003  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) != 0);
1004 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:692
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 1788 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.

1789 {
1791  TimeADT result;
1792  struct pg_tm tt,
1793  *tm = &tt;
1794  int tz;
1795  fsec_t fsec;
1796 
1797  if (TIMESTAMP_NOT_FINITE(timestamp))
1798  PG_RETURN_NULL();
1799 
1800  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1801  ereport(ERROR,
1802  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1803  errmsg("timestamp out of range")));
1804 
1805  /*
1806  * Could also do this with time = (timestamp / USECS_PER_DAY *
1807  * USECS_PER_DAY) - timestamp;
1808  */
1809  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1810  USECS_PER_SEC) + fsec;
1811 
1812  PG_RETURN_TIMEADT(result);
1813 }
#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:1784
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:102
#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:25
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ timestamptz_timetz()

Datum timestamptz_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2649 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().

2650 {
2652  TimeTzADT *result;
2653  struct pg_tm tt,
2654  *tm = &tt;
2655  int tz;
2656  fsec_t fsec;
2657 
2658  if (TIMESTAMP_NOT_FINITE(timestamp))
2659  PG_RETURN_NULL();
2660 
2661  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2662  ereport(ERROR,
2663  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2664  errmsg("timestamp out of range")));
2665 
2666  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2667 
2668  tm2timetz(tm, fsec, tz, result);
2669 
2670  PG_RETURN_TIMETZADT_P(result);
2671 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
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:1784
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2076
#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,...)
Definition: elog.h:144
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: date.h:27
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ timetypmodin()

Datum timetypmodin ( PG_FUNCTION_ARGS  )

Definition at line 1411 of file date.c.

References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

1412 {
1414 
1415  PG_RETURN_INT32(anytime_typmodin(false, ta));
1416 }
static int32 anytime_typmodin(bool istz, ArrayType *ta)
Definition: date.c:47
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251

◆ timetypmodout()

Datum timetypmodout ( PG_FUNCTION_ARGS  )

Definition at line 1419 of file date.c.

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

1420 {
1421  int32 typmod = PG_GETARG_INT32(0);
1422 
1423  PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1424 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:362
static char * anytime_typmodout(bool istz, int32 typmod)
Definition: date.c:90
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ timetz2tm()

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

Definition at line 2210 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 JsonEncodeDateTime(), timetz_out(), and timetz_part().

2211 {
2212  TimeOffset trem = time->time;
2213 
2214  tm->tm_hour = trem / USECS_PER_HOUR;
2215  trem -= tm->tm_hour * USECS_PER_HOUR;
2216  tm->tm_min = trem / USECS_PER_MINUTE;
2217  trem -= tm->tm_min * USECS_PER_MINUTE;
2218  tm->tm_sec = trem / USECS_PER_SEC;
2219  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2220 
2221  if (tzp != NULL)
2222  *tzp = time->zone;
2223 
2224  return 0;
2225 }
TimeADT time
Definition: date.h:29
#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:30
#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 2331 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().

Referenced by compareDatetime(), and leftmostvalue_timetz().

2332 {
2333  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2334  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2335 
2336  PG_RETURN_INT32(timetz_cmp_internal(time1, time2));
2337 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
Definition: date.h:27

◆ timetz_cmp_internal()

static int timetz_cmp_internal ( TimeTzADT time1,
TimeTzADT time2 
)
static

Definition at line 2250 of file date.c.

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

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

2251 {
2252  TimeOffset t1,
2253  t2;
2254 
2255  /* Primary sort is by true (GMT-equivalent) time */
2256  t1 = time1->time + (time1->zone * USECS_PER_SEC);
2257  t2 = time2->time + (time2->zone * USECS_PER_SEC);
2258 
2259  if (t1 > t2)
2260  return 1;
2261  if (t1 < t2)
2262  return -1;
2263 
2264  /*
2265  * If same GMT time, sort by timezone; we only want to say that two
2266  * timetz's are equal if both the time and zone parts are equal.
2267  */
2268  if (time1->zone > time2->zone)
2269  return 1;
2270  if (time1->zone < time2->zone)
2271  return -1;
2272 
2273  return 0;
2274 }
TimeADT time
Definition: date.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
int32 zone
Definition: date.h:30
int64 TimeOffset
Definition: timestamp.h:40

◆ timetz_eq()

Datum timetz_eq ( PG_FUNCTION_ARGS  )

Definition at line 2277 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2278 {
2279  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2280  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2281 
2282  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) == 0);
2283 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_ge()

Datum timetz_ge ( PG_FUNCTION_ARGS  )

Definition at line 2322 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2323 {
2324  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2325  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2326 
2327  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0);
2328 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_gt()

Datum timetz_gt ( PG_FUNCTION_ARGS  )

Definition at line 2313 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2314 {
2315  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2316  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2317 
2318  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0);
2319 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_hash()

Datum timetz_hash ( PG_FUNCTION_ARGS  )

Definition at line 2340 of file date.c.

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

2341 {
2343  uint32 thash;
2344 
2345  /*
2346  * To avoid any problems with padding bytes in the struct, we figure the
2347  * field hashes separately and XOR them.
2348  */
2350  Int64GetDatumFast(key->time)));
2351  thash ^= DatumGetUInt32(hash_uint32(key->zone));
2352  PG_RETURN_UINT32(thash);
2353 }
#define DatumGetUInt32(X)
Definition: postgres.h:486
TimeADT time
Definition: date.h:29
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:354
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
unsigned int uint32
Definition: c.h:374
#define Int64GetDatumFast(X)
Definition: postgres.h:760
static Datum hash_uint32(uint32 k)
Definition: hashfn.h:43
Definition: date.h:27

◆ timetz_hash_extended()

Datum timetz_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 2356 of file date.c.

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

2357 {
2359  Datum seed = PG_GETARG_DATUM(1);
2360  uint64 thash;
2361 
2362  /* Same approach as timetz_hash */
2364  Int64GetDatumFast(key->time),
2365  seed));
2367  DatumGetInt64(seed)));
2368  PG_RETURN_UINT64(thash);
2369 }
TimeADT time
Definition: date.h:29
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:367
int32 zone
Definition: date.h:30
#define DatumGetInt64(X)
Definition: postgres.h:607
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
uintptr_t Datum
Definition: postgres.h:367
#define Int64GetDatumFast(X)
Definition: postgres.h:760
#define DatumGetUInt64(X)
Definition: postgres.h:634
Definition: date.h:27
static Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.h:49
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ timetz_in()

Datum timetz_in ( PG_FUNCTION_ARGS  )

Definition at line 2086 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().

2087 {
2088  char *str = PG_GETARG_CSTRING(0);
2089 
2090 #ifdef NOT_USED
2091  Oid typelem = PG_GETARG_OID(1);
2092 #endif
2093  int32 typmod = PG_GETARG_INT32(2);
2094  TimeTzADT *result;
2095  fsec_t fsec;
2096  struct pg_tm tt,
2097  *tm = &tt;
2098  int tz;
2099  int nf;
2100  int dterr;
2101  char workbuf[MAXDATELEN + 1];
2102  char *field[MAXDATEFIELDS];
2103  int dtype;
2104  int ftype[MAXDATEFIELDS];
2105 
2106  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
2107  field, ftype, MAXDATEFIELDS, &nf);
2108  if (dterr == 0)
2109  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
2110  if (dterr != 0)
2111  DateTimeParseError(dterr, str, "time with time zone");
2112 
2113  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2114  tm2timetz(tm, fsec, tz, result);
2115  AdjustTimeForTypmod(&(result->time), typmod);
2116 
2117  PG_RETURN_TIMETZADT_P(result);
2118 }
#define MAXDATELEN
Definition: datetime.h:201
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3723
TimeADT time
Definition: date.h:29
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:1709
signed int int32
Definition: c.h:362
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2076
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int32 fsec_t
Definition: timestamp.h:41
#define MAXDATEFIELDS
Definition: datetime.h:203
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:537
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

Definition at line 2904 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.

2905 {
2907  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2908  TimeTzADT *result;
2909  int tz;
2910 
2911  if (zone->month != 0 || zone->day != 0)
2912  ereport(ERROR,
2913  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2914  errmsg("interval time zone \"%s\" must not include months or days",
2916  PointerGetDatum(zone))))));
2917 
2918  tz = -(zone->time / USECS_PER_SEC);
2919 
2920  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2921 
2922  result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2923  while (result->time < INT64CONST(0))
2924  result->time += USECS_PER_DAY;
2925  while (result->time >= USECS_PER_DAY)
2926  result->time -= USECS_PER_DAY;
2927 
2928  result->zone = tz;
2929 
2930  PG_RETURN_TIMETZADT_P(result);
2931 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
#define PointerGetDatum(X)
Definition: postgres.h:556
int errcode(int sqlerrcode)
Definition: elog.c:610
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:952
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:624
int32 day
Definition: timestamp.h:47
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:566
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
int32 month
Definition: timestamp.h:48
#define ereport(elevel,...)
Definition: elog.h:144
Definition: zic.c:98
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: date.h:27

◆ timetz_larger()

Datum timetz_larger ( PG_FUNCTION_ARGS  )

Definition at line 2372 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2373 {
2374  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2375  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2376  TimeTzADT *result;
2377 
2378  if (timetz_cmp_internal(time1, time2) > 0)
2379  result = time1;
2380  else
2381  result = time2;
2382  PG_RETURN_TIMETZADT_P(result);
2383 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
Definition: date.h:27

◆ timetz_le()

Datum timetz_le ( PG_FUNCTION_ARGS  )

Definition at line 2304 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2305 {
2306  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2307  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2308 
2309  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0);
2310 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_lt()

Datum timetz_lt ( PG_FUNCTION_ARGS  )

Definition at line 2295 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2296 {
2297  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2298  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2299 
2300  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) < 0);
2301 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_mi_interval()

Datum timetz_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 2425 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.

2426 {
2427  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2428  Interval *span = PG_GETARG_INTERVAL_P(1);
2429  TimeTzADT *result;
2430 
2431  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2432 
2433  result->time = time->time - span->time;
2434  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2435  if (result->time < INT64CONST(0))
2436  result->time += USECS_PER_DAY;
2437 
2438  result->zone = time->zone;
2439 
2440  PG_RETURN_TIMETZADT_P(result);
2441 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timetz_ne()

Datum timetz_ne ( PG_FUNCTION_ARGS  )

Definition at line 2286 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2287 {
2288  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2289  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2290 
2291  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) != 0);
2292 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2250
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Definition: date.h:27

◆ timetz_out()

Datum timetz_out ( PG_FUNCTION_ARGS  )

Definition at line 2121 of file date.c.

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

2122 {
2123  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2124  char *result;
2125  struct pg_tm tt,
2126  *tm = &tt;
2127  fsec_t fsec;
2128  int tz;
2129  char buf[MAXDATELEN + 1];
2130 
2131  timetz2tm(time, tm, &fsec, &tz);
2132  EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2133 
2134  result = pstrdup(buf);
2135  PG_RETURN_CSTRING(result);
2136 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3927
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
int32 fsec_t
Definition: timestamp.h:41
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2210
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
int DateStyle
Definition: globals.c:115
Definition: date.h:27

◆ timetz_part()

Datum timetz_part ( PG_FUNCTION_ARGS  )

Definition at line 2722 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.

2723 {
2724  text *units = PG_GETARG_TEXT_PP(0);
2725  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2726  float8 result;
2727  int type,
2728  val;
2729  char *lowunits;
2730 
2731  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
2732  VARSIZE_ANY_EXHDR(units),
2733  false);
2734 
2735  type = DecodeUnits(0, lowunits, &val);
2736  if (type == UNKNOWN_FIELD)
2737  type = DecodeSpecial(0, lowunits, &val);
2738 
2739  if (type == UNITS)
2740  {
2741  double dummy;
2742  int tz;
2743  fsec_t fsec;
2744  struct pg_tm tt,
2745  *tm = &tt;
2746 
2747  timetz2tm(time, tm, &fsec, &tz);
2748 
2749  switch (val)
2750  {
2751  case DTK_TZ:
2752  result = -tz;
2753  break;
2754 
2755  case DTK_TZ_MINUTE:
2756  result = -tz;
2757  result /= SECS_PER_MINUTE;
2758  FMODULO(result, dummy, (double) SECS_PER_MINUTE);
2759  break;
2760 
2761  case DTK_TZ_HOUR:
2762  dummy = -tz;
2763  FMODULO(dummy, result, (double) SECS_PER_HOUR);
2764  break;
2765 
2766  case DTK_MICROSEC:
2767  result = tm->tm_sec * 1000000.0 + fsec;
2768  break;
2769 
2770  case DTK_MILLISEC:
2771  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2772  break;
2773 
2774  case DTK_SECOND:
2775  result = tm->tm_sec + fsec / 1000000.0;
2776  break;
2777 
2778  case DTK_MINUTE:
2779  result = tm->tm_min;
2780  break;
2781 
2782  case DTK_HOUR:
2783  result = tm->tm_hour;
2784  break;
2785 
2786  case DTK_DAY:
2787  case DTK_MONTH:
2788  case DTK_QUARTER:
2789  case DTK_YEAR:
2790  case DTK_DECADE:
2791  case DTK_CENTURY:
2792  case DTK_MILLENNIUM:
2793  default:
2794  ereport(ERROR,
2795  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2796  errmsg("\"time with time zone\" units \"%s\" not recognized",
2797  lowunits)));
2798  result = 0;
2799  }
2800  }
2801  else if (type == RESERV && val == DTK_EPOCH)
2802  {
2803  result = time->time / 1000000.0 + time->zone;
2804  }
2805  else
2806  {
2807  ereport(ERROR,
2808  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2809  errmsg("\"time with time zone\" units \"%s\" not recognized",
2810  lowunits)));
2811  result = 0;
2812  }
2813 
2814  PG_RETURN_FLOAT8(result);
2815 }
#define DTK_TZ_HOUR
Definition: datetime.h:178
#define DTK_CENTURY
Definition: datetime.h:170
#define UNITS
Definition: datetime.h:108
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
TimeADT time
Definition: date.h:29
#define DTK_YEAR
Definition: datetime.h:168
int tm_hour
Definition: pgtime.h:29
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:130
#define DTK_QUARTER
Definition: datetime.h:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:365
#define FMODULO(t, q, u)
Definition: datetime.h:238
#define DTK_MILLENNIUM
Definition: datetime.h:171
int errcode(int sqlerrcode)
Definition: elog.c:610
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3686
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:102
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#define DTK_SECOND
Definition: datetime.h:161
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
#define DTK_TZ_MINUTE
Definition: datetime.h:179
#define SECS_PER_HOUR
Definition: timestamp.h:87
#define DTK_MINUTE
Definition: datetime.h:162
#define DTK_MICROSEC
Definition: datetime.h:173
int timetz2tm(TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: date.c:2210
#define ereport(elevel,...)
Definition: elog.h:144
#define DTK_DAY
Definition: datetime.h:164
#define RESERV
Definition: datetime.h:91
int DecodeSpecial(int field, char *lowtoken, int *val)
Definition: datetime.c:2995
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: c.h:562
int tm_sec
Definition: pgtime.h:27
Definition: date.h:27
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:664

◆ timetz_pl_interval()

Datum timetz_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 2403 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.

2404 {
2405  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2406  Interval *span = PG_GETARG_INTERVAL_P(1);
2407  TimeTzADT *result;
2408 
2409  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2410 
2411  result->time = time->time + span->time;
2412  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2413  if (result->time < INT64CONST(0))
2414  result->time += USECS_PER_DAY;
2415 
2416  result->zone = time->zone;
2417 
2418  PG_RETURN_TIMETZADT_P(result);
2419 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timetz_recv()

Datum timetz_recv ( PG_FUNCTION_ARGS  )

Definition at line 2142 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.

2143 {
2145 
2146 #ifdef NOT_USED
2147  Oid typelem = PG_GETARG_OID(1);
2148 #endif
2149  int32 typmod = PG_GETARG_INT32(2);
2150  TimeTzADT *result;
2151 
2152  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2153 
2154  result->time = pq_getmsgint64(buf);
2155 
2156  if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2157  ereport(ERROR,
2158  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2159  errmsg("time out of range")));
2160 
2161  result->zone = pq_getmsgint(buf, sizeof(result->zone));
2162 
2163  /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2164  if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2165  ereport(ERROR,
2166  (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
2167  errmsg("time zone displacement out of range")));
2168 
2169  AdjustTimeForTypmod(&(result->time), typmod);
2170 
2171  PG_RETURN_TIMETZADT_P(result);
2172 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
StringInfoData * StringInfo
Definition: stringinfo.h:44
int errcode(int sqlerrcode)
Definition: elog.c:610
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:362
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:30
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
#define USECS_PER_DAY
Definition: timestamp.h:91
#define TZDISP_LIMIT
Definition: timestamp.h:104
#define ereport(elevel,...)
Definition: elog.h:144
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1498

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2232 of file date.c.

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

2233 {
2234  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2235  int32 typmod = PG_GETARG_INT32(1);
2236  TimeTzADT *result;
2237 
2238  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2239 
2240  result->time = time->time;
2241  result->zone = time->zone;
2242 
2243  AdjustTimeForTypmod(&(result->time), typmod);
2244 
2245  PG_RETURN_TIMETZADT_P(result);
2246 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67