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

Go to the source code of this file.

Macros

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

Functions

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

Macro Definition Documentation

◆ TIMEADT_GT

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

Referenced by overlaps_time().

◆ TIMEADT_LT

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

Referenced by overlaps_time().

◆ TIMETZ_GT

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

Referenced by overlaps_timetz().

◆ TIMETZ_LT

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

Referenced by overlaps_timetz().

Function Documentation

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)

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

1470 {
1471  static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1472  INT64CONST(1000000),
1473  INT64CONST(100000),
1474  INT64CONST(10000),
1475  INT64CONST(1000),
1476  INT64CONST(100),
1477  INT64CONST(10),
1478  INT64CONST(1)
1479  };
1480 
1481  static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1482  INT64CONST(500000),
1483  INT64CONST(50000),
1484  INT64CONST(5000),
1485  INT64CONST(500),
1486  INT64CONST(50),
1487  INT64CONST(5),
1488  INT64CONST(0)
1489  };
1490 
1491  if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1492  {
1493  if (*time >= INT64CONST(0))
1494  *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1495  TimeScales[typmod];
1496  else
1497  *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1498  TimeScales[typmod]);
1499  }
1500 }
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 68 of file date.c.

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

Referenced by anytime_typmodin(), and transformSQLValueFunction().

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

◆ anytime_typmodin()

static int32 anytime_typmodin ( bool  istz,
ArrayType ta 
)
static

Definition at line 47 of file date.c.

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

Referenced by timetypmodin(), and timetztypmodin().

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

◆ anytime_typmodout()

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

Definition at line 90 of file date.c.

References psprintf().

Referenced by timetypmodout(), and timetztypmodout().

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

◆ date2timestamp()

static TimestampTz date2timestamp ( DateADT  dateVal)
static

Definition at line 612 of file date.c.

References date2timestamp_opt_overflow().

Referenced by date_mi_interval(), date_pl_interval(), date_timestamp(), datetime_timestamp(), and in_range_date_interval().

613 {
614  return date2timestamp_opt_overflow(dateVal, NULL);
615 }
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:568

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 724 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

725 {
726  double result;
727 
728  if (DATE_IS_NOBEGIN(dateVal))
729  result = -DBL_MAX;
730  else if (DATE_IS_NOEND(dateVal))
731  result = DBL_MAX;
732  else
733  {
734  /* date is days since 2000, timestamp is microseconds since same... */
735  result = dateVal * (double) USECS_PER_DAY;
736  }
737 
738  return result;
739 }
#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 568 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 date2timestamp(), and date_cmp_timestamp_internal().

569 {
570  Timestamp result;
571 
572  if (overflow)
573  *overflow = 0;
574 
575  if (DATE_IS_NOBEGIN(dateVal))
576  TIMESTAMP_NOBEGIN(result);
577  else if (DATE_IS_NOEND(dateVal))
578  TIMESTAMP_NOEND(result);
579  else
580  {
581  /*
582  * Since dates have the same minimum values as timestamps, only upper
583  * boundary need be checked for overflow.
584  */
585  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
586  {
587  if (overflow)
588  {
589  *overflow = 1;
590  TIMESTAMP_NOEND(result);
591  return result;
592  }
593  else
594  {
595  ereport(ERROR,
596  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
597  errmsg("date out of range for timestamp")));
598  }
599  }
600 
601  /* date is days since 2000, timestamp is microseconds since same... */
602  result = dateVal * USECS_PER_DAY;
603  }
604 
605  return result;
606 }
#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:821
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ date2timestamptz()

static TimestampTz date2timestamptz ( DateADT  dateVal)
static

Definition at line 708 of file date.c.

References date2timestamptz_opt_overflow().

Referenced by date_timestamptz().

709 {
710  return date2timestamptz_opt_overflow(dateVal, NULL);
711 }
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:628

◆ date2timestamptz_opt_overflow()

TimestampTz date2timestamptz_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 628 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, DetermineTimeZoneOffset(), 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 date2timestamptz(), and date_cmp_timestamptz_internal().

629 {
630  TimestampTz result;
631  struct pg_tm tt,
632  *tm = &tt;
633  int tz;
634 
635  if (overflow)
636  *overflow = 0;
637 
638  if (DATE_IS_NOBEGIN(dateVal))
639  TIMESTAMP_NOBEGIN(result);
640  else if (DATE_IS_NOEND(dateVal))
641  TIMESTAMP_NOEND(result);
642  else
643  {
644  /*
645  * Since dates have the same minimum values as timestamps, only upper
646  * boundary need be checked for overflow.
647  */
648  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
649  {
650  if (overflow)
651  {
652  *overflow = 1;
653  TIMESTAMP_NOEND(result);
654  return result;
655  }
656  else
657  {
658  ereport(ERROR,
659  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
660  errmsg("date out of range for timestamp")));
661  }
662  }
663 
664  j2date(dateVal + POSTGRES_EPOCH_JDATE,
665  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
666  tm->tm_hour = 0;
667  tm->tm_min = 0;
668  tm->tm_sec = 0;
670 
671  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
672 
673  /*
674  * Since it is possible to go beyond allowed timestamptz range because
675  * of time zone, check for allowed timestamp range after adding tz.
676  */
677  if (!IS_VALID_TIMESTAMP(result))
678  {
679  if (overflow)
680  {
681  if (result < MIN_TIMESTAMP)
682  {
683  *overflow = -1;
684  TIMESTAMP_NOBEGIN(result);
685  }
686  else
687  {
688  *overflow = 1;
689  TIMESTAMP_NOEND(result);
690  }
691  }
692  else
693  {
694  ereport(ERROR,
695  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
696  errmsg("date out of range for timestamp")));
697  }
698  }
699  }
700 
701  return result;
702 }
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:181
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28
#define USECS_PER_SEC
Definition: timestamp.h:94
int64 TimestampTz
Definition: timestamp.h:39
int tm_hour
Definition: pgtime.h:29
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1478
#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 ereport(elevel,...)
Definition: elog.h:144
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:195
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:821
#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 818 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_INT32.

819 {
820  DateADT dateVal = PG_GETARG_DATEADT(0);
822 
824 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_cmp_timestamp_internal()

int32 date_cmp_timestamp_internal ( DateADT  dateVal,
Timestamp  dt2 
)

Definition at line 747 of file date.c.

References Assert, date2timestamp_opt_overflow(), timestamp_cmp_internal(), and TIMESTAMP_IS_NOEND.

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

748 {
749  Timestamp dt1;
750  int overflow;
751 
752  dt1 = date2timestamp_opt_overflow(dateVal, &overflow);
753  if (overflow > 0)
754  {
755  /* dt1 is larger than any finite timestamp, but less than infinity */
756  return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
757  }
758  Assert(overflow == 0); /* -1 case cannot occur */
759 
760  return timestamp_cmp_internal(dt1, dt2);
761 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2056
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:568
int64 Timestamp
Definition: timestamp.h:38
#define Assert(condition)
Definition: c.h:746
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 902 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_INT32.

903 {
904  DateADT dateVal = PG_GETARG_DATEADT(0);
906 
908 }
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
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ date_cmp_timestamptz_internal()

int32 date_cmp_timestamptz_internal ( DateADT  dateVal,
TimestampTz  dt2 
)

Definition at line 827 of file date.c.

References date2timestamptz_opt_overflow(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, and timestamptz_cmp_internal.

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

828 {
829  TimestampTz dt1;
830  int overflow;
831 
832  dt1 = date2timestamptz_opt_overflow(dateVal, &overflow);
833  if (overflow > 0)
834  {
835  /* dt1 is larger than any finite timestamp, but less than infinity */
836  return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
837  }
838  if (overflow < 0)
839  {
840  /* dt1 is less than any finite timestamp, but more than -infinity */
841  return TIMESTAMP_IS_NOBEGIN(dt2) ? +1 : -1;
842  }
843 
844  return timestamptz_cmp_internal(dt1, dt2);
845 }
int64 TimestampTz
Definition: timestamp.h:39
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:628
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:115

◆ 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 764 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

765 {
766  DateADT dateVal = PG_GETARG_DATEADT(0);
768 
769  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) == 0);
770 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_eq_timestamptz()

Datum date_eq_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 848 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

849 {
850  DateADT dateVal = PG_GETARG_DATEADT(0);
852 
853  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt2) == 0);
854 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ 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 809 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

810 {
811  DateADT dateVal = PG_GETARG_DATEADT(0);
813 
814  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) >= 0);
815 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_ge_timestamptz()

