PostgreSQL Source Code  git master
date.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <float.h>
#include <time.h>
#include "access/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)
 
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 1442 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().

1443 {
1444  static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1445  INT64CONST(1000000),
1446  INT64CONST(100000),
1447  INT64CONST(10000),
1448  INT64CONST(1000),
1449  INT64CONST(100),
1450  INT64CONST(10),
1451  INT64CONST(1)
1452  };
1453 
1454  static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1455  INT64CONST(500000),
1456  INT64CONST(50000),
1457  INT64CONST(5000),
1458  INT64CONST(500),
1459  INT64CONST(50),
1460  INT64CONST(5),
1461  INT64CONST(0)
1462  };
1463 
1464  if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1465  {
1466  if (*time >= INT64CONST(0))
1467  *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1468  TimeScales[typmod];
1469  else
1470  *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1471  TimeScales[typmod]);
1472  }
1473 }
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 67 of file date.c.

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

Referenced by anytime_typmodin(), and transformSQLValueFunction().

68 {
69  if (typmod < 0)
70  ereport(ERROR,
71  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
72  errmsg("TIME(%d)%s precision must not be negative",
73  typmod, (istz ? " WITH TIME ZONE" : ""))));
74  if (typmod > MAX_TIME_PRECISION)
75  {
77  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
78  errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
79  typmod, (istz ? " WITH TIME ZONE" : ""),
81  typmod = MAX_TIME_PRECISION;
82  }
83 
84  return typmod;
85 }
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 46 of file date.c.

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

Referenced by timetypmodin(), and timetztypmodin().

47 {
48  int32 *tl;
49  int n;
50 
51  tl = ArrayGetIntegerTypmods(ta, &n);
52 
53  /*
54  * we're not too tense about good error message here because grammar
55  * shouldn't allow wrong number of modifiers for TIME
56  */
57  if (n != 1)
58  ereport(ERROR,
59  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
60  errmsg("invalid type modifier")));
61 
62  return anytime_typmod_check(istz, tl[0]);
63 }
int32 anytime_typmod_check(bool istz, int32 typmod)
Definition: date.c:67
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Definition: arrayutils.c:200
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:355
#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 89 of file date.c.

References psprintf().

Referenced by timetypmodout(), and timetztypmodout().

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

◆ date2timestamp()

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 707 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

708 {
709  double result;
710 
711  if (DATE_IS_NOBEGIN(dateVal))
712  result = -DBL_MAX;
713  else if (DATE_IS_NOEND(dateVal))
714  result = DBL_MAX;
715  else
716  {
717  /* date is days since 2000, timestamp is microseconds since same... */
718  result = dateVal * (double) USECS_PER_DAY;
719  }
720 
721  return result;
722 }
#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 562 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().

563 {
564  Timestamp result;
565 
566  if (DATE_IS_NOBEGIN(dateVal))
567  TIMESTAMP_NOBEGIN(result);
568  else if (DATE_IS_NOEND(dateVal))
569  TIMESTAMP_NOEND(result);
570  else
571  {
572  /*
573  * Date's range is wider than timestamp's, so check for boundaries.
574  * Since dates have the same minimum values as timestamps, only upper
575  * boundary need be checked for overflow.
576  */
577  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
578  {
579  if (overflow)
580  {
581  *overflow = 1;
582  return (Timestamp) 0;
583  }
584  else
585  {
586  ereport(ERROR,
587  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
588  errmsg("date out of range for timestamp")));
589  }
590  }
591 
592  /* date is days since 2000, timestamp is microseconds since same... */
593  result = dateVal * USECS_PER_DAY;
594  }
595 
596  return result;
597 }
#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 616 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().

617 {
618  TimestampTz result;
619  struct pg_tm tt,
620  *tm = &tt;
621  int tz;
622 
623  if (DATE_IS_NOBEGIN(dateVal))
624  TIMESTAMP_NOBEGIN(result);
625  else if (DATE_IS_NOEND(dateVal))
626  TIMESTAMP_NOEND(result);
627  else
628  {
629  /*
630  * Date's range is wider than timestamp's, so check for boundaries.
631  * Since dates have the same minimum values as timestamps, only upper
632  * boundary need be checked for overflow.
633  */
634  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
635  {
636  if (overflow)
637  {
638  *overflow = 1;
639  return (TimestampTz) 0;
640  }
641  else
642  {
643  ereport(ERROR,
644  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
645  errmsg("date out of range for timestamp")));
646  }
647  }
648 
649  j2date(dateVal + POSTGRES_EPOCH_JDATE,
650  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
651  tm->tm_hour = 0;
652  tm->tm_min = 0;
653  tm->tm_sec = 0;
655 
656  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
657 
658  /*
659  * Since it is possible to go beyond allowed timestamptz range because
660  * of time zone, check for allowed timestamp range after adding tz.
661  */
662  if (!IS_VALID_TIMESTAMP(result))
663  {
664  if (overflow)
665  {
666  if (result < MIN_TIMESTAMP)
667  *overflow = -1;
668  else
669  {
670  Assert(result >= END_TIMESTAMP);
671  *overflow = 1;
672  }
673  return (TimestampTz) 0;
674  }
675  else
676  {
677  ereport(ERROR,
678  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
679  errmsg("date out of range for timestamp")));
680  }
681  }
682  }
683 
684  return result;
685 }
#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:108
#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:1438
#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:738
#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 428 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_INT32.

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

429 {
430  DateADT dateVal1 = PG_GETARG_DATEADT(0);
431  DateADT dateVal2 = PG_GETARG_DATEADT(1);
432 
433  if (dateVal1 < dateVal2)
434  PG_RETURN_INT32(-1);
435  else if (dateVal1 > dateVal2)
436  PG_RETURN_INT32(1);
437  PG_RETURN_INT32(0);
438 }
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 802 of file date.c.

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