Datum date_ge_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 893 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

894 {
895  DateADT dateVal = PG_GETARG_DATEADT(0);
897 
898  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt2) >= 0);
899 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ 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 791 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

792 {
793  DateADT dateVal = PG_GETARG_DATEADT(0);
795 
796  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) > 0);
797 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_gt_timestamptz()

Datum date_gt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 875 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

876 {
877  DateADT dateVal = PG_GETARG_DATEADT(0);
879 
881 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ date_in()

Datum date_in ( PG_FUNCTION_ARGS  )

Definition at line 110 of file date.c.

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

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

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

801 {
802  DateADT dateVal = PG_GETARG_DATEADT(0);
804 
805  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) <= 0);
806 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_le_timestamptz()

Datum date_le_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 884 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

885 {
886  DateADT dateVal = PG_GETARG_DATEADT(0);
888 
889  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt2) <= 0);
890 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ 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 782 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

783 {
784  DateADT dateVal = PG_GETARG_DATEADT(0);
786 
787  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) < 0);
788 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_lt_timestamptz()

Datum date_lt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 866 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

867 {
868  DateADT dateVal = PG_GETARG_DATEADT(0);
870 
872 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ 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:363
#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:821

◆ date_mi_interval()

Datum date_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1093 of file date.c.

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

1094 {
1095  DateADT dateVal = PG_GETARG_DATEADT(0);
1096  Interval *span = PG_GETARG_INTERVAL_P(1);
1097  Timestamp dateStamp;
1098 
1099  dateStamp = date2timestamp(dateVal);
1100 
1102  TimestampGetDatum(dateStamp),
1103  PointerGetDatum(span));
1104 }
#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:2886
#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:612
#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:363
#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:821
#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 773 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

774 {
775  DateADT dateVal = PG_GETARG_DATEADT(0);
777 
778  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt2) != 0);
779 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ date_ne_timestamptz()

Datum date_ne_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 857 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

858 {
859  DateADT dateVal = PG_GETARG_DATEADT(0);
861 
862  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt2) != 0);
863 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ date_out()

Datum date_out ( PG_FUNCTION_ARGS  )

Definition at line 175 of file date.c.

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

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

◆ date_pl_interval()

Datum date_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 1073 of file date.c.

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

1074 {
1075  DateADT dateVal = PG_GETARG_DATEADT(0);
1076  Interval *span = PG_GETARG_INTERVAL_P(1);
1077  Timestamp dateStamp;
1078 
1079  dateStamp = date2timestamp(dateVal);
1080 
1082  TimestampGetDatum(dateStamp),
1083  PointerGetDatum(span));
1084 }
#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:2807
#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:612
#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:363
#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:821
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_recv()

Datum date_recv ( PG_FUNCTION_ARGS  )

Definition at line 200 of file date.c.

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

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

◆ date_send()

Datum date_send ( PG_FUNCTION_ARGS  )

Definition at line 222 of file date.c.

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

223 {
226 
227  pq_begintypsend(&buf);
228  pq_sendint32(&buf, date);
230 }
int32 DateADT
Definition: date.h:23
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
long date
Definition: pgtypes_date.h:9
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:369
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:145
static char * buf
Definition: pg_test_fsync.c:68
#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 1110 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1111 {
1112  DateADT dateVal = PG_GETARG_DATEADT(0);
1113  Timestamp result;
1114 
1115  result = date2timestamp(dateVal);
1116 
1117  PG_RETURN_TIMESTAMP(result);
1118 }
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:612

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1154 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1155 {
1156  DateADT dateVal = PG_GETARG_DATEADT(0);
1157  TimestampTz result;
1158 
1159  result = date2timestamptz(dateVal);
1160 
1161  PG_RETURN_TIMESTAMP(result);
1162 }
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:708
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

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

1791 {
1793  TimeADT time = PG_GETARG_TIMEADT(1);
1794  Timestamp result;
1795 
1796  result = date2timestamp(date);
1797  if (!TIMESTAMP_NOT_FINITE(result))
1798  {
1799  result += time;
1800  if (!IS_VALID_TIMESTAMP(result))
1801  ereport(ERROR,
1802  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1803  errmsg("timestamp out of range")));
1804  }
1805 
1806  PG_RETURN_TIMESTAMP(result);
1807 }
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:821
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:612

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

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

2653 {
2655  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2656  TimestampTz result;
2657 
2658  if (DATE_IS_NOBEGIN(date))
2659  TIMESTAMP_NOBEGIN(result);
2660  else if (DATE_IS_NOEND(date))
2661  TIMESTAMP_NOEND(result);
2662  else
2663  {
2664  /*
2665  * Date's range is wider than timestamp's, so check for boundaries.
2666  * Since dates have the same minimum values as timestamps, only upper
2667  * boundary need be checked for overflow.
2668  */
2670  ereport(ERROR,
2671  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2672  errmsg("date out of range for timestamp")));
2673  result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
2674 
2675  /*
2676  * Since it is possible to go beyond allowed timestamptz range because
2677  * of time zone, check for allowed timestamp range after adding tz.
2678  */
2679  if (!IS_VALID_TIMESTAMP(result))
2680  ereport(ERROR,
2681  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2682  errmsg("date out of range for timestamp")));
2683  }
2684 
2685  PG_RETURN_TIMESTAMP(result);
2686 }
#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:821
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
Definition: date.h:27

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 285 of file date.c.

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

Referenced by date_out(), and JsonEncodeDateTime().

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

◆ float_time_overflows()

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

Definition at line 1273 of file date.c.

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

Referenced by make_time(), and make_timestamp_internal().

1274 {
1275  /* Range-check the fields individually. */
1276  if (hour < 0 || hour > HOURS_PER_DAY ||
1277  min < 0 || min >= MINS_PER_HOUR)
1278  return true;
1279 
1280  /*
1281  * "sec", being double, requires extra care. Cope with NaN, and round off
1282  * before applying the range check to avoid unexpected errors due to
1283  * imprecise input. (We assume rint() behaves sanely with infinities.)
1284  */
1285  if (isnan(sec))
1286  return true;
1287  sec = rint(sec * USECS_PER_SEC);
1288  if (sec < 0 || sec > SECS_PER_MINUTE * USECS_PER_SEC)
1289  return true;
1290 
1291  /*
1292  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1293  * that the total time value doesn't exceed 24:00:00. This must match the
1294  * way that callers will convert the fields to a time.
1295  */
1296  if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1297  * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1298  return true;
1299 
1300  return false;
1301 }
#define USECS_PER_SEC
Definition: timestamp.h:94
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 300 of file date.c.

References date2j(), GetCurrentDateTime(), POSTGRES_EPOCH_JDATE, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by ExecEvalSQLValueFunction().

301 {
302  struct pg_tm tm;
303 
304  static int cache_year = 0;
305  static int cache_mon = 0;
306  static int cache_mday = 0;
307  static DateADT cache_date;
308 
310 
311  /*
312  * date2j involves several integer divisions; moreover, unless our session
313  * lives across local midnight, we don't really have to do it more than
314  * once. So it seems worth having a separate cache here.
315  */
316  if (tm.tm_year != cache_year ||
317  tm.tm_mon != cache_mon ||
318  tm.tm_mday != cache_mday)
319  {
321  cache_year = tm.tm_year;
322  cache_mon = tm.tm_mon;
323  cache_mday = tm.tm_mday;
324  }
325 
326  return cache_date;
327 }
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:349
int32 DateADT
Definition: date.h:23
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int date2j(int y, int m, int d)
Definition: datetime.c:269
int tm_year
Definition: pgtime.h:32
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ GetSQLCurrentTime()

TimeTzADT* GetSQLCurrentTime ( int32  typmod)

Definition at line 333 of file date.c.

References AdjustTimeForTypmod(), GetCurrentTimeUsec(), palloc(), TimeTzADT::time, tm, and tm2timetz().

Referenced by ExecEvalSQLValueFunction().

334 {
335  TimeTzADT *result;
336  struct pg_tm tt,
337  *tm = &tt;
338  fsec_t fsec;
339  int tz;
340 
341  GetCurrentTimeUsec(tm, &fsec, &tz);
342 
343  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
344  tm2timetz(tm, fsec, tz, result);
345  AdjustTimeForTypmod(&(result->time), typmod);
346  return result;
347 }
TimeADT time
Definition: date.h:29
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2047
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:370
int32 fsec_t
Definition: timestamp.h:41
void * palloc(Size size)
Definition: mcxt.c:950
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 353 of file date.c.

References AdjustTimeForTypmod(), GetCurrentTimeUsec(), tm, and tm2time().

Referenced by ExecEvalSQLValueFunction().

354 {
355  TimeADT result;
356  struct pg_tm tt,
357  *tm = &tt;
358  fsec_t fsec;
359  int tz;
360 
361  GetCurrentTimeUsec(tm, &fsec, &tz);
362 
363  tm2time(tm, fsec, &result);
364  AdjustTimeForTypmod(&result, typmod);
365  return result;
366 }
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:370
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:1238
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ in_range_date_interval()

Datum in_range_date_interval ( PG_FUNCTION_ARGS  )

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

1044 {
1046  DateADT base = PG_GETARG_DATEADT(1);
1047  Interval *offset = PG_GETARG_INTERVAL_P(2);
1048  bool sub = PG_GETARG_BOOL(3);
1049  bool less = PG_GETARG_BOOL(4);
1050  Timestamp valStamp;
1051  Timestamp baseStamp;
1052 
1053  /* XXX we could support out-of-range cases here, perhaps */
1054  valStamp = date2timestamp(val);
1055  baseStamp = date2timestamp(base);
1056 
1058  TimestampGetDatum(valStamp),
1059  TimestampGetDatum(baseStamp),
1060  IntervalPGetDatum(offset),
1061  BoolGetDatum(sub),
1062  BoolGetDatum(less));
1063 }
#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:3315
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:612
long val
Definition: informix.c:664

◆ in_range_time_interval()

Datum in_range_time_interval ( PG_FUNCTION_ARGS  )

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

1917 {
1919  TimeADT base = PG_GETARG_TIMEADT(1);
1920  Interval *offset = PG_GETARG_INTERVAL_P(2);
1921  bool sub = PG_GETARG_BOOL(3);
1922  bool less = PG_GETARG_BOOL(4);
1923  TimeADT sum;
1924 
1925  /*
1926  * Like time_pl_interval/time_mi_interval, we disregard the month and day
1927  * fields of the offset. So our test for negative should too.
1928  */
1929  if (offset->time < 0)
1930  ereport(ERROR,
1931  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1932  errmsg("invalid preceding or following size in window function")));
1933 
1934  /*
1935  * We can't use time_pl_interval/time_mi_interval here, because their
1936  * wraparound behavior would give wrong (or at least undesirable) answers.
1937  * Fortunately the equivalent non-wrapping behavior is trivial, especially
1938  * since we don't worry about integer overflow.
1939  */
1940  if (sub)
1941  sum = base - offset->time;
1942  else
1943  sum = base + offset->time;
1944 
1945  if (less)
1946  PG_RETURN_BOOL(val <= sum);
1947  else
1948  PG_RETURN_BOOL(val >= sum);
1949 }
#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:821
long val
Definition: informix.c:664

◆ in_range_timetz_interval()

Datum in_range_timetz_interval ( PG_FUNCTION_ARGS  )

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

2419 {
2421  TimeTzADT *base = PG_GETARG_TIMETZADT_P(1);
2422  Interval *offset = PG_GETARG_INTERVAL_P(2);
2423  bool sub = PG_GETARG_BOOL(3);
2424  bool less = PG_GETARG_BOOL(4);
2425  TimeTzADT sum;
2426 
2427  /*
2428  * Like timetz_pl_interval/timetz_mi_interval, we disregard the month and
2429  * day fields of the offset. So our test for negative should too.
2430  */
2431  if (offset->time < 0)
2432  ereport(ERROR,
2433  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
2434  errmsg("invalid preceding or following size in window function")));
2435 
2436  /*
2437  * We can't use timetz_pl_interval/timetz_mi_interval here, because their
2438  * wraparound behavior would give wrong (or at least undesirable) answers.
2439  * Fortunately the equivalent non-wrapping behavior is trivial, especially
2440  * since we don't worry about integer overflow.
2441  */
2442  if (sub)
2443  sum.time = base->time - offset->time;
2444  else
2445  sum.time = base->time + offset->time;
2446  sum.zone = base->zone;
2447 
2448  if (less)
2449  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) <= 0);
2450  else
2451  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) >= 0);
2452 }
#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:2221
#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:821
Definition: date.h:27
long val
Definition: informix.c:664

◆ interval_time()

Datum interval_time ( PG_FUNCTION_ARGS  )

Definition at line 1836 of file date.c.

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

1837 {
1838  Interval *span = PG_GETARG_INTERVAL_P(0);
1839  TimeADT result;
1840  int64 days;
1841 
1842  result = span->time;
1843  if (result >= USECS_PER_DAY)
1844  {
1845  days = result / USECS_PER_DAY;
1846  result -= days * USECS_PER_DAY;
1847  }
1848  else if (result < 0)
1849  {
1850  days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
1851  result += days * USECS_PER_DAY;
1852  }
1853 
1854  PG_RETURN_TIMEADT(result);
1855 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
TimeOffset time
Definition: timestamp.h:45
const char *const days[]
Definition: datetime.c:68
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ make_date()

Datum make_date ( PG_FUNCTION_ARGS  )

Definition at line 236 of file date.c.

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

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

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1401 of file date.c.

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

1402 {
1403  int tm_hour = PG_GETARG_INT32(0);
1404  int tm_min = PG_GETARG_INT32(1);
1405  double sec = PG_GETARG_FLOAT8(2);
1406  TimeADT time;
1407 
1408  /* Check for time overflow */
1409  if (float_time_overflows(tm_hour, tm_min, sec))
1410  ereport(ERROR,
1411  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
1412  errmsg("time field value out of range: %d:%02d:%02g",
1413  tm_hour, tm_min, sec)));
1414 
1415  /* This should match tm2time */
1416  time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1417  * USECS_PER_SEC) + (int64) rint(sec * USECS_PER_SEC);
1418 
1419  PG_RETURN_TIMEADT(time);
1420 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:281
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:610
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int64 TimeADT
Definition: date.h:25
#define ereport(elevel,...)
Definition: elog.h:144
bool float_time_overflows(int hour, int min, double sec)
Definition: date.c:1273
int errmsg(const char *fmt,...)
Definition: elog.c:821
int tm_min
Definition: pgtime.h:28

◆ overlaps_time()

Datum overlaps_time ( PG_FUNCTION_ARGS  )

Definition at line 1607 of file date.c.

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