803 {
804  DateADT dateVal = PG_GETARG_DATEADT(0);
806  Timestamp dt1;
807 
808  dt1 = date2timestamp(dateVal);
809 
811 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 886 of file date.c.

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

887 {
888  DateADT dateVal = PG_GETARG_DATEADT(0);
890  TimestampTz dt1;
891 
892  dt1 = date2timestamptz(dateVal);
893 
895 }
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:691
#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 374 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dateeq().

375 {
376  DateADT dateVal1 = PG_GETARG_DATEADT(0);
377  DateADT dateVal2 = PG_GETARG_DATEADT(1);
378 
379  PG_RETURN_BOOL(dateVal1 == dateVal2);
380 }
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 730 of file date.c.

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

731 {
732  DateADT dateVal = PG_GETARG_DATEADT(0);
734  Timestamp dt1;
735 
736  dt1 = date2timestamp(dateVal);
737 
738  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
739 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_eq_timestamptz()

Datum date_eq_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 814 of file date.c.

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

815 {
816  DateADT dateVal = PG_GETARG_DATEADT(0);
818  TimestampTz dt1;
819 
820  dt1 = date2timestamptz(dateVal);
821 
823 }
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:691
#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 441 of file date.c.

References DatumGetDateADT.

Referenced by date_sortsupport().

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

◆ date_finite()

Datum date_finite ( PG_FUNCTION_ARGS  )

Definition at line 463 of file date.c.

References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.

464 {
466 
468 }
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 419 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datege().

420 {
421  DateADT dateVal1 = PG_GETARG_DATEADT(0);
422  DateADT dateVal2 = PG_GETARG_DATEADT(1);
423 
424  PG_RETURN_BOOL(dateVal1 >= dateVal2);
425 }
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 790 of file date.c.

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

791 {
792  DateADT dateVal = PG_GETARG_DATEADT(0);
794  Timestamp dt1;
795 
796  dt1 = date2timestamp(dateVal);
797 
798  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
799 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_ge_timestamptz()

Datum date_ge_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 874 of file date.c.

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

875 {
876  DateADT dateVal = PG_GETARG_DATEADT(0);
878  TimestampTz dt1;
879 
880  dt1 = date2timestamptz(dateVal);
881 
883 }
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:691
#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 410 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dategt().

411 {
412  DateADT dateVal1 = PG_GETARG_DATEADT(0);
413  DateADT dateVal2 = PG_GETARG_DATEADT(1);
414 
415  PG_RETURN_BOOL(dateVal1 > dateVal2);
416 }
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 766 of file date.c.

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

767 {
768  DateADT dateVal = PG_GETARG_DATEADT(0);
770  Timestamp dt1;
771 
772  dt1 = date2timestamp(dateVal);
773 
774  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
775 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_gt_timestamptz()

Datum date_gt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 850 of file date.c.

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

851 {
852  DateADT dateVal = PG_GETARG_DATEADT(0);
854  TimestampTz dt1;
855 
856  dt1 = date2timestamptz(dateVal);
857 
859 }
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:691
#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 109 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.

110 {
111  char *str = PG_GETARG_CSTRING(0);
112  DateADT date;
113  fsec_t fsec;
114  struct pg_tm tt,
115  *tm = &tt;
116  int tzp;
117  int dtype;
118  int nf;
119  int dterr;
120  char *field[MAXDATEFIELDS];
121  int ftype[MAXDATEFIELDS];
122  char workbuf[MAXDATELEN + 1];
123 
124  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
125  field, ftype, MAXDATEFIELDS, &nf);
126  if (dterr == 0)
127  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
128  if (dterr != 0)
129  DateTimeParseError(dterr, str, "date");
130 
131  switch (dtype)
132  {
133  case DTK_DATE:
134  break;
135 
136  case DTK_EPOCH:
137  GetEpochTime(tm);
138  break;
139 
140  case DTK_LATE:
141  DATE_NOEND(date);
142  PG_RETURN_DATEADT(date);
143 
144  case DTK_EARLY:
145  DATE_NOBEGIN(date);
146  PG_RETURN_DATEADT(date);
147 
148  default:
149  DateTimeParseError(DTERR_BAD_FORMAT, str, "date");
150  break;
151  }
152 
153  /* Prevent overflow in Julian-day routines */
154  if (!IS_VALID_JULIAN(tm->tm_year, tm->tm_mon, tm->tm_mday))
155  ereport(ERROR,
156  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
157  errmsg("date out of range: \"%s\"", str)));
158 
159  date = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
160 
161  /* Now check for just-out-of-range dates */
162  if (!IS_VALID_DATE(date))
163  ereport(ERROR,
164  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
165  errmsg("date out of range: \"%s\"", str)));
166 
167  PG_RETURN_DATEADT(date);
168 }
#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:3736
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:108
#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:2019
#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 471 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

472 {
473  DateADT dateVal1 = PG_GETARG_DATEADT(0);
474  DateADT dateVal2 = PG_GETARG_DATEADT(1);
475 
476  PG_RETURN_DATEADT((dateVal1 > dateVal2) ? dateVal1 : dateVal2);
477 }
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 401 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datele().

402 {
403  DateADT dateVal1 = PG_GETARG_DATEADT(0);
404  DateADT dateVal2 = PG_GETARG_DATEADT(1);
405 
406  PG_RETURN_BOOL(dateVal1 <= dateVal2);
407 }
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 778 of file date.c.

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

779 {
780  DateADT dateVal = PG_GETARG_DATEADT(0);
782  Timestamp dt1;
783 
784  dt1 = date2timestamp(dateVal);
785 
786  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
787 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_le_timestamptz()

Datum date_le_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 862 of file date.c.

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

863 {
864  DateADT dateVal = PG_GETARG_DATEADT(0);
866  TimestampTz dt1;
867 
868  dt1 = date2timestamptz(dateVal);
869 
871 }
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:691
#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 392 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datelt().

393 {
394  DateADT dateVal1 = PG_GETARG_DATEADT(0);
395  DateADT dateVal2 = PG_GETARG_DATEADT(1);
396 
397  PG_RETURN_BOOL(dateVal1 < dateVal2);
398 }
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 754 of file date.c.

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

755 {
756  DateADT dateVal = PG_GETARG_DATEADT(0);
758  Timestamp dt1;
759 
760  dt1 = date2timestamp(dateVal);
761 
762  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
763 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_lt_timestamptz()

Datum date_lt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 838 of file date.c.

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

839 {
840  DateADT dateVal = PG_GETARG_DATEADT(0);
842  TimestampTz dt1;
843 
844  dt1 = date2timestamptz(dateVal);
845 
847 }
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:691
#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 491 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().

492 {
493  DateADT dateVal1 = PG_GETARG_DATEADT(0);
494  DateADT dateVal2 = PG_GETARG_DATEADT(1);
495 
496  if (DATE_NOT_FINITE(dateVal1) || DATE_NOT_FINITE(dateVal2))
497  ereport(ERROR,
498  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
499  errmsg("cannot subtract infinite dates")));
500 
501  PG_RETURN_INT32((int32) (dateVal1 - dateVal2));
502 }
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:355
#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 1121 of file date.c.

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

1122 {
1123  DateADT dateVal = PG_GETARG_DATEADT(0);
1124  Interval *span = PG_GETARG_INTERVAL_P(1);
1125  Timestamp dateStamp;
1126 
1127  dateStamp = date2timestamp(dateVal);
1128 
1130  TimestampGetDatum(dateStamp),
1131  PointerGetDatum(span));
1132 }
#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:2912
#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:603
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ date_mii()

Datum date_mii ( PG_FUNCTION_ARGS  )

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

533 {
534  DateADT dateVal = PG_GETARG_DATEADT(0);
536  DateADT result;
537 
538  if (DATE_NOT_FINITE(dateVal))
539  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
540 
541  result = dateVal - days;
542 
543  /* Check for integer overflow and out-of-allowed-range */
544  if ((days >= 0 ? (result > dateVal) : (result < dateVal)) ||
545  !IS_VALID_DATE(result))
546  ereport(ERROR,
547  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
548  errmsg("date out of range")));
549 
550  PG_RETURN_DATEADT(result);
551 }
#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:355
#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 383 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

384 {
385  DateADT dateVal1 = PG_GETARG_DATEADT(0);
386  DateADT dateVal2 = PG_GETARG_DATEADT(1);
387 
388  PG_RETURN_BOOL(dateVal1 != dateVal2);
389 }
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 742 of file date.c.

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

743 {
744  DateADT dateVal = PG_GETARG_DATEADT(0);
746  Timestamp dt1;
747 
748  dt1 = date2timestamp(dateVal);
749 
750  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
751 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ date_ne_timestamptz()

Datum date_ne_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 826 of file date.c.

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

827 {
828  DateADT dateVal = PG_GETARG_DATEADT(0);
830  TimestampTz dt1;
831 
832  dt1 = date2timestamptz(dateVal);
833 
835 }
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:691
#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 174 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.

175 {
177  char *result;
178  struct pg_tm tt,
179  *tm = &tt;
180  char buf[MAXDATELEN + 1];
181 
182  if (DATE_NOT_FINITE(date))
183  EncodeSpecialDate(date, buf);
184  else
185  {
187  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
188  EncodeDateOnly(tm, DateStyle, buf);
189  }
190 
191  result = pstrdup(buf);
192  PG_RETURN_CSTRING(result);
193 }
#define MAXDATELEN
Definition: datetime.h:201
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition: datetime.c:3855
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:108
#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:284
#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 1101 of file date.c.

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

1102 {
1103  DateADT dateVal = PG_GETARG_DATEADT(0);
1104  Interval *span = PG_GETARG_INTERVAL_P(1);
1105  Timestamp dateStamp;
1106 
1107  dateStamp = date2timestamp(dateVal);
1108 
1110  TimestampGetDatum(dateStamp),
1111  PointerGetDatum(span));
1112 }
#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:2833
#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:603
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ date_pli()

Datum date_pli ( PG_FUNCTION_ARGS  )

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

509 {
510  DateADT dateVal = PG_GETARG_DATEADT(0);
512  DateADT result;
513 
514  if (DATE_NOT_FINITE(dateVal))
515  PG_RETURN_DATEADT(dateVal); /* can't change infinity */
516 
517  result = dateVal + days;
518 
519  /* Check for integer overflow and out-of-allowed-range */
520  if ((days >= 0 ? (result < dateVal) : (result > dateVal)) ||
521  !IS_VALID_DATE(result))
522  ereport(ERROR,
523  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
524  errmsg("date out of range")));
525 
526  PG_RETURN_DATEADT(result);
527 }
#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:355
#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 199 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().

200 {
202  DateADT result;
203 
204  result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
205 
206  /* Limit to the same range that date_in() accepts. */
207  if (DATE_NOT_FINITE(result))
208  /* ok */ ;
209  else if (!IS_VALID_DATE(result))
210  ereport(ERROR,
211  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
212  errmsg("date out of range")));
213 
214  PG_RETURN_DATEADT(result);
215 }
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 221 of file date.c.

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

222 {
225 
226  pq_begintypsend(&buf);
227  pq_sendint32(&buf, date);
229 }
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 480 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_DATEADT.

481 {
482  DateADT dateVal1 = PG_GETARG_DATEADT(0);
483  DateADT dateVal2 = PG_GETARG_DATEADT(1);
484 
485  PG_RETURN_DATEADT((dateVal1 < dateVal2) ? dateVal1 : dateVal2);
486 }
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 454 of file date.c.

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

455 {
457 
458  ssup->comparator = date_fastcmp;
459  PG_RETURN_VOID();
460 }
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:441
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 1138 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1139 {
1140  DateADT dateVal = PG_GETARG_DATEADT(0);
1141  Timestamp result;
1142 
1143  result = date2timestamp(dateVal);
1144 
1145  PG_RETURN_TIMESTAMP(result);
1146 }
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:603

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1182 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1183 {
1184  DateADT dateVal = PG_GETARG_DATEADT(0);
1185  TimestampTz result;
1186 
1187  result = date2timestamptz(dateVal);
1188 
1189  PG_RETURN_TIMESTAMP(result);
1190 }
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:691
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

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

1764 {
1766  TimeADT time = PG_GETARG_TIMEADT(1);
1767  Timestamp result;
1768 
1769  result = date2timestamp(date);
1770  if (!TIMESTAMP_NOT_FINITE(result))
1771  {
1772  result += time;
1773  if (!IS_VALID_TIMESTAMP(result))
1774  ereport(ERROR,
1775  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1776  errmsg("timestamp out of range")));
1777  }
1778 
1779  PG_RETURN_TIMESTAMP(result);
1780 }
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:603

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

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

2626 {
2628  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2629  TimestampTz result;
2630 
2631  if (DATE_IS_NOBEGIN(date))
2632  TIMESTAMP_NOBEGIN(result);
2633  else if (DATE_IS_NOEND(date))
2634  TIMESTAMP_NOEND(result);
2635  else
2636  {
2637  /*
2638  * Date's range is wider than timestamp's, so check for boundaries.
2639  * Since dates have the same minimum values as timestamps, only upper
2640  * boundary need be checked for overflow.
2641  */
2643  ereport(ERROR,
2644  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2645  errmsg("date out of range for timestamp")));
2646  result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
2647 
2648  /*
2649  * Since it is possible to go beyond allowed timestamptz range because
2650  * of time zone, check for allowed timestamp range after adding tz.
2651  */
2652  if (!IS_VALID_TIMESTAMP(result))
2653  ereport(ERROR,
2654  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2655  errmsg("date out of range for timestamp")));
2656  }
2657 
2658  PG_RETURN_TIMESTAMP(result);
2659 }
#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 284 of file date.c.

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

Referenced by date_out(), and JsonEncodeDateTime().

285 {
286  if (DATE_IS_NOBEGIN(dt))
287  strcpy(str, EARLY);
288  else if (DATE_IS_NOEND(dt))
289  strcpy(str, LATE);
290  else /* shouldn't happen */
291  elog(ERROR, "invalid argument for EncodeSpecialDate");
292 }
#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

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

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

300 {
301  TimestampTz ts;
302  struct pg_tm tt,
303  *tm = &tt;
304  fsec_t fsec;
305  int tz;
306 
308 
309  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
310  ereport(ERROR,
311  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
312  errmsg("timestamp out of range")));
313 
314  return date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
315 }
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:1793
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#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:783
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 321 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

322 {
323  TimeTzADT *result;
324  TimestampTz ts;
325  struct pg_tm tt,
326  *tm = &tt;
327  fsec_t fsec;
328  int tz;
329 
331 
332  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
333  ereport(ERROR,
334  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
335  errmsg("timestamp out of range")));
336 
337  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
338  tm2timetz(tm, fsec, tz, result);
339  AdjustTimeForTypmod(&(result->time), typmod);
340  return result;
341 }
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:1793
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2020
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:783
#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:1442

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 347 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

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

◆ in_range_date_interval()

Datum in_range_date_interval ( PG_FUNCTION_ARGS  )

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

1073 {
1075  DateADT base = PG_GETARG_DATEADT(1);
1076  Interval *offset = PG_GETARG_INTERVAL_P(2);
1077  bool sub = PG_GETARG_BOOL(3);
1078  bool less = PG_GETARG_BOOL(4);
1079  Timestamp valStamp;
1080  Timestamp baseStamp;
1081 
1082  valStamp = date2timestamp(val);
1083  baseStamp = date2timestamp(base);
1084 
1086  TimestampGetDatum(valStamp),
1087  TimestampGetDatum(baseStamp),
1088  IntervalPGetDatum(offset),
1089  BoolGetDatum(sub),
1090  BoolGetDatum(less));
1091 }
#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:3341
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:603
long val
Definition: informix.c:664

◆ in_range_time_interval()

Datum in_range_time_interval ( PG_FUNCTION_ARGS  )

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

1890 {
1892  TimeADT base = PG_GETARG_TIMEADT(1);
1893  Interval *offset = PG_GETARG_INTERVAL_P(2);
1894  bool sub = PG_GETARG_BOOL(3);
1895  bool less = PG_GETARG_BOOL(4);
1896  TimeADT sum;
1897 
1898  /*
1899  * Like time_pl_interval/time_mi_interval, we disregard the month and day
1900  * fields of the offset. So our test for negative should too.
1901  */
1902  if (offset->time < 0)
1903  ereport(ERROR,
1904  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1905  errmsg("invalid preceding or following size in window function")));
1906 
1907  /*
1908  * We can't use time_pl_interval/time_mi_interval here, because their
1909  * wraparound behavior would give wrong (or at least undesirable) answers.
1910  * Fortunately the equivalent non-wrapping behavior is trivial, especially
1911  * since we don't worry about integer overflow.
1912  */
1913  if (sub)
1914  sum = base - offset->time;
1915  else
1916  sum = base + offset->time;
1917 
1918  if (less)
1919  PG_RETURN_BOOL(val <= sum);
1920  else
1921  PG_RETURN_BOOL(val >= sum);
1922 }
#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 2391 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.

2392 {
2394  TimeTzADT *base = PG_GETARG_TIMETZADT_P(1);
2395  Interval *offset = PG_GETARG_INTERVAL_P(2);
2396  bool sub = PG_GETARG_BOOL(3);
2397  bool less = PG_GETARG_BOOL(4);
2398  TimeTzADT sum;
2399 
2400  /*
2401  * Like timetz_pl_interval/timetz_mi_interval, we disregard the month and
2402  * day fields of the offset. So our test for negative should too.
2403  */
2404  if (offset->time < 0)
2405  ereport(ERROR,
2406  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
2407  errmsg("invalid preceding or following size in window function")));
2408 
2409  /*
2410  * We can't use timetz_pl_interval/timetz_mi_interval here, because their
2411  * wraparound behavior would give wrong (or at least undesirable) answers.
2412  * Fortunately the equivalent non-wrapping behavior is trivial, especially
2413  * since we don't worry about integer overflow.
2414  */
2415  if (sub)
2416  sum.time = base->time - offset->time;
2417  else
2418  sum.time = base->time + offset->time;
2419  sum.zone = base->zone;
2420 
2421  if (less)
2422  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) <= 0);
2423  else
2424  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) >= 0);
2425 }
#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:2194
#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 1809 of file date.c.

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