1608 {
1609  /*
1610  * The arguments are TimeADT, but we leave them as generic Datums to avoid
1611  * dereferencing nulls (TimeADT is pass-by-reference!)
1612  */
1613  Datum ts1 = PG_GETARG_DATUM(0);
1614  Datum te1 = PG_GETARG_DATUM(1);
1615  Datum ts2 = PG_GETARG_DATUM(2);
1616  Datum te2 = PG_GETARG_DATUM(3);
1617  bool ts1IsNull = PG_ARGISNULL(0);
1618  bool te1IsNull = PG_ARGISNULL(1);
1619  bool ts2IsNull = PG_ARGISNULL(2);
1620  bool te2IsNull = PG_ARGISNULL(3);
1621 
1622 #define TIMEADT_GT(t1,t2) \
1623  (DatumGetTimeADT(t1) > DatumGetTimeADT(t2))
1624 #define TIMEADT_LT(t1,t2) \
1625  (DatumGetTimeADT(t1) < DatumGetTimeADT(t2))
1626 
1627  /*
1628  * If both endpoints of interval 1 are null, the result is null (unknown).
1629  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
1630  * take ts1 as the lesser endpoint.
1631  */
1632  if (ts1IsNull)
1633  {
1634  if (te1IsNull)
1635  PG_RETURN_NULL();
1636  /* swap null for non-null */
1637  ts1 = te1;
1638  te1IsNull = true;
1639  }
1640  else if (!te1IsNull)
1641  {
1642  if (TIMEADT_GT(ts1, te1))
1643  {
1644  Datum tt = ts1;
1645 
1646  ts1 = te1;
1647  te1 = tt;
1648  }
1649  }
1650 
1651  /* Likewise for interval 2. */
1652  if (ts2IsNull)
1653  {
1654  if (te2IsNull)
1655  PG_RETURN_NULL();
1656  /* swap null for non-null */
1657  ts2 = te2;
1658  te2IsNull = true;
1659  }
1660  else if (!te2IsNull)
1661  {
1662  if (TIMEADT_GT(ts2, te2))
1663  {
1664  Datum tt = ts2;
1665 
1666  ts2 = te2;
1667  te2 = tt;
1668  }
1669  }
1670 
1671  /*
1672  * At this point neither ts1 nor ts2 is null, so we can consider three
1673  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
1674  */
1675  if (TIMEADT_GT(ts1, ts2))
1676  {
1677  /*
1678  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
1679  * in the presence of nulls it's not quite completely so.
1680  */
1681  if (te2IsNull)
1682  PG_RETURN_NULL();
1683  if (TIMEADT_LT(ts1, te2))
1684  PG_RETURN_BOOL(true);
1685  if (te1IsNull)
1686  PG_RETURN_NULL();
1687 
1688  /*
1689  * If te1 is not null then we had ts1 <= te1 above, and we just found
1690  * ts1 >= te2, hence te1 >= te2.
1691  */
1692  PG_RETURN_BOOL(false);
1693  }
1694  else if (TIMEADT_LT(ts1, ts2))
1695  {
1696  /* This case is ts2 < te1 OR te2 < te1 */
1697  if (te1IsNull)
1698  PG_RETURN_NULL();
1699  if (TIMEADT_LT(ts2, te1))
1700  PG_RETURN_BOOL(true);
1701  if (te2IsNull)
1702  PG_RETURN_NULL();
1703 
1704  /*
1705  * If te2 is not null then we had ts2 <= te2 above, and we just found
1706  * ts2 >= te1, hence te2 >= te1.
1707  */
1708  PG_RETURN_BOOL(false);
1709  }
1710  else
1711  {
1712  /*
1713  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
1714  * rather silly way of saying "true if both are nonnull, else null".
1715  */
1716  if (te1IsNull || te2IsNull)
1717  PG_RETURN_NULL();
1718  PG_RETURN_BOOL(true);
1719  }
1720 
1721 #undef TIMEADT_GT
1722 #undef TIMEADT_LT
1723 }
#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 2461 of file date.c.

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

2462 {
2463  /*
2464  * The arguments are TimeTzADT *, but we leave them as generic Datums for
2465  * convenience of notation --- and to avoid dereferencing nulls.
2466  */
2467  Datum ts1 = PG_GETARG_DATUM(0);
2468  Datum te1 = PG_GETARG_DATUM(1);
2469  Datum ts2 = PG_GETARG_DATUM(2);
2470  Datum te2 = PG_GETARG_DATUM(3);
2471  bool ts1IsNull = PG_ARGISNULL(0);
2472  bool te1IsNull = PG_ARGISNULL(1);
2473  bool ts2IsNull = PG_ARGISNULL(2);
2474  bool te2IsNull = PG_ARGISNULL(3);
2475 
2476 #define TIMETZ_GT(t1,t2) \
2477  DatumGetBool(DirectFunctionCall2(timetz_gt,t1,t2))
2478 #define TIMETZ_LT(t1,t2) \
2479  DatumGetBool(DirectFunctionCall2(timetz_lt,t1,t2))
2480 
2481  /*
2482  * If both endpoints of interval 1 are null, the result is null (unknown).
2483  * If just one endpoint is null, take ts1 as the non-null one. Otherwise,
2484  * take ts1 as the lesser endpoint.
2485  */
2486  if (ts1IsNull)
2487  {
2488  if (te1IsNull)
2489  PG_RETURN_NULL();
2490  /* swap null for non-null */
2491  ts1 = te1;
2492  te1IsNull = true;
2493  }
2494  else if (!te1IsNull)
2495  {
2496  if (TIMETZ_GT(ts1, te1))
2497  {
2498  Datum tt = ts1;
2499 
2500  ts1 = te1;
2501  te1 = tt;
2502  }
2503  }
2504 
2505  /* Likewise for interval 2. */
2506  if (ts2IsNull)
2507  {
2508  if (te2IsNull)
2509  PG_RETURN_NULL();
2510  /* swap null for non-null */
2511  ts2 = te2;
2512  te2IsNull = true;
2513  }
2514  else if (!te2IsNull)
2515  {
2516  if (TIMETZ_GT(ts2, te2))
2517  {
2518  Datum tt = ts2;
2519 
2520  ts2 = te2;
2521  te2 = tt;
2522  }
2523  }
2524 
2525  /*
2526  * At this point neither ts1 nor ts2 is null, so we can consider three
2527  * cases: ts1 > ts2, ts1 < ts2, ts1 = ts2
2528  */
2529  if (TIMETZ_GT(ts1, ts2))
2530  {
2531  /*
2532  * This case is ts1 < te2 OR te1 < te2, which may look redundant but
2533  * in the presence of nulls it's not quite completely so.
2534  */
2535  if (te2IsNull)
2536  PG_RETURN_NULL();
2537  if (TIMETZ_LT(ts1, te2))
2538  PG_RETURN_BOOL(true);
2539  if (te1IsNull)
2540  PG_RETURN_NULL();
2541 
2542  /*
2543  * If te1 is not null then we had ts1 <= te1 above, and we just found
2544  * ts1 >= te2, hence te1 >= te2.
2545  */
2546  PG_RETURN_BOOL(false);
2547  }
2548  else if (TIMETZ_LT(ts1, ts2))
2549  {
2550  /* This case is ts2 < te1 OR te2 < te1 */
2551  if (te1IsNull)
2552  PG_RETURN_NULL();
2553  if (TIMETZ_LT(ts2, te1))
2554  PG_RETURN_BOOL(true);
2555  if (te2IsNull)
2556  PG_RETURN_NULL();
2557 
2558  /*
2559  * If te2 is not null then we had ts2 <= te2 above, and we just found
2560  * ts2 >= te1, hence te2 >= te1.
2561  */
2562  PG_RETURN_BOOL(false);
2563  }
2564  else
2565  {
2566  /*
2567  * For ts1 = ts2 the spec says te1 <> te2 OR te1 = te2, which is a
2568  * rather silly way of saying "true if both are nonnull, else null".
2569  */
2570  if (te1IsNull || te2IsNull)
2571  PG_RETURN_NULL();
2572  PG_RETURN_BOOL(true);
2573  }
2574 
2575 #undef TIMETZ_GT
2576 #undef TIMETZ_LT
2577 }
#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 1312 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().