1810 {
1811  Interval *span = PG_GETARG_INTERVAL_P(0);
1812  TimeADT result;
1813  int64 days;
1814 
1815  result = span->time;
1816  if (result >= USECS_PER_DAY)
1817  {
1818  days = result / USECS_PER_DAY;
1819  result -= days * USECS_PER_DAY;
1820  }
1821  else if (result < 0)
1822  {
1823  days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
1824  result += days * USECS_PER_DAY;
1825  }
1826 
1827  PG_RETURN_TIMEADT(result);
1828 }
#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 235 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().

236 {
237  struct pg_tm tm;
238  DateADT date;
239  int dterr;
240  bool bc = false;
241 
245 
246  /* Handle negative years as BC */
247  if (tm.tm_year < 0)
248  {
249  bc = true;
250  tm.tm_year = -tm.tm_year;
251  }
252 
253  dterr = ValidateDate(DTK_DATE_M, false, false, bc, &tm);
254 
255  if (dterr != 0)
256  ereport(ERROR,
257  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
258  errmsg("date field value out of range: %d-%02d-%02d",
259  tm.tm_year, tm.tm_mon, tm.tm_mday)));
260 
261  /* Prevent overflow in Julian-day routines */
263  ereport(ERROR,
264  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
265  errmsg("date out of range: %d-%02d-%02d",
266  tm.tm_year, tm.tm_mon, tm.tm_mday)));
267 
269 
270  /* Now check for just-out-of-range dates */
271  if (!IS_VALID_DATE(date))
272  ereport(ERROR,
273  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
274  errmsg("date out of range: %d-%02d-%02d",
275  tm.tm_year, tm.tm_mon, tm.tm_mday)));
276 
277  PG_RETURN_DATEADT(date);
278 }
#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:108
#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:2448

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1370 of file date.c.

References ereport, errcode(), errmsg(), ERROR, HOURS_PER_DAY, 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.

1371 {
1372  int tm_hour = PG_GETARG_INT32(0);
1373  int tm_min = PG_GETARG_INT32(1);
1374  double sec = PG_GETARG_FLOAT8(2);
1375  TimeADT time;
1376 
1377  /* This should match the checks in DecodeTimeOnly */
1378  if (tm_hour < 0 || tm_min < 0 || tm_min > MINS_PER_HOUR - 1 ||
1379  sec < 0 || sec > SECS_PER_MINUTE ||
1380  tm_hour > HOURS_PER_DAY ||
1381  /* test for > 24:00:00 */
1382  (tm_hour == HOURS_PER_DAY && (tm_min > 0 || sec > 0)))
1383  ereport(ERROR,
1384  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
1385  errmsg("time field value out of range: %d:%02d:%02g",
1386  tm_hour, tm_min, sec)));
1387 
1388  /* This should match tm2time */
1389  time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1390  * USECS_PER_SEC) + rint(sec * USECS_PER_SEC);
1391 
1392  PG_RETURN_TIMEADT(time);
1393 }
#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 HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int64 TimeADT
Definition: date.h:25
#define ereport(elevel,...)
Definition: elog.h:144
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 1580 of file date.c.

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

1581 {
1582  /*
1583  * The arguments are TimeADT, but we leave them as generic Datums to avoid
1584  * dereferencing nulls (TimeADT is pass-by-reference!)
1585  */
1586  Datum ts1 = PG_GETARG_DATUM(0);
1587  Datum te1 = PG_GETARG_DATUM(1);
1588  Datum ts2 = PG_GETARG_DATUM(2);
1589  Datum te2 = PG_GETARG_DATUM(3);
1590  bool ts1IsNull = PG_ARGISNULL(0);
1591  bool te1IsNull = PG_ARGISNULL(1);
1592  bool ts2IsNull = PG_ARGISNULL(2);
1593  bool te2IsNull = PG_ARGISNULL(3);
1594 
1595 #define TIMEADT_GT(t1,t2) \
1596  (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
1597 #define TIMEADT_LT(t1,t2) \
1598  (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
1599 
1600  /*
1601  * If both endpoints of interval 1 are null, the result is null (unknown).
1602  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
1603  * take ts1 as the lesser endpoint.
1604  */
1605  if (ts1IsNull)
1606  {
1607  if (te1IsNull)
1608  PG_RETURN_NULL();
1609  /* swap null for non-null */
1610  ts1 = te1;
1611  te1IsNull = true;
1612  }
1613  else if (!te1IsNull)
1614  {
1615  if (TIMEADT_GT(ts1, te1))
1616  {
1617  Datum tt = ts1;
1618 
1619  ts1 = te1;
1620  te1 = tt;
1621  }
1622  }
1623 
1624  /* Likewise for interval 2. */
1625  if (ts2IsNull)
1626  {
1627  if (te2IsNull)
1628  PG_RETURN_NULL();
1629  /* swap null for non-null */
1630  ts2 = te2;
1631  te2IsNull = true;
1632  }
1633  else if (!te2IsNull)
1634  {
1635  if (TIMEADT_GT(ts2, te2))
1636  {
1637  Datum tt = ts2;
1638 
1639  ts2 = te2;
1640  te2 = tt;
1641  }
1642  }
1643 
1644  /*
1645  * At this point neither ts1 nor ts2 is null, so we can consider three
1646  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
1647  */
1648  if (TIMEADT_GT(ts1, ts2))
1649  {
1650  /*
1651  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
1652  * in the presence of nulls it's not quite completely so.
1653  */
1654  if (te2IsNull)
1655  PG_RETURN_NULL();
1656  if (TIMEADT_LT(ts1, te2))
1657  PG_RETURN_BOOL(true);
1658  if (te1IsNull)
1659  PG_RETURN_NULL();
1660 
1661  /*
1662  * If te1 is not null then we had ts1 <= te1 above, and we just found
1663  * ts1 >= te2, hence te1 >= te2.
1664  */
1665  PG_RETURN_BOOL(false);
1666  }
1667  else if (TIMEADT_LT(ts1, ts2))
1668  {
1669  /* This case is ts2 < te1 OR te2 < te1 */
1670  if (te1IsNull)
1671  PG_RETURN_NULL();
1672  if (TIMEADT_LT(ts2, te1))
1673  PG_RETURN_BOOL(true);
1674  if (te2IsNull)
1675  PG_RETURN_NULL();
1676 
1677  /*
1678  * If te2 is not null then we had ts2 <= te2 above, and we just found
1679  * ts2 >= te1, hence te2 >= te1.
1680  */
1681  PG_RETURN_BOOL(false);
1682  }
1683  else
1684  {
1685  /*
1686  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
1687  * rather silly way of saying "true if both are nonnull, else null".
1688  */
1689  if (te1IsNull || te2IsNull)
1690  PG_RETURN_NULL();
1691  PG_RETURN_BOOL(true);
1692  }
1693 
1694 #undef TIMEADT_GT
1695 #undef TIMEADT_LT
1696 }
#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 2434 of file date.c.

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

2435 {
2436  /*
2437  * The arguments are TimeTzADT *, but we leave them as generic Datums for
2438  * convenience of notation --- and to avoid dereferencing nulls.
2439  */
2440  Datum ts1 = PG_GETARG_DATUM(0);
2441  Datum te1 = PG_GETARG_DATUM(1);
2442  Datum ts2 = PG_GETARG_DATUM(2);
2443  Datum te2 = PG_GETARG_DATUM(3);
2444  bool ts1IsNull = PG_ARGISNULL(0);
2445  bool te1IsNull = PG_ARGISNULL(1);
2446  bool ts2IsNull = PG_ARGISNULL(2);
2447  bool te2IsNull = PG_ARGISNULL(3);
2448 
2449 #define TIMETZ_GT(t1,t2) \
2450  DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
2451 #define TIMETZ_LT(t1,t2) \
2452  DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
2453 
2454  /*
2455  * If both endpoints of interval 1 are null, the result is null (unknown).
2456  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
2457  * take ts1 as the lesser endpoint.
2458  */
2459  if (ts1IsNull)
2460  {
2461  if (te1IsNull)
2462  PG_RETURN_NULL();
2463  /* swap null for non-null */
2464  ts1 = te1;
2465  te1IsNull = true;
2466  }
2467  else if (!te1IsNull)
2468  {
2469  if (TIMETZ_GT(ts1, te1))
2470  {
2471  Datum tt = ts1;
2472 
2473  ts1 = te1;
2474  te1 = tt;
2475  }
2476  }
2477 
2478  /* Likewise for interval 2. */
2479  if (ts2IsNull)
2480  {
2481  if (te2IsNull)
2482  PG_RETURN_NULL();
2483  /* swap null for non-null */
2484  ts2 = te2;
2485  te2IsNull = true;
2486  }
2487  else if (!te2IsNull)
2488  {
2489  if (TIMETZ_GT(ts2, te2))
2490  {
2491  Datum tt = ts2;
2492 
2493  ts2 = te2;
2494  te2 = tt;
2495  }
2496  }
2497 
2498  /*
2499  * At this point neither ts1 nor ts2 is null, so we can consider three
2500  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
2501  */
2502  if (TIMETZ_GT(ts1, ts2))
2503  {
2504  /*
2505  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
2506  * in the presence of nulls it's not quite completely so.
2507  */
2508  if (te2IsNull)
2509  PG_RETURN_NULL();
2510  if (TIMETZ_LT(ts1, te2))
2511  PG_RETURN_BOOL(true);
2512  if (te1IsNull)
2513  PG_RETURN_NULL();
2514 
2515  /*
2516  * If te1 is not null then we had ts1 <= te1 above, and we just found
2517  * ts1 >= te2, hence te1 >= te2.
2518  */
2519  PG_RETURN_BOOL(false);
2520  }
2521  else if (TIMETZ_LT(ts1, ts2))
2522  {
2523  /* This case is ts2 < te1 OR te2 < te1 */
2524  if (te1IsNull)
2525  PG_RETURN_NULL();
2526  if (TIMETZ_LT(ts2, te1))
2527  PG_RETURN_BOOL(true);
2528  if (te2IsNull)
2529  PG_RETURN_NULL();
2530 
2531  /*
2532  * If te2 is not null then we had ts2 <= te2 above, and we just found
2533  * ts2 >= te1, hence te2 >= te1.
2534  */
2535  PG_RETURN_BOOL(false);
2536  }
2537  else
2538  {
2539  /*
2540  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
2541  * rather silly way of saying "true if both are nonnull, else null".
2542  */
2543  if (te1IsNull || te2IsNull)
2544  PG_RETURN_NULL();
2545  PG_RETURN_BOOL(true);
2546  }
2547 
2548 #undef TIMETZ_GT
2549 #undef TIMETZ_LT
2550 }
#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 1281 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().

1282 {
1283  tm->tm_hour = time / USECS_PER_HOUR;
1284  time -= tm->tm_hour * USECS_PER_HOUR;
1285  tm->tm_min = time / USECS_PER_MINUTE;
1286  time -= tm->tm_min * USECS_PER_MINUTE;
1287  tm->tm_sec = time / USECS_PER_SEC;
1288  time -= tm->tm_sec * USECS_PER_SEC;
1289  *fsec = time;
1290  return 0;
1291 }
#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 1531 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_INT32.

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

1532 {
1533  TimeADT time1 = PG_GETARG_TIMEADT(0);
1534  TimeADT time2 = PG_GETARG_TIMEADT(1);
1535 
1536  if (time1 < time2)
1537  PG_RETURN_INT32(-1);
1538  if (time1 > time2)
1539  PG_RETURN_INT32(1);
1540  PG_RETURN_INT32(0);
1541 }
#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 1477 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

1478 {
1479  TimeADT time1 = PG_GETARG_TIMEADT(0);
1480  TimeADT time2 = PG_GETARG_TIMEADT(1);
1481 
1482  PG_RETURN_BOOL(time1 == time2);
1483 }
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 1522 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

1523 {
1524  TimeADT time1 = PG_GETARG_TIMEADT(0);
1525  TimeADT time2 = PG_GETARG_TIMEADT(1);
1526 
1527  PG_RETURN_BOOL(time1 >= time2);
1528 }
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 1513 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

1514 {
1515  TimeADT time1 = PG_GETARG_TIMEADT(0);
1516  TimeADT time2 = PG_GETARG_TIMEADT(1);
1517 
1518  PG_RETURN_BOOL(time1 > time2);
1519 }
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 1544 of file date.c.

References hashint8().

1545 {
1546  return hashint8(fcinfo);
1547 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1550 of file date.c.

References hashint8extended().

1551 {
1552  return hashint8extended(fcinfo);
1553 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

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

1230 {
1231  char *str = PG_GETARG_CSTRING(0);
1232 
1233 #ifdef NOT_USED
1234  Oid typelem = PG_GETARG_OID(1);
1235 #endif
1236  int32 typmod = PG_GETARG_INT32(2);
1237  TimeADT result;
1238  fsec_t fsec;
1239  struct pg_tm tt,
1240  *tm = &tt;
1241  int tz;
1242  int nf;
1243  int dterr;
1244  char workbuf[MAXDATELEN + 1];
1245  char *field[MAXDATEFIELDS];
1246  int dtype;
1247  int ftype[MAXDATEFIELDS];
1248 
1249  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1250  field, ftype, MAXDATEFIELDS, &nf);
1251  if (dterr == 0)
1252  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1253  if (dterr != 0)
1254  DateTimeParseError(dterr, str, "time");
1255 
1256  tm2time(tm, fsec, &result);
1257  AdjustTimeForTypmod(&result, typmod);
1258 
1259  PG_RETURN_TIMEADT(result);
1260 }
#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:3736
#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:1714
signed int int32
Definition: c.h:355
static struct pg_tm tm
Definition: localtime.c:108
#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:1266
#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:1442

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1786 of file date.c.

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

1787 {
1788  TimeADT time = PG_GETARG_TIMEADT(0);
1789  Interval *result;
1790 
1791  result = (Interval *) palloc(sizeof(Interval));
1792 
1793  result->time = time;
1794  result->day = 0;
1795  result->month = 0;
1796 
1797  PG_RETURN_INTERVAL_P(result);
1798 }
#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 1556 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1557 {
1558  TimeADT time1 = PG_GETARG_TIMEADT(0);
1559  TimeADT time2 = PG_GETARG_TIMEADT(1);
1560 
1561  PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2);
1562 }
#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 1504 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

1505 {
1506  TimeADT time1 = PG_GETARG_TIMEADT(0);
1507  TimeADT time2 = PG_GETARG_TIMEADT(1);
1508 
1509  PG_RETURN_BOOL(time1 <= time2);
1510 }
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 1495 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

1496 {
1497  TimeADT time1 = PG_GETARG_TIMEADT(0);
1498  TimeADT time2 = PG_GETARG_TIMEADT(1);
1499 
1500  PG_RETURN_BOOL(time1 < time2);
1501 }
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 1871 of file date.c.

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

1872 {
1873  TimeADT time = PG_GETARG_TIMEADT(0);
1874  Interval *span = PG_GETARG_INTERVAL_P(1);
1875  TimeADT result;
1876 
1877  result = time - span->time;
1878  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1879  if (result < INT64CONST(0))
1880  result += USECS_PER_DAY;
1881 
1882  PG_RETURN_TIMEADT(result);
1883 }
#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 1834 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().

1835 {
1836  TimeADT time1 = PG_GETARG_TIMEADT(0);
1837  TimeADT time2 = PG_GETARG_TIMEADT(1);
1838  Interval *result;
1839 
1840  result = (Interval *) palloc(sizeof(Interval));
1841 
1842  result->month = 0;
1843  result->day = 0;
1844  result->time = time1 - time2;
1845 
1846  PG_RETURN_INTERVAL_P(result);
1847 }
#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 1486 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

1487 {
1488  TimeADT time1 = PG_GETARG_TIMEADT(0);
1489  TimeADT time2 = PG_GETARG_TIMEADT(1);
1490 
1491  PG_RETURN_BOOL(time1 != time2);
1492 }
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 1294 of file date.c.

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

1295 {
1296  TimeADT time = PG_GETARG_TIMEADT(0);
1297  char *result;
1298  struct pg_tm tt,
1299  *tm = &tt;
1300  fsec_t fsec;
1301  char buf[MAXDATELEN + 1];
1302 
1303  time2tm(time, tm, &fsec);
1304  EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1305 
1306  result = pstrdup(buf);
1307  PG_RETURN_CSTRING(result);
1308 }
#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:3940
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1281
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
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_part()

Datum time_part ( PG_FUNCTION_ARGS  )

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

1930 {
1931  text *units = PG_GETARG_TEXT_PP(0);
1932  TimeADT time = PG_GETARG_TIMEADT(1);
1933  float8 result;
1934  int type,
1935  val;
1936  char *lowunits;
1937 
1938  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
1939  VARSIZE_ANY_EXHDR(units),
1940  false);
1941 
1942  type = DecodeUnits(0, lowunits, &val);
1943  if (type == UNKNOWN_FIELD)
1944  type = DecodeSpecial(0, lowunits, &val);
1945 
1946  if (type == UNITS)
1947  {
1948  fsec_t fsec;
1949  struct pg_tm tt,
1950  *tm = &tt;
1951 
1952  time2tm(time, tm, &fsec);
1953 
1954  switch (val)
1955  {
1956  case DTK_MICROSEC:
1957  result = tm->tm_sec * 1000000.0 + fsec;
1958  break;
1959 
1960  case DTK_MILLISEC:
1961  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
1962  break;
1963 
1964  case DTK_SECOND:
1965  result = tm->tm_sec + fsec / 1000000.0;
1966  break;
1967 
1968  case DTK_MINUTE:
1969  result = tm->tm_min;
1970  break;
1971 
1972  case DTK_HOUR:
1973  result = tm->tm_hour;
1974  break;
1975 
1976  case DTK_TZ:
1977  case DTK_TZ_MINUTE:
1978  case DTK_TZ_HOUR:
1979  case DTK_DAY:
1980  case DTK_MONTH:
1981  case DTK_QUARTER:
1982  case DTK_YEAR:
1983  case DTK_DECADE:
1984  case DTK_CENTURY:
1985  case DTK_MILLENNIUM:
1986  case DTK_ISOYEAR:
1987  default:
1988  ereport(ERROR,
1989  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1990  errmsg("\"time\" units \"%s\" not recognized",
1991  lowunits)));
1992  result = 0;
1993  }
1994  }
1995  else if (type == RESERV && val == DTK_EPOCH)
1996  {
1997  result = time / 1000000.0;
1998  }
1999  else
2000  {
2001  ereport(ERROR,
2002  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2003  errmsg("\"time\" units \"%s\" not recognized",
2004  lowunits)));
2005  result = 0;
2006  }
2007 
2008  PG_RETURN_FLOAT8(result);
2009 }
#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:1281
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3699
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:108
#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:491
#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:3008
#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:555
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 1853 of file date.c.

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