1313 {
1314  tm->tm_hour = time / USECS_PER_HOUR;
1315  time -= tm->tm_hour * USECS_PER_HOUR;
1316  tm->tm_min = time / USECS_PER_MINUTE;
1317  time -= tm->tm_min * USECS_PER_MINUTE;
1318  tm->tm_sec = time / USECS_PER_SEC;
1319  time -= tm->tm_sec * USECS_PER_SEC;
1320  *fsec = time;
1321  return 0;
1322 }
#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 1558 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_INT32.

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

1559 {
1560  TimeADT time1 = PG_GETARG_TIMEADT(0);
1561  TimeADT time2 = PG_GETARG_TIMEADT(1);
1562 
1563  if (time1 < time2)
1564  PG_RETURN_INT32(-1);
1565  if (time1 > time2)
1566  PG_RETURN_INT32(1);
1567  PG_RETURN_INT32(0);
1568 }
#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 1504 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

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_ge()

Datum time_ge ( PG_FUNCTION_ARGS  )

Definition at line 1549 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

1550 {
1551  TimeADT time1 = PG_GETARG_TIMEADT(0);
1552  TimeADT time2 = PG_GETARG_TIMEADT(1);
1553 
1554  PG_RETURN_BOOL(time1 >= time2);
1555 }
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 1540 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

1541 {
1542  TimeADT time1 = PG_GETARG_TIMEADT(0);
1543  TimeADT time2 = PG_GETARG_TIMEADT(1);
1544 
1545  PG_RETURN_BOOL(time1 > time2);
1546 }
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 1571 of file date.c.

References hashint8().

1572 {
1573  return hashint8(fcinfo);
1574 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1577 of file date.c.

References hashint8extended().

1578 {
1579  return hashint8extended(fcinfo);
1580 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

Definition at line 1201 of file date.c.

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

1202 {
1203  char *str = PG_GETARG_CSTRING(0);
1204 
1205 #ifdef NOT_USED
1206  Oid typelem = PG_GETARG_OID(1);
1207 #endif
1208  int32 typmod = PG_GETARG_INT32(2);
1209  TimeADT result;
1210  fsec_t fsec;
1211  struct pg_tm tt,
1212  *tm = &tt;
1213  int tz;
1214  int nf;
1215  int dterr;
1216  char workbuf[MAXDATELEN + 1];
1217  char *field[MAXDATEFIELDS];
1218  int dtype;
1219  int ftype[MAXDATEFIELDS];
1220 
1221  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1222  field, ftype, MAXDATEFIELDS, &nf);
1223  if (dterr == 0)
1224  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1225  if (dterr != 0)
1226  DateTimeParseError(dterr, str, "time");
1227 
1228  tm2time(tm, fsec, &result);
1229  AdjustTimeForTypmod(&result, typmod);
1230 
1231  PG_RETURN_TIMEADT(result);
1232 }
#define MAXDATELEN
Definition: datetime.h:201
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3768
#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:1754
signed int int32
Definition: c.h:363
static struct pg_tm tm
Definition: localtime.c:102
#define PG_GETARG_OID(n)
Definition: fmgr.h:275
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1238
#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:582
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1813 of file date.c.

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

1814 {
1815  TimeADT time = PG_GETARG_TIMEADT(0);
1816  Interval *result;
1817 
1818  result = (Interval *) palloc(sizeof(Interval));
1819 
1820  result->time = time;
1821  result->day = 0;
1822  result->month = 0;
1823 
1824  PG_RETURN_INTERVAL_P(result);
1825 }
#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:950

◆ time_larger()

Datum time_larger ( PG_FUNCTION_ARGS  )

Definition at line 1583 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1584 {
1585  TimeADT time1 = PG_GETARG_TIMEADT(0);
1586  TimeADT time2 = PG_GETARG_TIMEADT(1);
1587 
1588  PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2);
1589 }
#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 1531 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

1532 {
1533  TimeADT time1 = PG_GETARG_TIMEADT(0);
1534  TimeADT time2 = PG_GETARG_TIMEADT(1);
1535 
1536  PG_RETURN_BOOL(time1 <= time2);
1537 }
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 1522 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

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_mi_interval()

Datum time_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1898 of file date.c.

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

1899 {
1900  TimeADT time = PG_GETARG_TIMEADT(0);
1901  Interval *span = PG_GETARG_INTERVAL_P(1);
1902  TimeADT result;
1903 
1904  result = time - span->time;
1905  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1906  if (result < INT64CONST(0))
1907  result += USECS_PER_DAY;
1908 
1909  PG_RETURN_TIMEADT(result);
1910 }
#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 1861 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().

1862 {
1863  TimeADT time1 = PG_GETARG_TIMEADT(0);
1864  TimeADT time2 = PG_GETARG_TIMEADT(1);
1865  Interval *result;
1866 
1867  result = (Interval *) palloc(sizeof(Interval));
1868 
1869  result->month = 0;
1870  result->day = 0;
1871  result->time = time1 - time2;
1872 
1873  PG_RETURN_INTERVAL_P(result);
1874 }
#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:950

◆ time_ne()

Datum time_ne ( PG_FUNCTION_ARGS  )

Definition at line 1513 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

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_out()

Datum time_out ( PG_FUNCTION_ARGS  )

Definition at line 1325 of file date.c.

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

1326 {
1327  TimeADT time = PG_GETARG_TIMEADT(0);
1328  char *result;
1329  struct pg_tm tt,
1330  *tm = &tt;
1331  fsec_t fsec;
1332  char buf[MAXDATELEN + 1];
1333 
1334  time2tm(time, tm, &fsec);
1335  EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1336 
1337  result = pstrdup(buf);
1338  PG_RETURN_CSTRING(result);
1339 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1187
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3972
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1312
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
static char * buf
Definition: pg_test_fsync.c:68
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361
int DateStyle
Definition: globals.c:115

◆ time_overflows()

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

Definition at line 1249 of file date.c.

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

Referenced by DecodeDateTime(), and DecodeTimeOnly().

1250 {
1251  /* Range-check the fields individually. */
1252  if (hour < 0 || hour > HOURS_PER_DAY ||
1253  min < 0 || min >= MINS_PER_HOUR ||
1254  sec < 0 || sec > SECS_PER_MINUTE ||
1255  fsec < 0 || fsec > USECS_PER_SEC)
1256  return true;
1257 
1258  /*
1259  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1260  * that the total time value doesn't exceed 24:00:00.
1261  */
1262  if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1263  + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1264  return true;
1265 
1266  return false;
1267 }
#define USECS_PER_SEC
Definition: timestamp.h:94
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ time_part()

Datum time_part ( PG_FUNCTION_ARGS  )

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

1957 {
1958  text *units = PG_GETARG_TEXT_PP(0);
1959  TimeADT time = PG_GETARG_TIMEADT(1);
1960  float8 result;
1961  int type,
1962  val;
1963  char *lowunits;
1964 
1965  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
1966  VARSIZE_ANY_EXHDR(units),
1967  false);
1968 
1969  type = DecodeUnits(0, lowunits, &val);
1970  if (type == UNKNOWN_FIELD)
1971  type = DecodeSpecial(0, lowunits, &val);
1972 
1973  if (type == UNITS)
1974  {
1975  fsec_t fsec;
1976  struct pg_tm tt,
1977  *tm = &tt;
1978 
1979  time2tm(time, tm, &fsec);
1980 
1981  switch (val)
1982  {
1983  case DTK_MICROSEC:
1984  result = tm->tm_sec * 1000000.0 + fsec;
1985  break;
1986 
1987  case DTK_MILLISEC:
1988  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
1989  break;
1990 
1991  case DTK_SECOND:
1992  result = tm->tm_sec + fsec / 1000000.0;
1993  break;
1994 
1995  case DTK_MINUTE:
1996  result = tm->tm_min;
1997  break;
1998 
1999  case DTK_HOUR:
2000  result = tm->tm_hour;
2001  break;
2002 
2003  case DTK_TZ:
2004  case DTK_TZ_MINUTE:
2005  case DTK_TZ_HOUR:
2006  case DTK_DAY:
2007  case DTK_MONTH:
2008  case DTK_QUARTER:
2009  case DTK_YEAR:
2010  case DTK_DECADE:
2011  case DTK_CENTURY:
2012  case DTK_MILLENNIUM:
2013  case DTK_ISOYEAR:
2014  default:
2015  ereport(ERROR,
2016  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2017  errmsg("\"time\" units \"%s\" not recognized",
2018  lowunits)));
2019  result = 0;
2020  }
2021  }
2022  else if (type == RESERV && val == DTK_EPOCH)
2023  {
2024  result = time / 1000000.0;
2025  }
2026  else
2027  {
2028  ereport(ERROR,
2029  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2030  errmsg("\"time\" units \"%s\" not recognized",
2031  lowunits)));
2032  result = 0;
2033  }
2034 
2035  PG_RETURN_FLOAT8(result);
2036 }
#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:37
#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:1312
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3731
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:102
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:499
#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:3040
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:821
Definition: c.h:563
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 1880 of file date.c.

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