1854 {
1855  TimeADT time = PG_GETARG_TIMEADT(0);
1856  Interval *span = PG_GETARG_INTERVAL_P(1);
1857  TimeADT result;
1858 
1859  result = time + span->time;
1860  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1861  if (result < INT64CONST(0))
1862  result += USECS_PER_DAY;
1863 
1864  PG_RETURN_TIMEADT(result);
1865 }
#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 1314 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.

1315 {
1317 
1318 #ifdef NOT_USED
1319  Oid typelem = PG_GETARG_OID(1);
1320 #endif
1321  int32 typmod = PG_GETARG_INT32(2);
1322  TimeADT result;
1323 
1324  result = pq_getmsgint64(buf);
1325 
1326  if (result < INT64CONST(0) || result > USECS_PER_DAY)
1327  ereport(ERROR,
1328  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1329  errmsg("time out of range")));
1330 
1331  AdjustTimeForTypmod(&result, typmod);
1332 
1333  PG_RETURN_TIMEADT(result);
1334 }
#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:355
#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:1442

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1422 of file date.c.

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

1423 {
1424  TimeADT time = PG_GETARG_TIMEADT(0);
1425  int32 typmod = PG_GETARG_INT32(1);
1426  TimeADT result;
1427 
1428  result = time;
1429  AdjustTimeForTypmod(&result, typmod);
1430 
1431  PG_RETURN_TIMEADT(result);
1432 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
signed int int32
Definition: c.h:355
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1442

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1340 of file date.c.

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

1341 {
1342  TimeADT time = PG_GETARG_TIMEADT(0);
1344 
1345  pq_begintypsend(&buf);
1346  pq_sendint64(&buf, time);
1348 }
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 1565 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1566 {
1567  TimeADT time1 = PG_GETARG_TIMEADT(0);
1568  TimeADT time2 = PG_GETARG_TIMEADT(1);
1569 
1570  PG_RETURN_TIMEADT((time1 < time2) ? time1 : time2);
1571 }
#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 1402 of file date.c.

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

1403 {
1404  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1405  Node *ret = NULL;
1406 
1407  if (IsA(rawreq, SupportRequestSimplify))
1408  {
1410 
1411  ret = TemporalSimplify(MAX_TIME_PRECISION, (Node *) req->fcall);
1412  }
1413 
1414  PG_RETURN_POINTER(ret);
1415 }
#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:4464
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

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

2568 {
2569  TimeADT time = PG_GETARG_TIMEADT(0);
2570  TimeTzADT *result;
2571  struct pg_tm tt,
2572  *tm = &tt;
2573  fsec_t fsec;
2574  int tz;
2575 
2576  GetCurrentDateTime(tm);
2577  time2tm(time, tm, &fsec);
2579 
2580  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2581 
2582  result->time = time;
2583  result->zone = tz;
2584 
2585  PG_RETURN_TIMETZADT_P(result);
2586 }
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:1281
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int32 zone
Definition: date.h:30
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1438
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 970 of file date.c.

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

971 {
973  DateADT dateVal = PG_GETARG_DATEADT(1);
974  Timestamp dt2;
975 
976  dt2 = date2timestamp(dateVal);
977 
979 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

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

1153 {
1155  DateADT result;
1156  struct pg_tm tt,
1157  *tm = &tt;
1158  fsec_t fsec;
1159 
1160  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1161  DATE_NOBEGIN(result);
1162  else if (TIMESTAMP_IS_NOEND(timestamp))
1163  DATE_NOEND(result);
1164  else
1165  {
1166  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1167  ereport(ERROR,
1168  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1169  errmsg("timestamp out of range")));
1170 
1171  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1172  }
1173 
1174  PG_RETURN_DATEADT(result);
1175 }
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:1793
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#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 898 of file date.c.

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

899 {
901  DateADT dateVal = PG_GETARG_DATEADT(1);
902  Timestamp dt2;
903 
904  dt2 = date2timestamp(dateVal);
905 
906  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
907 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_ge_date()

Datum timestamp_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 958 of file date.c.

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

959 {
961  DateADT dateVal = PG_GETARG_DATEADT(1);
962  Timestamp dt2;
963 
964  dt2 = date2timestamp(dateVal);
965 
966  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
967 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_gt_date()

Datum timestamp_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 934 of file date.c.

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

935 {
937  DateADT dateVal = PG_GETARG_DATEADT(1);
938  Timestamp dt2;
939 
940  dt2 = date2timestamp(dateVal);
941 
942  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
943 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_le_date()

Datum timestamp_le_date ( PG_FUNCTION_ARGS  )

Definition at line 946 of file date.c.

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

947 {
949  DateADT dateVal = PG_GETARG_DATEADT(1);
950  Timestamp dt2;
951 
952  dt2 = date2timestamp(dateVal);
953 
954  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
955 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_lt_date()

Datum timestamp_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 922 of file date.c.

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

923 {
925  DateADT dateVal = PG_GETARG_DATEADT(1);
926  Timestamp dt2;
927 
928  dt2 = date2timestamp(dateVal);
929 
930  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
931 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_ne_date()

Datum timestamp_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 910 of file date.c.

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

911 {
913  DateADT dateVal = PG_GETARG_DATEADT(1);
914  Timestamp dt2;
915 
916  dt2 = date2timestamp(dateVal);
917 
918  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
919 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2061
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:603

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

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

1703 {
1705  TimeADT result;
1706  struct pg_tm tt,
1707  *tm = &tt;
1708  fsec_t fsec;
1709 
1710  if (TIMESTAMP_NOT_FINITE(timestamp))
1711  PG_RETURN_NULL();
1712 
1713  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1714  ereport(ERROR,
1715  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1716  errmsg("timestamp out of range")));
1717 
1718  /*
1719  * Could also do this with time = (timestamp / USECS_PER_DAY *
1720  * USECS_PER_DAY) - timestamp;
1721  */
1722  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1723  USECS_PER_SEC) + fsec;
1724 
1725  PG_RETURN_TIMEADT(result);
1726 }
#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:1793
#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:108
#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 1054 of file date.c.

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

1055 {
1057  DateADT dateVal = PG_GETARG_DATEADT(1);
1058  TimestampTz dt2;
1059 
1060  dt2 = date2timestamptz(dateVal);
1061 
1063 }
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:691
#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 1197 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.

1198 {
1200  DateADT result;
1201  struct pg_tm tt,
1202  *tm = &tt;
1203  fsec_t fsec;
1204  int tz;
1205 
1206  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1207  DATE_NOBEGIN(result);
1208  else if (TIMESTAMP_IS_NOEND(timestamp))
1209  DATE_NOEND(result);
1210  else
1211  {
1212  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1213  ereport(ERROR,
1214  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1215  errmsg("timestamp out of range")));
1216 
1217  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1218  }
1219 
1220  PG_RETURN_DATEADT(result);
1221 }
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:1793
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#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 982 of file date.c.

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

983 {
985  DateADT dateVal = PG_GETARG_DATEADT(1);
986  TimestampTz dt2;
987 
988  dt2 = date2timestamptz(dateVal);
989 
991 }
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:691
#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 1042 of file date.c.

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

1043 {
1045  DateADT dateVal = PG_GETARG_DATEADT(1);
1046  TimestampTz dt2;
1047 
1048  dt2 = date2timestamptz(dateVal);
1049 
1050  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0);
1051 }
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:691
#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 1018 of file date.c.

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

1019 {
1021  DateADT dateVal = PG_GETARG_DATEADT(1);
1022  TimestampTz dt2;
1023 
1024  dt2 = date2timestamptz(dateVal);
1025 
1027 }
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:691
#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 1030 of file date.c.

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

1031 {
1033  DateADT dateVal = PG_GETARG_DATEADT(1);
1034  TimestampTz dt2;
1035 
1036  dt2 = date2timestamptz(dateVal);
1037 
1038  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) <= 0);
1039 }
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:691
#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 1006 of file date.c.

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

1007 {
1009  DateADT dateVal = PG_GETARG_DATEADT(1);
1010  TimestampTz dt2;
1011 
1012  dt2 = date2timestamptz(dateVal);
1013 
1015 }
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:691
#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 994 of file date.c.

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

995 {
997  DateADT dateVal = PG_GETARG_DATEADT(1);
998  TimestampTz dt2;
999 
1000  dt2 = date2timestamptz(dateVal);
1001 
1002  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) != 0);
1003 }
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:691
#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 1732 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.

1733 {
1735  TimeADT result;
1736  struct pg_tm tt,
1737  *tm = &tt;
1738  int tz;
1739  fsec_t fsec;
1740 
1741  if (TIMESTAMP_NOT_FINITE(timestamp))
1742  PG_RETURN_NULL();
1743 
1744  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1745  ereport(ERROR,
1746  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1747  errmsg("timestamp out of range")));
1748 
1749  /*
1750  * Could also do this with time = (timestamp / USECS_PER_DAY *
1751  * USECS_PER_DAY) - timestamp;
1752  */
1753  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1754  USECS_PER_SEC) + fsec;
1755 
1756  PG_RETURN_TIMEADT(result);
1757 }
#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:1793
#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:108
#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 2593 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().

2594 {
2596  TimeTzADT *result;
2597  struct pg_tm tt,
2598  *tm = &tt;
2599  int tz;
2600  fsec_t fsec;
2601 
2602  if (TIMESTAMP_NOT_FINITE(timestamp))
2603  PG_RETURN_NULL();
2604 
2605  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2606  ereport(ERROR,
2607  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2608  errmsg("timestamp out of range")));
2609 
2610  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2611 
2612  tm2timetz(tm, fsec, tz, result);
2613 
2614  PG_RETURN_TIMETZADT_P(result);
2615 }
#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:1793
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2020
#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 1351 of file date.c.

References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

1352 {
1354 
1355  PG_RETURN_INT32(anytime_typmodin(false, ta));
1356 }
static int32 anytime_typmodin(bool istz, ArrayType *ta)
Definition: date.c:46
#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 1359 of file date.c.

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

1360 {
1361  int32 typmod = PG_GETARG_INT32(0);
1362 
1363  PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1364 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:355
static char * anytime_typmodout(bool istz, int32 typmod)
Definition: date.c:89
#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 2154 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().

2155 {
2156  TimeOffset trem = time->time;
2157 
2158  tm->tm_hour = trem / USECS_PER_HOUR;
2159  trem -= tm->tm_hour * USECS_PER_HOUR;
2160  tm->tm_min = trem / USECS_PER_MINUTE;
2161  trem -= tm->tm_min * USECS_PER_MINUTE;
2162  tm->tm_sec = trem / USECS_PER_SEC;
2163  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2164 
2165  if (tzp != NULL)
2166  *tzp = time->zone;
2167 
2168  return 0;
2169 }
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 2275 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().

Referenced by compareDatetime(), and leftmostvalue_timetz().

2276 {
2277  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2278  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2279 
2280  PG_RETURN_INT32(timetz_cmp_internal(time1, time2));
2281 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2194 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().

2195 {
2196  TimeOffset t1,
2197  t2;
2198 
2199  /* Primary sort is by true (GMT-equivalent) time */
2200  t1 = time1->time + (time1->zone * USECS_PER_SEC);
2201  t2 = time2->time + (time2->zone * USECS_PER_SEC);
2202 
2203  if (t1 > t2)
2204  return 1;
2205  if (t1 < t2)
2206  return -1;
2207 
2208  /*
2209  * If same GMT time, sort by timezone; we only want to say that two
2210  * timetz's are equal if both the time and zone parts are equal.
2211  */
2212  if (time1->zone > time2->zone)
2213  return 1;
2214  if (time1->zone < time2->zone)
2215  return -1;
2216 
2217  return 0;
2218 }
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 2221 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2222 {
2223  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2224  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2225 
2226  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) == 0);
2227 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2266 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2267 {
2268  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2269  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2270 
2271  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0);
2272 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2257 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2258 {
2259  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2260  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2261 
2262  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0);
2263 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2284 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.

2285 {
2287  uint32 thash;
2288 
2289  /*
2290  * To avoid any problems with padding bytes in the struct, we figure the
2291  * field hashes separately and XOR them.
2292  */
2294  Int64GetDatumFast(key->time)));
2295  thash ^= DatumGetUInt32(hash_uint32(key->zone));
2296  PG_RETURN_UINT32(thash);
2297 }
#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:367
#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 2300 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.

2301 {
2303  Datum seed = PG_GETARG_DATUM(1);
2304  uint64 thash;
2305 
2306  /* Same approach as timetz_hash */
2308  Int64GetDatumFast(key->time),
2309  seed));
2311  DatumGetInt64(seed)));
2312  PG_RETURN_UINT64(thash);
2313 }
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 2030 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().

2031 {
2032  char *str = PG_GETARG_CSTRING(0);
2033 
2034 #ifdef NOT_USED
2035  Oid typelem = PG_GETARG_OID(1);
2036 #endif
2037  int32 typmod = PG_GETARG_INT32(2);
2038  TimeTzADT *result;
2039  fsec_t fsec;
2040  struct pg_tm tt,
2041  *tm = &tt;
2042  int tz;
2043  int nf;
2044  int dterr;
2045  char workbuf[MAXDATELEN + 1];
2046  char *field[MAXDATEFIELDS];
2047  int dtype;
2048  int ftype[MAXDATEFIELDS];
2049 
2050  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
2051  field, ftype, MAXDATEFIELDS, &nf);
2052  if (dterr == 0)
2053  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
2054  if (dterr != 0)
2055  DateTimeParseError(dterr, str, "time with time zone");
2056 
2057  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2058  tm2timetz(tm, fsec, tz, result);
2059  AdjustTimeForTypmod(&(result->time), typmod);
2060 
2061  PG_RETURN_TIMETZADT_P(result);
2062 }
#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:3736
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:1714
signed int int32
Definition: c.h:355
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2020
#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:1442

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

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