1881 {
1882  TimeADT time = PG_GETARG_TIMEADT(0);
1883  Interval *span = PG_GETARG_INTERVAL_P(1);
1884  TimeADT result;
1885 
1886  result = time + span->time;
1887  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1888  if (result < INT64CONST(0))
1889  result += USECS_PER_DAY;
1890 
1891  PG_RETURN_TIMEADT(result);
1892 }
#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 1345 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.

1346 {
1348 
1349 #ifdef NOT_USED
1350  Oid typelem = PG_GETARG_OID(1);
1351 #endif
1352  int32 typmod = PG_GETARG_INT32(2);
1353  TimeADT result;
1354 
1355  result = pq_getmsgint64(buf);
1356 
1357  if (result < INT64CONST(0) || result > USECS_PER_DAY)
1358  ereport(ERROR,
1359  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1360  errmsg("time out of range")));
1361 
1362  AdjustTimeForTypmod(&result, typmod);
1363 
1364  PG_RETURN_TIMEADT(result);
1365 }
#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:363
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
#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:821
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1449 of file date.c.

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

1450 {
1451  TimeADT time = PG_GETARG_TIMEADT(0);
1452  int32 typmod = PG_GETARG_INT32(1);
1453  TimeADT result;
1454 
1455  result = time;
1456  AdjustTimeForTypmod(&result, typmod);
1457 
1458  PG_RETURN_TIMEADT(result);
1459 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
signed int int32
Definition: c.h:363
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1371 of file date.c.

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

1372 {
1373  TimeADT time = PG_GETARG_TIMEADT(0);
1375 
1376  pq_begintypsend(&buf);
1377  pq_sendint64(&buf, time);
1379 }
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:68
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 1592 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1593 {
1594  TimeADT time1 = PG_GETARG_TIMEADT(0);
1595  TimeADT time2 = PG_GETARG_TIMEADT(1);
1596 
1597  PG_RETURN_TIMEADT((time1 < time2) ? time1 : time2);
1598 }
#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 1429 of file date.c.

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

1430 {
1431  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1432  Node *ret = NULL;
1433 
1434  if (IsA(rawreq, SupportRequestSimplify))
1435  {
1437 
1438  ret = TemporalSimplify(MAX_TIME_PRECISION, (Node *) req->fcall);
1439  }
1440 
1441  PG_RETURN_POINTER(ret);
1442 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
Definition: nodes.h:528
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
Node * TemporalSimplify(int32 max_precis, Node *node)
Definition: datetime.c:4497
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

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

2595 {
2596  TimeADT time = PG_GETARG_TIMEADT(0);
2597  TimeTzADT *result;
2598  struct pg_tm tt,
2599  *tm = &tt;
2600  fsec_t fsec;
2601  int tz;
2602 
2603  GetCurrentDateTime(tm);
2604  time2tm(time, tm, &fsec);
2606 
2607  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2608 
2609  result->time = time;
2610  result->zone = tz;
2611 
2612  PG_RETURN_TIMETZADT_P(result);
2613 }
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:349
#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:1312
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int32 zone
Definition: date.h:30
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1478
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:950
Definition: date.h:27

◆ timestamp_cmp_date()

Datum timestamp_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 965 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_INT32.

966 {
968  DateADT dateVal = PG_GETARG_DATEADT(1);
969 
971 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

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

1125 {
1127  DateADT result;
1128  struct pg_tm tt,
1129  *tm = &tt;
1130  fsec_t fsec;
1131 
1132  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1133  DATE_NOBEGIN(result);
1134  else if (TIMESTAMP_IS_NOEND(timestamp))
1135  DATE_NOEND(result);
1136  else
1137  {
1138  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1139  ereport(ERROR,
1140  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1141  errmsg("timestamp out of range")));
1142 
1143  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1144  }
1145 
1146  PG_RETURN_DATEADT(result);
1147 }
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:1788
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOBEGIN(j)
Definition: date.h:39
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
int64 Timestamp
Definition: timestamp.h:38
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:821
#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 911 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

912 {
914  DateADT dateVal = PG_GETARG_DATEADT(1);
915 
916  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) == 0);
917 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_ge_date()

Datum timestamp_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 956 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

957 {
959  DateADT dateVal = PG_GETARG_DATEADT(1);
960 
961  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) <= 0);
962 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_gt_date()

Datum timestamp_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 938 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

939 {
941  DateADT dateVal = PG_GETARG_DATEADT(1);
942 
943  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) < 0);
944 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_le_date()

Datum timestamp_le_date ( PG_FUNCTION_ARGS  )

Definition at line 947 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

948 {
950  DateADT dateVal = PG_GETARG_DATEADT(1);
951 
952  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) >= 0);
953 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_lt_date()

Datum timestamp_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 929 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

930 {
932  DateADT dateVal = PG_GETARG_DATEADT(1);
933 
934  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) > 0);
935 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_ne_date()

Datum timestamp_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 920 of file date.c.

References date_cmp_timestamp_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMP, and PG_RETURN_BOOL.

921 {
923  DateADT dateVal = PG_GETARG_DATEADT(1);
924 
925  PG_RETURN_BOOL(date_cmp_timestamp_internal(dateVal, dt1) != 0);
926 }
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
int32 date_cmp_timestamp_internal(DateADT dateVal, Timestamp dt2)
Definition: date.c:747

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

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

1730 {
1732  TimeADT result;
1733  struct pg_tm tt,
1734  *tm = &tt;
1735  fsec_t fsec;
1736 
1737  if (TIMESTAMP_NOT_FINITE(timestamp))
1738  PG_RETURN_NULL();
1739 
1740  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1741  ereport(ERROR,
1742  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1743  errmsg("timestamp out of range")));
1744 
1745  /*
1746  * Could also do this with time = (timestamp / USECS_PER_DAY *
1747  * USECS_PER_DAY) - timestamp;
1748  */
1749  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1750  USECS_PER_SEC) + fsec;
1751 
1752  PG_RETURN_TIMEADT(result);
1753 }
#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:1788
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:102
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
int64 Timestamp
Definition: timestamp.h:38
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:821
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 1028 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_INT32.

1029 {
1031  DateADT dateVal = PG_GETARG_DATEADT(1);
1032 
1034 }
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
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_date()

Datum timestamptz_date ( PG_FUNCTION_ARGS  )

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