2849 {
2851  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2852  TimeTzADT *result;
2853  int tz;
2854 
2855  if (zone->month != 0 || zone->day != 0)
2856  ereport(ERROR,
2857  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2858  errmsg("interval time zone \"%s\" must not include months or days",
2860  PointerGetDatum(zone))))));
2861 
2862  tz = -(zone->time / USECS_PER_SEC);
2863 
2864  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2865 
2866  result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2867  while (result->time < INT64CONST(0))
2868  result->time += USECS_PER_DAY;
2869  while (result->time >= USECS_PER_DAY)
2870  result->time -= USECS_PER_DAY;
2871 
2872  result->zone = tz;
2873 
2874  PG_RETURN_TIMETZADT_P(result);
2875 }
#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:961
#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 2316 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2317 {
2318  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2319  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2320  TimeTzADT *result;
2321 
2322  if (timetz_cmp_internal(time1, time2) > 0)
2323  result = time1;
2324  else
2325  result = time2;
2326  PG_RETURN_TIMETZADT_P(result);
2327 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2248 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2249 {
2250  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2251  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2252 
2253  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0);
2254 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2239 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2240 {
2241  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2242  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2243 
2244  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) < 0);
2245 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2369 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.

2370 {
2371  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2372  Interval *span = PG_GETARG_INTERVAL_P(1);
2373  TimeTzADT *result;
2374 
2375  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2376 
2377  result->time = time->time - span->time;
2378  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2379  if (result->time < INT64CONST(0))
2380  result->time += USECS_PER_DAY;
2381 
2382  result->zone = time->zone;
2383 
2384  PG_RETURN_TIMETZADT_P(result);
2385 }
#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 2230 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2231 {
2232  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2233  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2234 
2235  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) != 0);
2236 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#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 2065 of file date.c.

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

2066 {
2067  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2068  char *result;
2069  struct pg_tm tt,
2070  *tm = &tt;
2071  fsec_t fsec;
2072  int tz;
2073  char buf[MAXDATELEN + 1];
2074 
2075  timetz2tm(time, tm, &fsec, &tz);
2076  EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2077 
2078  result = pstrdup(buf);
2079  PG_RETURN_CSTRING(result);
2080 }
#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:3940
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
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:2154
#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 2666 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.

2667 {
2668  text *units = PG_GETARG_TEXT_PP(0);
2669  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2670  float8 result;
2671  int type,
2672  val;
2673  char *lowunits;
2674 
2675  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
2676  VARSIZE_ANY_EXHDR(units),
2677  false);
2678 
2679  type = DecodeUnits(0, lowunits, &val);
2680  if (type == UNKNOWN_FIELD)
2681  type = DecodeSpecial(0, lowunits, &val);
2682 
2683  if (type == UNITS)
2684  {
2685  double dummy;
2686  int tz;
2687  fsec_t fsec;
2688  struct pg_tm tt,
2689  *tm = &tt;
2690 
2691  timetz2tm(time, tm, &fsec, &tz);
2692 
2693  switch (val)
2694  {
2695  case DTK_TZ:
2696  result = -tz;
2697  break;
2698 
2699  case DTK_TZ_MINUTE:
2700  result = -tz;
2701  result /= SECS_PER_MINUTE;
2702  FMODULO(result, dummy, (double) SECS_PER_MINUTE);
2703  break;
2704 
2705  case DTK_TZ_HOUR:
2706  dummy = -tz;
2707  FMODULO(dummy, result, (double) SECS_PER_HOUR);
2708  break;
2709 
2710  case DTK_MICROSEC:
2711  result = tm->tm_sec * 1000000.0 + fsec;
2712  break;
2713 
2714  case DTK_MILLISEC:
2715  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2716  break;
2717 
2718  case DTK_SECOND:
2719  result = tm->tm_sec + fsec / 1000000.0;
2720  break;
2721 
2722  case DTK_MINUTE:
2723  result = tm->tm_min;
2724  break;
2725 
2726  case DTK_HOUR:
2727  result = tm->tm_hour;
2728  break;
2729 
2730  case DTK_DAY:
2731  case DTK_MONTH:
2732  case DTK_QUARTER:
2733  case DTK_YEAR:
2734  case DTK_DECADE:
2735  case DTK_CENTURY:
2736  case DTK_MILLENNIUM:
2737  default:
2738  ereport(ERROR,
2739  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2740  errmsg("\"time with time zone\" units \"%s\" not recognized",
2741  lowunits)));
2742  result = 0;
2743  }
2744  }
2745  else if (type == RESERV && val == DTK_EPOCH)
2746  {
2747  result = time->time / 1000000.0 + time->zone;
2748  }
2749  else
2750  {
2751  ereport(ERROR,
2752  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2753  errmsg("\"time with time zone\" units \"%s\" not recognized",
2754  lowunits)));
2755  result = 0;
2756  }
2757 
2758  PG_RETURN_FLOAT8(result);
2759 }
#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:3699
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:108
#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:491
#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:2154
#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:3008
#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:555
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 2347 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.

2348 {
2349  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2350  Interval *span = PG_GETARG_INTERVAL_P(1);
2351  TimeTzADT *result;
2352 
2353  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2354 
2355  result->time = time->time + span->time;
2356  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2357  if (result->time < INT64CONST(0))
2358  result->time += USECS_PER_DAY;
2359 
2360  result->zone = time->zone;
2361 
2362  PG_RETURN_TIMETZADT_P(result);
2363 }
#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 2086 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.

2087 {
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 
2096  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2097 
2098  result->time = pq_getmsgint64(buf);
2099 
2100  if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2101  ereport(ERROR,
2102  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2103  errmsg("time out of range")));
2104 
2105  result->zone = pq_getmsgint(buf, sizeof(result->zone));
2106 
2107  /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2108  if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2109  ereport(ERROR,
2110  (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
2111  errmsg("time zone displacement out of range")));
2112 
2113  AdjustTimeForTypmod(&(result->time), typmod);
2114 
2115  PG_RETURN_TIMETZADT_P(result);
2116 }
#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:355
#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:1442

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2176 of file date.c.

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

2177 {
2178  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2179  int32 typmod = PG_GETARG_INT32(1);
2180  TimeTzADT *result;
2181 
2182  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2183 
2184  result->time = time->time;
2185  result->zone = time->zone;
2186 
2187  AdjustTimeForTypmod(&(result->time), typmod);
2188 
2189  PG_RETURN_TIMETZADT_P(result);
2190 }
#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
signed int int32
Definition: c.h:355
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1442

◆ timetz_send()

Datum timetz_send ( PG_FUNCTION_ARGS  )

Definition at line 2122 of file date.c.

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

2123 {
2124  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2126 
2127  pq_begintypsend(&buf);
2128  pq_sendint64(&buf, time->time);
2129  pq_sendint32(&buf, time->zone);
2131 }
TimeADT time
Definition: date.h:29
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 void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
int32 zone
Definition: date.h:30
static char * buf
Definition: pg_test_fsync.c:67
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
Definition: date.h:27

◆ timetz_smaller()

Datum timetz_smaller ( PG_FUNCTION_ARGS  )

Definition at line 2330 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2331 {
2332  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2333  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2334  TimeTzADT *result;
2335 
2336  if (timetz_cmp_internal(time1, time2) < 0)
2337  result = time1;
2338  else
2339  result = time2;
2340  PG_RETURN_TIMETZADT_P(result);
2341 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2194
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
Definition: date.h:27

◆ timetz_time()

Datum timetz_time ( PG_FUNCTION_ARGS  )

Definition at line 2554 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and TimeTzADT::time.

2555 {
2556  TimeTzADT *timetz = PG_GETARG_TIMETZADT_P(0);
2557  TimeADT result;
2558 
2559  /* swallow the time zone and just return the time */
2560  result = timetz->time;
2561 
2562  PG_RETURN_TIMEADT(result);
2563 }
TimeADT time
Definition: date.h:29