1170 {
1172  DateADT result;
1173  struct pg_tm tt,
1174  *tm = &tt;
1175  fsec_t fsec;
1176  int tz;
1177 
1178  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1179  DATE_NOBEGIN(result);
1180  else if (TIMESTAMP_IS_NOEND(timestamp))
1181  DATE_NOEND(result);
1182  else
1183  {
1184  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1185  ereport(ERROR,
1186  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1187  errmsg("timestamp out of range")));
1188 
1189  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1190  }
1191 
1192  PG_RETURN_DATEADT(result);
1193 }
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:1788
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
#define DATE_NOBEGIN(j)
Definition: date.h:39
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
int date2j(int y, int m, int d)
Definition: datetime.c:269
#define ereport(elevel,...)
Definition: elog.h:144
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:821
#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 974 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

975 {
977  DateADT dateVal = PG_GETARG_DATEADT(1);
978 
979  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt1) == 0);
980 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_ge_date()

Datum timestamptz_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 1019 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

1020 {
1022  DateADT dateVal = PG_GETARG_DATEADT(1);
1023 
1024  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt1) <= 0);
1025 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_gt_date()

Datum timestamptz_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 1001 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

1002 {
1004  DateADT dateVal = PG_GETARG_DATEADT(1);
1005 
1006  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt1) < 0);
1007 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_le_date()

Datum timestamptz_le_date ( PG_FUNCTION_ARGS  )

Definition at line 1010 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

1011 {
1013  DateADT dateVal = PG_GETARG_DATEADT(1);
1014 
1015  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt1) >= 0);
1016 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_lt_date()

Datum timestamptz_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 992 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

993 {
995  DateADT dateVal = PG_GETARG_DATEADT(1);
996 
998 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_ne_date()

Datum timestamptz_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 983 of file date.c.

References date_cmp_timestamptz_internal(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, and PG_RETURN_BOOL.

984 {
986  DateADT dateVal = PG_GETARG_DATEADT(1);
987 
988  PG_RETURN_BOOL(date_cmp_timestamptz_internal(dateVal, dt1) != 0);
989 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36
int32 date_cmp_timestamptz_internal(DateADT dateVal, TimestampTz dt2)
Definition: date.c:827

◆ timestamptz_time()

Datum timestamptz_time ( PG_FUNCTION_ARGS  )

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

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

2621 {
2623  TimeTzADT *result;
2624  struct pg_tm tt,
2625  *tm = &tt;
2626  int tz;
2627  fsec_t fsec;
2628 
2629  if (TIMESTAMP_NOT_FINITE(timestamp))
2630  PG_RETURN_NULL();
2631 
2632  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2633  ereport(ERROR,
2634  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2635  errmsg("timestamp out of range")));
2636 
2637  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2638 
2639  tm2timetz(tm, fsec, tz, result);
2640 
2641  PG_RETURN_TIMETZADT_P(result);
2642 }
#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:1788
int errcode(int sqlerrcode)
Definition: elog.c:610
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2047
#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:950
int errmsg(const char *fmt,...)
Definition: elog.c:821
Definition: date.h:27
#define PG_RETURN_NULL()
Definition: fmgr.h:344

◆ timetypmodin()

Datum timetypmodin ( PG_FUNCTION_ARGS  )

Definition at line 1382 of file date.c.

References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

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

◆ timetypmodout()

Datum timetypmodout ( PG_FUNCTION_ARGS  )

Definition at line 1390 of file date.c.

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

1391 {
1392  int32 typmod = PG_GETARG_INT32(0);
1393 
1394  PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1395 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
signed int int32
Definition: c.h:363
static char * anytime_typmodout(bool istz, int32 typmod)
Definition: date.c:90
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:361

◆ timetz2tm()

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

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

2182 {
2183  TimeOffset trem = time->time;
2184 
2185  tm->tm_hour = trem / USECS_PER_HOUR;
2186  trem -= tm->tm_hour * USECS_PER_HOUR;
2187  tm->tm_min = trem / USECS_PER_MINUTE;
2188  trem -= tm->tm_min * USECS_PER_MINUTE;
2189  tm->tm_sec = trem / USECS_PER_SEC;
2190  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2191 
2192  if (tzp != NULL)
2193  *tzp = time->zone;
2194 
2195  return 0;
2196 }
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 2302 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().

Referenced by compareDatetime(), and leftmostvalue_timetz().

2303 {
2304  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2305  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2306 
2307  PG_RETURN_INT32(timetz_cmp_internal(time1, time2));
2308 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 2221 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().

2222 {
2223  TimeOffset t1,
2224  t2;
2225 
2226  /* Primary sort is by true (GMT-equivalent) time */
2227  t1 = time1->time + (time1->zone * USECS_PER_SEC);
2228  t2 = time2->time + (time2->zone * USECS_PER_SEC);
2229 
2230  if (t1 > t2)
2231  return 1;
2232  if (t1 < t2)
2233  return -1;
2234 
2235  /*
2236  * If same GMT time, sort by timezone; we only want to say that two
2237  * timetz's are equal if both the time and zone parts are equal.
2238  */
2239  if (time1->zone > time2->zone)
2240  return 1;
2241  if (time1->zone < time2->zone)
2242  return -1;
2243 
2244  return 0;
2245 }
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 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:2221
#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 2293 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2294 {
2295  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2296  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2297 
2298  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0);
2299 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 2284 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2285 {
2286  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2287  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2288 
2289  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0);
2290 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 2311 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.

2312 {
2314  uint32 thash;
2315 
2316  /*
2317  * To avoid any problems with padding bytes in the struct, we figure the
2318  * field hashes separately and XOR them.
2319  */
2321  Int64GetDatumFast(key->time)));
2322  thash ^= DatumGetUInt32(hash_uint32(key->zone));
2323  PG_RETURN_UINT32(thash);
2324 }
#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:375
#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 2327 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.

2328 {
2330  Datum seed = PG_GETARG_DATUM(1);
2331  uint64 thash;
2332 
2333  /* Same approach as timetz_hash */
2335  Int64GetDatumFast(key->time),
2336  seed));
2338  DatumGetInt64(seed)));
2339  PG_RETURN_UINT64(thash);
2340 }
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 2057 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().

2058 {
2059  char *str = PG_GETARG_CSTRING(0);
2060 
2061 #ifdef NOT_USED
2062  Oid typelem = PG_GETARG_OID(1);
2063 #endif
2064  int32 typmod = PG_GETARG_INT32(2);
2065  TimeTzADT *result;
2066  fsec_t fsec;
2067  struct pg_tm tt,
2068  *tm = &tt;
2069  int tz;
2070  int nf;
2071  int dterr;
2072  char workbuf[MAXDATELEN + 1];
2073  char *field[MAXDATEFIELDS];
2074  int dtype;
2075  int ftype[MAXDATEFIELDS];
2076 
2077  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
2078  field, ftype, MAXDATEFIELDS, &nf);
2079  if (dterr == 0)
2080  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
2081  if (dterr != 0)
2082  DateTimeParseError(dterr, str, "time with time zone");
2083 
2084  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2085  tm2timetz(tm, fsec, tz, result);
2086  AdjustTimeForTypmod(&(result->time), typmod);
2087 
2088  PG_RETURN_TIMETZADT_P(result);
2089 }
#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:3768
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:1754
signed int int32
Definition: c.h:363
static struct pg_tm tm
Definition: localtime.c:102
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2047
#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:950
#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:582
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

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

2876 {
2878  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2879  TimeTzADT *result;
2880  int tz;
2881 
2882  if (zone->month != 0 || zone->day != 0)
2883  ereport(ERROR,
2884  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2885  errmsg("interval time zone \"%s\" must not include months or days",
2887  PointerGetDatum(zone))))));
2888 
2889  tz = -(zone->time / USECS_PER_SEC);
2890 
2891  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2892 
2893  result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2894  while (result->time < INT64CONST(0))
2895  result->time += USECS_PER_DAY;
2896  while (result->time >= USECS_PER_DAY)
2897  result->time -= USECS_PER_DAY;
2898 
2899  result->zone = tz;
2900 
2901  PG_RETURN_TIMETZADT_P(result);
2902 }
#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:956
#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:93
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:821
Definition: date.h:27

◆ timetz_larger()

Datum timetz_larger ( PG_FUNCTION_ARGS  )

Definition at line 2343 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2344 {
2345  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2346  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2347  TimeTzADT *result;
2348 
2349  if (timetz_cmp_internal(time1, time2) > 0)
2350  result = time1;
2351  else
2352  result = time2;
2353  PG_RETURN_TIMETZADT_P(result);
2354 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 2275 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2276 {
2277  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2278  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2279 
2280  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0);
2281 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 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:2221
#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 2396 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.

2397 {
2398  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2399  Interval *span = PG_GETARG_INTERVAL_P(1);
2400  TimeTzADT *result;
2401 
2402  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2403 
2404  result->time = time->time - span->time;
2405  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2406  if (result->time < INT64CONST(0))
2407  result->time += USECS_PER_DAY;
2408 
2409  result->zone = time->zone;
2410 
2411  PG_RETURN_TIMETZADT_P(result);
2412 }
#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:950
Definition: date.h:27

◆ timetz_ne()

Datum timetz_ne ( 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:2221
#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 2092 of file date.c.

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

2093 {
2094  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2095  char *result;
2096  struct pg_tm tt,
2097  *tm = &tt;
2098  fsec_t fsec;
2099  int tz;
2100  char buf[MAXDATELEN + 1];
2101 
2102  timetz2tm(time, tm, &fsec, &tz);
2103  EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2104 
2105  result = pstrdup(buf);
2106  PG_RETURN_CSTRING(result);
2107 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1187
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3972
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:102
static char * buf
Definition: pg_test_fsync.c:68
#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:2181
#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 2693 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.

2694 {
2695  text *units = PG_GETARG_TEXT_PP(0);
2696  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2697  float8 result;
2698  int type,
2699  val;
2700  char *lowunits;
2701 
2702  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
2703  VARSIZE_ANY_EXHDR(units),
2704  false);
2705 
2706  type = DecodeUnits(0, lowunits, &val);
2707  if (type == UNKNOWN_FIELD)
2708  type = DecodeSpecial(0, lowunits, &val);
2709 
2710  if (type == UNITS)
2711  {
2712  double dummy;
2713  int tz;
2714  fsec_t fsec;
2715  struct pg_tm tt,
2716  *tm = &tt;
2717 
2718  timetz2tm(time, tm, &fsec, &tz);
2719 
2720  switch (val)
2721  {
2722  case DTK_TZ:
2723  result = -tz;
2724  break;
2725 
2726  case DTK_TZ_MINUTE:
2727  result = -tz;
2728  result /= SECS_PER_MINUTE;
2729  FMODULO(result, dummy, (double) SECS_PER_MINUTE);
2730  break;
2731 
2732  case DTK_TZ_HOUR:
2733  dummy = -tz;
2734  FMODULO(dummy, result, (double) SECS_PER_HOUR);
2735  break;
2736 
2737  case DTK_MICROSEC:
2738  result = tm->tm_sec * 1000000.0 + fsec;
2739  break;
2740 
2741  case DTK_MILLISEC:
2742  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2743  break;
2744 
2745  case DTK_SECOND:
2746  result = tm->tm_sec + fsec / 1000000.0;
2747  break;
2748 
2749  case DTK_MINUTE:
2750  result = tm->tm_min;
2751  break;
2752 
2753  case DTK_HOUR:
2754  result = tm->tm_hour;
2755  break;
2756 
2757  case DTK_DAY:
2758  case DTK_MONTH:
2759  case DTK_QUARTER:
2760  case DTK_YEAR:
2761  case DTK_DECADE:
2762  case DTK_CENTURY:
2763  case DTK_MILLENNIUM:
2764  default:
2765  ereport(ERROR,
2766  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2767  errmsg("\"time with time zone\" units \"%s\" not recognized",
2768  lowunits)));
2769  result = 0;
2770  }
2771  }
2772  else if (type == RESERV && val == DTK_EPOCH)
2773  {
2774  result = time->time / 1000000.0 + time->zone;
2775  }
2776  else
2777  {
2778  ereport(ERROR,
2779  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2780  errmsg("\"time with time zone\" units \"%s\" not recognized",
2781  lowunits)));
2782  result = 0;
2783  }
2784 
2785  PG_RETURN_FLOAT8(result);
2786 }
#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:37
#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:3731
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
static struct pg_tm tm
Definition: localtime.c:102
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:499
#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:2181
#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:3040
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:821
Definition: c.h:563
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 2374 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.

2375 {
2376  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2377  Interval *span = PG_GETARG_INTERVAL_P(1);
2378  TimeTzADT *result;
2379 
2380  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2381 
2382  result->time = time->time + span->time;
2383  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2384  if (result->time < INT64CONST(0))
2385  result->time += USECS_PER_DAY;
2386 
2387  result->zone = time->zone;
2388 
2389  PG_RETURN_TIMETZADT_P(result);
2390 }
#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:950
Definition: date.h:27

◆ timetz_recv()

Datum timetz_recv ( PG_FUNCTION_ARGS  )

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

2114 {
2116 
2117 #ifdef NOT_USED
2118  Oid typelem = PG_GETARG_OID(1);
2119 #endif
2120  int32 typmod = PG_GETARG_INT32(2);
2121  TimeTzADT *result;
2122 
2123  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2124 
2125  result->time = pq_getmsgint64(buf);
2126 
2127  if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2128  ereport(ERROR,
2129  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2130  errmsg("time out of range")));
2131 
2132  result->zone = pq_getmsgint(buf, sizeof(result->zone));
2133 
2134  /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2135  if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2136  ereport(ERROR,
2137  (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
2138  errmsg("time zone displacement out of range")));
2139 
2140  AdjustTimeForTypmod(&(result->time), typmod);
2141 
2142  PG_RETURN_TIMETZADT_P(result);
2143 }
#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:363
#define ERROR
Definition: elog.h:43
int32 zone
Definition: date.h:30
static char * buf
Definition: pg_test_fsync.c:68
#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:950
int errmsg(const char *fmt,...)
Definition: elog.c:821
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:1469

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2203 of file date.c.

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

2204 {
2205  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2206  int32 typmod = PG_GETARG_INT32(1);
2207  TimeTzADT *result;
2208 
2209  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2210 
2211  result->time = time->time;
2212  result->zone = time->zone;
2213 
2214  AdjustTimeForTypmod(&(result->time), typmod);
2215 
2216  PG_RETURN_TIMETZADT_P(result);
2217 }
#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:363
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
void * palloc(Size size)
Definition: mcxt.c:950
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1469

◆ timetz_send()

Datum timetz_send ( PG_FUNCTION_ARGS  )

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

2150 {
2151  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2153 
2154  pq_begintypsend(&buf);
2155  pq_sendint64(&buf, time->time);
2156  pq_sendint32(&buf, time->zone);
2158 }
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:68
#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 2357 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2358 {
2359  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2360  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2361  TimeTzADT *result;
2362 
2363  if (timetz_cmp_internal(time1, time2) < 0)
2364  result = time1;
2365  else
2366  result = time2;
2367  PG_RETURN_TIMETZADT_P(result);
2368 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2221
#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 2581 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and TimeTzADT::time.

2582 {
2583  TimeTzADT *timetz = PG_GETARG_TIMETZADT_P(0);
2584  TimeADT result;
2585 
2586  /* swallow the time zone and just return the time */
2587  result = timetz->time;
2588 
2589  PG_RETURN_TIMEADT(result);
2590 }
TimeADT time
Definition: date.h:29
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
int64 TimeADT
Definition: date.h:25
Definition: date.h:27

◆ timetz_zone()