PostgreSQL Source Code  git master
date.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <float.h>
#include <time.h>
#include "access/xact.h"
#include "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/hashutils.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_error (DateADT dateVal, bool *have_error)
 
static TimestampTz date2timestamp (DateADT dateVal)
 
TimestampTz date2timestamptz_opt_error (DateADT dateVal, bool *have_error)
 
static TimestampTz date2timestamptz (DateADT dateVal)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
Datum date_eq_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamp (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamp (PG_FUNCTION_ARGS)
 
Datum date_le_timestamp (PG_FUNCTION_ARGS)
 
Datum date_ge_timestamp (PG_FUNCTION_ARGS)
 
Datum date_cmp_timestamp (PG_FUNCTION_ARGS)
 
Datum date_eq_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_ne_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_lt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_gt_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_le_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_ge_timestamptz (PG_FUNCTION_ARGS)
 
Datum date_cmp_timestamptz (PG_FUNCTION_ARGS)
 
Datum timestamp_eq_date (PG_FUNCTION_ARGS)
 
Datum timestamp_ne_date (PG_FUNCTION_ARGS)
 
Datum timestamp_lt_date (PG_FUNCTION_ARGS)
 
Datum timestamp_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamp_le_date (PG_FUNCTION_ARGS)
 
Datum timestamp_ge_date (PG_FUNCTION_ARGS)
 
Datum timestamp_cmp_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_eq_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_ne_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_lt_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_gt_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_le_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_ge_date (PG_FUNCTION_ARGS)
 
Datum timestamptz_cmp_date (PG_FUNCTION_ARGS)
 
Datum in_range_date_interval (PG_FUNCTION_ARGS)
 
Datum date_pl_interval (PG_FUNCTION_ARGS)
 
Datum date_mi_interval (PG_FUNCTION_ARGS)
 
Datum date_timestamp (PG_FUNCTION_ARGS)
 
Datum timestamp_date (PG_FUNCTION_ARGS)
 
Datum date_timestamptz (PG_FUNCTION_ARGS)
 
Datum timestamptz_date (PG_FUNCTION_ARGS)
 
Datum time_in (PG_FUNCTION_ARGS)
 
int tm2time (struct pg_tm *tm, fsec_t fsec, TimeADT *result)
 
int time2tm (TimeADT time, struct pg_tm *tm, fsec_t *fsec)
 
Datum time_out (PG_FUNCTION_ARGS)
 
Datum time_recv (PG_FUNCTION_ARGS)
 
Datum time_send (PG_FUNCTION_ARGS)
 
Datum timetypmodin (PG_FUNCTION_ARGS)
 
Datum timetypmodout (PG_FUNCTION_ARGS)
 
Datum make_time (PG_FUNCTION_ARGS)
 
Datum time_support (PG_FUNCTION_ARGS)
 
Datum time_scale (PG_FUNCTION_ARGS)
 
void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 
Datum time_eq (PG_FUNCTION_ARGS)
 
Datum time_ne (PG_FUNCTION_ARGS)
 
Datum time_lt (PG_FUNCTION_ARGS)
 
Datum time_le (PG_FUNCTION_ARGS)
 
Datum time_gt (PG_FUNCTION_ARGS)
 
Datum time_ge (PG_FUNCTION_ARGS)
 
Datum time_cmp (PG_FUNCTION_ARGS)
 
Datum time_hash (PG_FUNCTION_ARGS)
 
Datum time_hash_extended (PG_FUNCTION_ARGS)
 
Datum time_larger (PG_FUNCTION_ARGS)
 
Datum time_smaller (PG_FUNCTION_ARGS)
 
Datum overlaps_time (PG_FUNCTION_ARGS)
 
Datum timestamp_time (PG_FUNCTION_ARGS)
 
Datum timestamptz_time (PG_FUNCTION_ARGS)
 
Datum datetime_timestamp (PG_FUNCTION_ARGS)
 
Datum time_interval (PG_FUNCTION_ARGS)
 
Datum interval_time (PG_FUNCTION_ARGS)
 
Datum time_mi_time (PG_FUNCTION_ARGS)
 
Datum time_pl_interval (PG_FUNCTION_ARGS)
 
Datum time_mi_interval (PG_FUNCTION_ARGS)
 
Datum in_range_time_interval (PG_FUNCTION_ARGS)
 
Datum time_part (PG_FUNCTION_ARGS)
 
int tm2timetz (struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
 
Datum timetz_in (PG_FUNCTION_ARGS)
 
Datum timetz_out (PG_FUNCTION_ARGS)
 
Datum timetz_recv (PG_FUNCTION_ARGS)
 
Datum timetz_send (PG_FUNCTION_ARGS)
 
Datum timetztypmodin (PG_FUNCTION_ARGS)
 
Datum timetztypmodout (PG_FUNCTION_ARGS)
 
int timetz2tm (TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
 
Datum timetz_scale (PG_FUNCTION_ARGS)
 
static int timetz_cmp_internal (TimeTzADT *time1, TimeTzADT *time2)
 
Datum timetz_eq (PG_FUNCTION_ARGS)
 
Datum timetz_ne (PG_FUNCTION_ARGS)
 
Datum timetz_lt (PG_FUNCTION_ARGS)
 
Datum timetz_le (PG_FUNCTION_ARGS)
 
Datum timetz_gt (PG_FUNCTION_ARGS)
 
Datum timetz_ge (PG_FUNCTION_ARGS)
 
Datum timetz_cmp (PG_FUNCTION_ARGS)
 
Datum timetz_hash (PG_FUNCTION_ARGS)
 
Datum timetz_hash_extended (PG_FUNCTION_ARGS)
 
Datum timetz_larger (PG_FUNCTION_ARGS)
 
Datum timetz_smaller (PG_FUNCTION_ARGS)
 
Datum timetz_pl_interval (PG_FUNCTION_ARGS)
 
Datum timetz_mi_interval (PG_FUNCTION_ARGS)
 
Datum in_range_timetz_interval (PG_FUNCTION_ARGS)
 
Datum overlaps_timetz (PG_FUNCTION_ARGS)
 
Datum timetz_time (PG_FUNCTION_ARGS)
 
Datum time_timetz (PG_FUNCTION_ARGS)
 
Datum timestamptz_timetz (PG_FUNCTION_ARGS)
 
Datum datetimetz_timestamptz (PG_FUNCTION_ARGS)
 
Datum timetz_part (PG_FUNCTION_ARGS)
 
Datum timetz_zone (PG_FUNCTION_ARGS)
 
Datum timetz_izone (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ TIMEADT_GT

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

Referenced by overlaps_time().

◆ TIMEADT_LT

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

Referenced by overlaps_time().

◆ TIMETZ_GT

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

Referenced by overlaps_timetz().

◆ TIMETZ_LT

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

Referenced by overlaps_timetz().

Function Documentation

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)

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

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

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 67 of file date.c.

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

Referenced by anytime_typmodin(), and transformSQLValueFunction().

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

◆ anytime_typmodin()

static int32 anytime_typmodin ( bool  istz,
ArrayType ta 
)
static

Definition at line 46 of file date.c.

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

Referenced by timetypmodin(), and timetztypmodin().

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

◆ anytime_typmodout()

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

Definition at line 89 of file date.c.

References psprintf().

Referenced by timetypmodout(), and timetztypmodout().

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

◆ date2timestamp()

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 699 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

700 {
701  double result;
702 
703  if (DATE_IS_NOBEGIN(dateVal))
704  result = -DBL_MAX;
705  else if (DATE_IS_NOEND(dateVal))
706  result = DBL_MAX;
707  else
708  {
709  /* date is days since 2000, timestamp is microseconds since same... */
710  result = dateVal * (double) USECS_PER_DAY;
711  }
712 
713  return result;
714 }
#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_error()

Timestamp date2timestamp_opt_error ( DateADT  dateVal,
bool have_error 
)

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

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

◆ date2timestamptz()

◆ date2timestamptz_opt_error()

TimestampTz date2timestamptz_opt_error ( DateADT  dateVal,
bool have_error 
)

Definition at line 614 of file date.c.

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

Referenced by compareDatetime(), and date2timestamptz().

615 {
616  TimestampTz result;
617  struct pg_tm tt,
618  *tm = &tt;
619  int tz;
620 
621  if (DATE_IS_NOBEGIN(dateVal))
622  TIMESTAMP_NOBEGIN(result);
623  else if (DATE_IS_NOEND(dateVal))
624  TIMESTAMP_NOEND(result);
625  else
626  {
627  /*
628  * Date's range is wider than timestamp's, so check for boundaries.
629  * Since dates have the same minimum values as timestamps, only upper
630  * boundary need be checked for overflow.
631  */
632  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
633  {
634  if (have_error)
635  {
636  *have_error = true;
637  return (TimestampTz) 0;
638  }
639  else
640  {
641  ereport(ERROR,
642  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
643  errmsg("date out of range for timestamp")));
644  }
645  }
646 
647  j2date(dateVal + POSTGRES_EPOCH_JDATE,
648  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
649  tm->tm_hour = 0;
650  tm->tm_min = 0;
651  tm->tm_sec = 0;
653 
654  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
655 
656  /*
657  * Since it is possible to go beyond allowed timestamptz range because
658  * of time zone, check for allowed timestamp range after adding tz.
659  */
660  if (!IS_VALID_TIMESTAMP(result))
661  {
662  if (have_error)
663  {
664  *have_error = true;
665  return (TimestampTz) 0;
666  }
667  else
668  {
669  ereport(ERROR,
670  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
671  errmsg("date out of range for timestamp")));
672  }
673  }
674  }
675 
676  return result;
677 }
#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:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1441
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:141
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:295
#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:784
#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:344
#define PG_GETARG_DATEADT(n)
Definition: date.h:61

◆ date_cmp_timestamp()

Datum date_cmp_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 794 of file date.c.

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

795 {
796  DateADT dateVal = PG_GETARG_DATEADT(0);
798  Timestamp dt1;
799 
800  dt1 = date2timestamp(dateVal);
801 
803 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_cmp_timestamptz()

Datum date_cmp_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 878 of file date.c.

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

879 {
880  DateADT dateVal = PG_GETARG_DATEADT(0);
882  TimestampTz dt1;
883 
884  dt1 = date2timestamptz(dateVal);
885 
887 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:683
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_eq()

Datum date_eq ( PG_FUNCTION_ARGS  )

Definition at line 374 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dateeq().

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

◆ date_eq_timestamp()

Datum date_eq_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 722 of file date.c.

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

723 {
724  DateADT dateVal = PG_GETARG_DATEADT(0);
726  Timestamp dt1;
727 
728  dt1 = date2timestamp(dateVal);
729 
730  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
731 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_eq_timestamptz()

Datum date_eq_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 806 of file date.c.

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

807 {
808  DateADT dateVal = PG_GETARG_DATEADT(0);
810  TimestampTz dt1;
811 
812  dt1 = date2timestamptz(dateVal);
813 
815 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_fastcmp()

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

Definition at line 441 of file date.c.

References DatumGetDateADT.

Referenced by date_sortsupport().

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

◆ date_finite()

Datum date_finite ( PG_FUNCTION_ARGS  )

Definition at line 463 of file date.c.

References DATE_NOT_FINITE, PG_GETARG_DATEADT, and PG_RETURN_BOOL.

464 {
466 
468 }
int32 DateADT
Definition: date.h:23
long date
Definition: pgtypes_date.h:9
#define DATE_NOT_FINITE(j)
Definition: date.h:43
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ 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:349

◆ date_ge_timestamp()

Datum date_ge_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 782 of file date.c.

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

783 {
784  DateADT dateVal = PG_GETARG_DATEADT(0);
786  Timestamp dt1;
787 
788  dt1 = date2timestamp(dateVal);
789 
790  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
791 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_ge_timestamptz()

Datum date_ge_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 866 of file date.c.

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

867 {
868  DateADT dateVal = PG_GETARG_DATEADT(0);
870  TimestampTz dt1;
871 
872  dt1 = date2timestamptz(dateVal);
873 
875 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_gt()

Datum date_gt ( PG_FUNCTION_ARGS  )

Definition at line 410 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_dategt().

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

◆ date_gt_timestamp()

Datum date_gt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 758 of file date.c.

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

759 {
760  DateADT dateVal = PG_GETARG_DATEADT(0);
762  Timestamp dt1;
763 
764  dt1 = date2timestamp(dateVal);
765 
766  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
767 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_gt_timestamptz()

Datum date_gt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 842 of file date.c.

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

843 {
844  DateADT dateVal = PG_GETARG_DATEADT(0);
846  TimestampTz dt1;
847 
848  dt1 = date2timestamptz(dateVal);
849 
851 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_in()

Datum date_in ( PG_FUNCTION_ARGS  )

Definition at line 109 of file date.c.

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

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

◆ date_le_timestamp()

Datum date_le_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 770 of file date.c.

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

771 {
772  DateADT dateVal = PG_GETARG_DATEADT(0);
774  Timestamp dt1;
775 
776  dt1 = date2timestamp(dateVal);
777 
778  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
779 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_le_timestamptz()

Datum date_le_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 854 of file date.c.

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

855 {
856  DateADT dateVal = PG_GETARG_DATEADT(0);
858  TimestampTz dt1;
859 
860  dt1 = date2timestamptz(dateVal);
861 
863 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_lt()

Datum date_lt ( PG_FUNCTION_ARGS  )

Definition at line 392 of file date.c.

References PG_GETARG_DATEADT, and PG_RETURN_BOOL.

Referenced by gbt_datelt().

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

◆ date_lt_timestamp()

Datum date_lt_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 746 of file date.c.

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

747 {
748  DateADT dateVal = PG_GETARG_DATEADT(0);
750  Timestamp dt1;
751 
752  dt1 = date2timestamp(dateVal);
753 
754  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
755 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_lt_timestamptz()

Datum date_lt_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 830 of file date.c.

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

831 {
832  DateADT dateVal = PG_GETARG_DATEADT(0);
834  TimestampTz dt1;
835 
836  dt1 = date2timestamptz(dateVal);
837 
839 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_mi()

Datum date_mi ( PG_FUNCTION_ARGS  )

Definition at line 491 of file date.c.

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

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

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

◆ date_mi_interval()

Datum date_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1113 of file date.c.

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

1114 {
1115  DateADT dateVal = PG_GETARG_DATEADT(0);
1116  Interval *span = PG_GETARG_INTERVAL_P(1);
1117  Timestamp dateStamp;
1118 
1119  dateStamp = date2timestamp(dateVal);
1120 
1122  TimestampGetDatum(dateStamp),
1123  PointerGetDatum(span));
1124 }
#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:2910
#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:602
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:619

◆ 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:264
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:570
signed int int32
Definition: c.h:346
#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:69
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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:349

◆ date_ne_timestamp()

Datum date_ne_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 734 of file date.c.

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

735 {
736  DateADT dateVal = PG_GETARG_DATEADT(0);
738  Timestamp dt1;
739 
740  dt1 = date2timestamp(dateVal);
741 
742  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
743 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ date_ne_timestamptz()

Datum date_ne_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 818 of file date.c.

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

819 {
820  DateADT dateVal = PG_GETARG_DATEADT(0);
822  TimestampTz dt1;
823 
824  dt1 = date2timestamptz(dateVal);
825 
827 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ date_out()

Datum date_out ( PG_FUNCTION_ARGS  )

Definition at line 174 of file date.c.

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

175 {
177  char *result;
178  struct pg_tm tt,
179  *tm = &tt;
180  char buf[MAXDATELEN + 1];
181 
182  if (DATE_NOT_FINITE(date))
183  EncodeSpecialDate(date, buf);
184  else
185  {
187  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
188  EncodeDateOnly(tm, DateStyle, buf);
189  }
190 
191  result = pstrdup(buf);
192  PG_RETURN_CSTRING(result);
193 }
#define MAXDATELEN
Definition: datetime.h:201
void EncodeDateOnly(struct pg_tm *tm, int style, char *str)
Definition: datetime.c:3858
int32 DateADT
Definition: date.h:23
char * pstrdup(const char *in)
Definition: mcxt.c:1186
long date
Definition: pgtypes_date.h:9
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define DATE_NOT_FINITE(j)
Definition: date.h:43
int tm_mday
Definition: pgtime.h:30
static char * buf
Definition: pg_test_fsync.c:68
int tm_mon
Definition: pgtime.h:31
void EncodeSpecialDate(DateADT dt, char *str)
Definition: date.c:284
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:295
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
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 1093 of file date.c.

References date2timestamp(), DirectFunctionCall2, PG_GETARG_DATEADT, PG_GETARG_INTERVAL_P, PointerGetDatum, timestamp_pl_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_pl_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:2831
#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:602
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:619

◆ 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:264
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:570
signed int int32
Definition: c.h:346
#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:69
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_recv()

Datum date_recv ( PG_FUNCTION_ARGS  )

Definition at line 199 of file date.c.

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

200 {
202  DateADT result;
203 
204  result = (DateADT) pq_getmsgint(buf, sizeof(DateADT));
205 
206  /* Limit to the same range that date_in() accepts. */
207  if (DATE_NOT_FINITE(result))
208  /* ok */ ;
209  else if (!IS_VALID_DATE(result))
210  ereport(ERROR,
211  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
212  errmsg("date out of range")));
213 
214  PG_RETURN_DATEADT(result);
215 }
int32 DateADT
Definition: date.h:23
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#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, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:417
#define PG_RETURN_DATEADT(x)
Definition: date.h:65

◆ date_send()

Datum date_send ( PG_FUNCTION_ARGS  )

Definition at line 221 of file date.c.

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

222 {
225 
226  pq_begintypsend(&buf);
227  pq_sendint32(&buf, date);
229 }
int32 DateADT
Definition: date.h:23
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
long date
Definition: pgtypes_date.h:9
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
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:271
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:339

◆ date_timestamp()

Datum date_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 1130 of file date.c.

References date2timestamp(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1131 {
1132  DateADT dateVal = PG_GETARG_DATEADT(0);
1133  Timestamp result;
1134 
1135  result = date2timestamp(dateVal);
1136 
1137  PG_RETURN_TIMESTAMP(result);
1138 }
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:602

◆ date_timestamptz()

Datum date_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 1174 of file date.c.

References date2timestamptz(), PG_GETARG_DATEADT, and PG_RETURN_TIMESTAMP.

1175 {
1176  DateADT dateVal = PG_GETARG_DATEADT(0);
1177  TimestampTz result;
1178 
1179  result = date2timestamptz(dateVal);
1180 
1181  PG_RETURN_TIMESTAMP(result);
1182 }
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:683
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39

◆ datetime_timestamp()

Datum datetime_timestamp ( PG_FUNCTION_ARGS  )

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

1756 {
1758  TimeADT time = PG_GETARG_TIMEADT(1);
1759  Timestamp result;
1760 
1761  result = date2timestamp(date);
1762  if (!TIMESTAMP_NOT_FINITE(result))
1763  {
1764  result += time;
1765  if (!IS_VALID_TIMESTAMP(result))
1766  ereport(ERROR,
1767  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1768  errmsg("timestamp out of range")));
1769  }
1770 
1771  PG_RETURN_TIMESTAMP(result);
1772 }
int32 DateADT
Definition: date.h:23
int errcode(int sqlerrcode)
Definition: elog.c:570
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 ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
#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:784
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ datetimetz_timestamptz()

Datum datetimetz_timestamptz ( PG_FUNCTION_ARGS  )

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

2618 {
2620  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2621  TimestampTz result;
2622 
2623  if (DATE_IS_NOBEGIN(date))
2624  TIMESTAMP_NOBEGIN(result);
2625  else if (DATE_IS_NOEND(date))
2626  TIMESTAMP_NOEND(result);
2627  else
2628  {
2629  /*
2630  * Date's range is wider than timestamp's, so check for boundaries.
2631  * Since dates have the same minimum values as timestamps, only upper
2632  * boundary need be checked for overflow.
2633  */
2635  ereport(ERROR,
2636  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2637  errmsg("date out of range for timestamp")));
2638  result = date * USECS_PER_DAY + time->time + time->zone * USECS_PER_SEC;
2639 
2640  /*
2641  * Since it is possible to go beyond allowed timestamptz range because
2642  * of time zone, check for allowed timestamp range after adding tz.
2643  */
2644  if (!IS_VALID_TIMESTAMP(result))
2645  ereport(ERROR,
2646  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2647  errmsg("date out of range for timestamp")));
2648  }
2649 
2650  PG_RETURN_TIMESTAMP(result);
2651 }
#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:570
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 ereport(elevel, rest)
Definition: elog.h:141
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
#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:784
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163
Definition: date.h:27

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 284 of file date.c.

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

Referenced by date_out(), and JsonEncodeDateTime().

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

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 299 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

300 {
301  TimestampTz ts;
302  struct pg_tm tt,
303  *tm = &tt;
304  fsec_t fsec;
305  int tz;
306 
308 
309  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
310  ereport(ERROR,
311  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
312  errmsg("timestamp out of range")));
313 
314  return date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
315 }
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:783
int date2j(int y, int m, int d)
Definition: datetime.c:270
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:163

◆ GetSQLCurrentTime()

TimeTzADT* GetSQLCurrentTime ( int32  typmod)

Definition at line 321 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

322 {
323  TimeTzADT *result;
324  TimestampTz ts;
325  struct pg_tm tt,
326  *tm = &tt;
327  fsec_t fsec;
328  int tz;
329 
331 
332  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
333  ereport(ERROR,
334  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
335  errmsg("timestamp out of range")));
336 
337  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
338  tm2timetz(tm, fsec, tz, result);
339  AdjustTimeForTypmod(&(result->time), typmod);
340  return result;
341 }
TimeADT time
Definition: date.h:29
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2012
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:783
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 347 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

348 {
349  TimeADT result;
350  TimestampTz ts;
351  struct pg_tm tt,
352  *tm = &tt;
353  fsec_t fsec;
354  int tz;
355 
357 
358  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
359  ereport(ERROR,
360  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
361  errmsg("timestamp out of range")));
362 
363  tm2time(tm, fsec, &result);
364  AdjustTimeForTypmod(&result, typmod);
365  return result;
366 }
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define ereport(elevel, rest)
Definition: elog.h:141
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:783
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1258
int errmsg(const char *fmt,...)
Definition: elog.c:784
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ in_range_date_interval()

Datum in_range_date_interval ( PG_FUNCTION_ARGS  )

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

1065 {
1067  DateADT base = PG_GETARG_DATEADT(1);
1068  Interval *offset = PG_GETARG_INTERVAL_P(2);
1069  bool sub = PG_GETARG_BOOL(3);
1070  bool less = PG_GETARG_BOOL(4);
1071  Timestamp valStamp;
1072  Timestamp baseStamp;
1073 
1074  valStamp = date2timestamp(val);
1075  baseStamp = date2timestamp(base);
1076 
1078  TimestampGetDatum(valStamp),
1079  TimestampGetDatum(baseStamp),
1080  IntervalPGetDatum(offset),
1081  BoolGetDatum(sub),
1082  BoolGetDatum(less));
1083 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int32 DateADT
Definition: date.h:23
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
#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:625
int64 Timestamp
Definition: timestamp.h:38
#define BoolGetDatum(X)
Definition: postgres.h:402
Datum in_range_timestamp_interval(PG_FUNCTION_ARGS)
Definition: timestamp.c:3339
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602
long val
Definition: informix.c:684

◆ in_range_time_interval()

Datum in_range_time_interval ( PG_FUNCTION_ARGS  )

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

1882 {
1884  TimeADT base = PG_GETARG_TIMEADT(1);
1885  Interval *offset = PG_GETARG_INTERVAL_P(2);
1886  bool sub = PG_GETARG_BOOL(3);
1887  bool less = PG_GETARG_BOOL(4);
1888  TimeADT sum;
1889 
1890  /*
1891  * Like time_pl_interval/time_mi_interval, we disregard the month and day
1892  * fields of the offset. So our test for negative should too.
1893  */
1894  if (offset->time < 0)
1895  ereport(ERROR,
1896  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
1897  errmsg("invalid preceding or following size in window function")));
1898 
1899  /*
1900  * We can't use time_pl_interval/time_mi_interval here, because their
1901  * wraparound behavior would give wrong (or at least undesirable) answers.
1902  * Fortunately the equivalent non-wrapping behavior is trivial, especially
1903  * since we don't worry about integer overflow.
1904  */
1905  if (sub)
1906  sum = base - offset->time;
1907  else
1908  sum = base + offset->time;
1909 
1910  if (less)
1911  PG_RETURN_BOOL(val <= sum);
1912  else
1913  PG_RETURN_BOOL(val >= sum);
1914 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
#define ERROR
Definition: elog.h:43
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
#define ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
int errmsg(const char *fmt,...)
Definition: elog.c:784
long val
Definition: informix.c:684

◆ in_range_timetz_interval()

Datum in_range_timetz_interval ( PG_FUNCTION_ARGS  )

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

2384 {
2386  TimeTzADT *base = PG_GETARG_TIMETZADT_P(1);
2387  Interval *offset = PG_GETARG_INTERVAL_P(2);
2388  bool sub = PG_GETARG_BOOL(3);
2389  bool less = PG_GETARG_BOOL(4);
2390  TimeTzADT sum;
2391 
2392  /*
2393  * Like timetz_pl_interval/timetz_mi_interval, we disregard the month and
2394  * day fields of the offset. So our test for negative should too.
2395  */
2396  if (offset->time < 0)
2397  ereport(ERROR,
2398  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
2399  errmsg("invalid preceding or following size in window function")));
2400 
2401  /*
2402  * We can't use timetz_pl_interval/timetz_mi_interval here, because their
2403  * wraparound behavior would give wrong (or at least undesirable) answers.
2404  * Fortunately the equivalent non-wrapping behavior is trivial, especially
2405  * since we don't worry about integer overflow.
2406  */
2407  if (sub)
2408  sum.time = base->time - offset->time;
2409  else
2410  sum.time = base->time + offset->time;
2411  sum.zone = base->zone;
2412 
2413  if (less)
2414  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) <= 0);
2415  else
2416  PG_RETURN_BOOL(timetz_cmp_internal(val, &sum) >= 0);
2417 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
TimeADT time
Definition: date.h:29
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#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 ereport(elevel, rest)
Definition: elog.h:141
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: date.h:27
long val
Definition: informix.c:684

◆ interval_time()

Datum interval_time ( PG_FUNCTION_ARGS  )

Definition at line 1801 of file date.c.

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

1802 {
1803  Interval *span = PG_GETARG_INTERVAL_P(0);
1804  TimeADT result;
1805  int64 days;
1806 
1807  result = span->time;
1808  if (result >= USECS_PER_DAY)
1809  {
1810  days = result / USECS_PER_DAY;
1811  result -= days * USECS_PER_DAY;
1812  }
1813  else if (result < 0)
1814  {
1815  days = (-result + USECS_PER_DAY - 1) / USECS_PER_DAY;
1816  result += days * USECS_PER_DAY;
1817  }
1818 
1819  PG_RETURN_TIMEADT(result);
1820 }
#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:69
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91

◆ make_date()

Datum make_date ( PG_FUNCTION_ARGS  )

Definition at line 235 of file date.c.

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

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

◆ make_time()

Datum make_time ( PG_FUNCTION_ARGS  )

Definition at line 1362 of file date.c.

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

1363 {
1364  int tm_hour = PG_GETARG_INT32(0);
1365  int tm_min = PG_GETARG_INT32(1);
1366  double sec = PG_GETARG_FLOAT8(2);
1367  TimeADT time;
1368 
1369  /* This should match the checks in DecodeTimeOnly */
1370  if (tm_hour < 0 || tm_min < 0 || tm_min > MINS_PER_HOUR - 1 ||
1371  sec < 0 || sec > SECS_PER_MINUTE ||
1372  tm_hour > HOURS_PER_DAY ||
1373  /* test for > 24:00:00 */
1374  (tm_hour == HOURS_PER_DAY && (tm_min > 0 || sec > 0)))
1375  ereport(ERROR,
1376  (errcode(ERRCODE_DATETIME_FIELD_OVERFLOW),
1377  errmsg("time field value out of range: %d:%02d:%02g",
1378  tm_hour, tm_min, sec)));
1379 
1380  /* This should match tm2time */
1381  time = (((tm_hour * MINS_PER_HOUR + tm_min) * SECS_PER_MINUTE)
1382  * USECS_PER_SEC) + rint(sec * USECS_PER_SEC);
1383 
1384  PG_RETURN_TIMEADT(time);
1385 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#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:570
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define ERROR
Definition: elog.h:43
#define HOURS_PER_DAY
Definition: timestamp.h:78
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int64 TimeADT
Definition: date.h:25
double rint(double x)
Definition: rint.c:21
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
int tm_min
Definition: pgtime.h:28

◆ overlaps_time()

Datum overlaps_time ( PG_FUNCTION_ARGS  )

Definition at line 1572 of file date.c.

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

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

◆ overlaps_timetz()

Datum overlaps_timetz ( PG_FUNCTION_ARGS  )

Definition at line 2426 of file date.c.

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

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

◆ time2tm()

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

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

1274 {
1275  tm->tm_hour = time / USECS_PER_HOUR;
1276  time -= tm->tm_hour * USECS_PER_HOUR;
1277  tm->tm_min = time / USECS_PER_MINUTE;
1278  time -= tm->tm_min * USECS_PER_MINUTE;
1279  tm->tm_sec = time / USECS_PER_SEC;
1280  time -= tm->tm_sec * USECS_PER_SEC;
1281  *fsec = time;
1282  return 0;
1283 }
#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 1523 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_INT32.

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

1524 {
1525  TimeADT time1 = PG_GETARG_TIMEADT(0);
1526  TimeADT time2 = PG_GETARG_TIMEADT(1);
1527 
1528  if (time1 < time2)
1529  PG_RETURN_INT32(-1);
1530  if (time1 > time2)
1531  PG_RETURN_INT32(1);
1532  PG_RETURN_INT32(0);
1533 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
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 1469 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timeeq().

1470 {
1471  TimeADT time1 = PG_GETARG_TIMEADT(0);
1472  TimeADT time2 = PG_GETARG_TIMEADT(1);
1473 
1474  PG_RETURN_BOOL(time1 == time2);
1475 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_ge()

Datum time_ge ( PG_FUNCTION_ARGS  )

Definition at line 1514 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timege().

1515 {
1516  TimeADT time1 = PG_GETARG_TIMEADT(0);
1517  TimeADT time2 = PG_GETARG_TIMEADT(1);
1518 
1519  PG_RETURN_BOOL(time1 >= time2);
1520 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_gt()

Datum time_gt ( PG_FUNCTION_ARGS  )

Definition at line 1505 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timegt().

1506 {
1507  TimeADT time1 = PG_GETARG_TIMEADT(0);
1508  TimeADT time2 = PG_GETARG_TIMEADT(1);
1509 
1510  PG_RETURN_BOOL(time1 > time2);
1511 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_hash()

Datum time_hash ( PG_FUNCTION_ARGS  )

Definition at line 1536 of file date.c.

References hashint8().

1537 {
1538  return hashint8(fcinfo);
1539 }
Datum hashint8(PG_FUNCTION_ARGS)
Definition: hashfunc.c:83

◆ time_hash_extended()

Datum time_hash_extended ( PG_FUNCTION_ARGS  )

Definition at line 1542 of file date.c.

References hashint8extended().

1543 {
1544  return hashint8extended(fcinfo);
1545 }
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103

◆ time_in()

Datum time_in ( PG_FUNCTION_ARGS  )

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

1222 {
1223  char *str = PG_GETARG_CSTRING(0);
1224 
1225 #ifdef NOT_USED
1226  Oid typelem = PG_GETARG_OID(1);
1227 #endif
1228  int32 typmod = PG_GETARG_INT32(2);
1229  TimeADT result;
1230  fsec_t fsec;
1231  struct pg_tm tt,
1232  *tm = &tt;
1233  int tz;
1234  int nf;
1235  int dterr;
1236  char workbuf[MAXDATELEN + 1];
1237  char *field[MAXDATEFIELDS];
1238  int dtype;
1239  int ftype[MAXDATEFIELDS];
1240 
1241  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
1242  field, ftype, MAXDATEFIELDS, &nf);
1243  if (dterr == 0)
1244  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
1245  if (dterr != 0)
1246  DateTimeParseError(dterr, str, "time");
1247 
1248  tm2time(tm, fsec, &result);
1249  AdjustTimeForTypmod(&result, typmod);
1250 
1251  PG_RETURN_TIMEADT(result);
1252 }
#define MAXDATELEN
Definition: datetime.h:201
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3739
#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:1717
signed int int32
Definition: c.h:346
static struct pg_tm tm
Definition: localtime.c:108
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
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:1258
#define MAXDATEFIELDS
Definition: datetime.h:203
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:540
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ time_interval()

Datum time_interval ( PG_FUNCTION_ARGS  )

Definition at line 1778 of file date.c.

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

1779 {
1780  TimeADT time = PG_GETARG_TIMEADT(0);
1781  Interval *result;
1782 
1783  result = (Interval *) palloc(sizeof(Interval));
1784 
1785  result->time = time;
1786  result->day = 0;
1787  result->month = 0;
1788 
1789  PG_RETURN_INTERVAL_P(result);
1790 }
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
int32 day
Definition: timestamp.h:47
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949

◆ time_larger()

Datum time_larger ( PG_FUNCTION_ARGS  )

Definition at line 1548 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

1549 {
1550  TimeADT time1 = PG_GETARG_TIMEADT(0);
1551  TimeADT time2 = PG_GETARG_TIMEADT(1);
1552 
1553  PG_RETURN_TIMEADT((time1 > time2) ? time1 : time2);
1554 }
#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 1496 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timele().

1497 {
1498  TimeADT time1 = PG_GETARG_TIMEADT(0);
1499  TimeADT time2 = PG_GETARG_TIMEADT(1);
1500 
1501  PG_RETURN_BOOL(time1 <= time2);
1502 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_lt()

Datum time_lt ( PG_FUNCTION_ARGS  )

Definition at line 1487 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

Referenced by gbt_timelt().

1488 {
1489  TimeADT time1 = PG_GETARG_TIMEADT(0);
1490  TimeADT time2 = PG_GETARG_TIMEADT(1);
1491 
1492  PG_RETURN_BOOL(time1 < time2);
1493 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_mi_interval()

Datum time_mi_interval ( PG_FUNCTION_ARGS  )

Definition at line 1863 of file date.c.

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

1864 {
1865  TimeADT time = PG_GETARG_TIMEADT(0);
1866  Interval *span = PG_GETARG_INTERVAL_P(1);
1867  TimeADT result;
1868 
1869  result = time - span->time;
1870  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1871  if (result < INT64CONST(0))
1872  result += USECS_PER_DAY;
1873 
1874  PG_RETURN_TIMEADT(result);
1875 }
#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 1826 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().

1827 {
1828  TimeADT time1 = PG_GETARG_TIMEADT(0);
1829  TimeADT time2 = PG_GETARG_TIMEADT(1);
1830  Interval *result;
1831 
1832  result = (Interval *) palloc(sizeof(Interval));
1833 
1834  result->month = 0;
1835  result->day = 0;
1836  result->time = time1 - time2;
1837 
1838  PG_RETURN_INTERVAL_P(result);
1839 }
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
int32 day
Definition: timestamp.h:47
TimeOffset time
Definition: timestamp.h:45
int64 TimeADT
Definition: date.h:25
int32 month
Definition: timestamp.h:48
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949

◆ time_ne()

Datum time_ne ( PG_FUNCTION_ARGS  )

Definition at line 1478 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_BOOL.

1479 {
1480  TimeADT time1 = PG_GETARG_TIMEADT(0);
1481  TimeADT time2 = PG_GETARG_TIMEADT(1);
1482 
1483  PG_RETURN_BOOL(time1 != time2);
1484 }
int64 TimeADT
Definition: date.h:25
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62

◆ time_out()

Datum time_out ( PG_FUNCTION_ARGS  )

Definition at line 1286 of file date.c.

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

1287 {
1288  TimeADT time = PG_GETARG_TIMEADT(0);
1289  char *result;
1290  struct pg_tm tt,
1291  *tm = &tt;
1292  fsec_t fsec;
1293  char buf[MAXDATELEN + 1];
1294 
1295  time2tm(time, tm, &fsec);
1296  EncodeTimeOnly(tm, fsec, false, 0, DateStyle, buf);
1297 
1298  result = pstrdup(buf);
1299  PG_RETURN_CSTRING(result);
1300 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3943
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1273
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
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:352
int DateStyle
Definition: globals.c:115

◆ time_part()

Datum time_part ( PG_FUNCTION_ARGS  )

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

1922 {
1923  text *units = PG_GETARG_TEXT_PP(0);
1924  TimeADT time = PG_GETARG_TIMEADT(1);
1925  float8 result;
1926  int type,
1927  val;
1928  char *lowunits;
1929 
1930  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
1931  VARSIZE_ANY_EXHDR(units),
1932  false);
1933 
1934  type = DecodeUnits(0, lowunits, &val);
1935  if (type == UNKNOWN_FIELD)
1936  type = DecodeSpecial(0, lowunits, &val);
1937 
1938  if (type == UNITS)
1939  {
1940  fsec_t fsec;
1941  struct pg_tm tt,
1942  *tm = &tt;
1943 
1944  time2tm(time, tm, &fsec);
1945 
1946  switch (val)
1947  {
1948  case DTK_MICROSEC:
1949  result = tm->tm_sec * 1000000.0 + fsec;
1950  break;
1951 
1952  case DTK_MILLISEC:
1953  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
1954  break;
1955 
1956  case DTK_SECOND:
1957  result = tm->tm_sec + fsec / 1000000.0;
1958  break;
1959 
1960  case DTK_MINUTE:
1961  result = tm->tm_min;
1962  break;
1963 
1964  case DTK_HOUR:
1965  result = tm->tm_hour;
1966  break;
1967 
1968  case DTK_TZ:
1969  case DTK_TZ_MINUTE:
1970  case DTK_TZ_HOUR:
1971  case DTK_DAY:
1972  case DTK_MONTH:
1973  case DTK_QUARTER:
1974  case DTK_YEAR:
1975  case DTK_DECADE:
1976  case DTK_CENTURY:
1977  case DTK_MILLENNIUM:
1978  case DTK_ISOYEAR:
1979  default:
1980  ereport(ERROR,
1981  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1982  errmsg("\"time\" units \"%s\" not recognized",
1983  lowunits)));
1984  result = 0;
1985  }
1986  }
1987  else if (type == RESERV && val == DTK_EPOCH)
1988  {
1989  result = time / 1000000.0;
1990  }
1991  else
1992  {
1993  ereport(ERROR,
1994  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1995  errmsg("\"time\" units \"%s\" not recognized",
1996  lowunits)));
1997  result = 0;
1998  }
1999 
2000  PG_RETURN_FLOAT8(result);
2001 }
#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:131
#define DTK_QUARTER
Definition: datetime.h:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define DTK_MILLENNIUM
Definition: datetime.h:171
int errcode(int sqlerrcode)
Definition: elog.c:570
int time2tm(TimeADT time, struct pg_tm *tm, fsec_t *fsec)
Definition: date.c:1273
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3702
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
static struct pg_tm tm
Definition: localtime.c:108
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
#define DTK_SECOND
Definition: datetime.h:161
#define DTK_ISOYEAR
Definition: datetime.h:180
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define DTK_TZ_MINUTE
Definition: datetime.h:179
#define ereport(elevel, rest)
Definition: elog.h:141
#define DTK_MINUTE
Definition: datetime.h:162
#define DTK_MICROSEC
Definition: datetime.h:173
#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:3011
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: c.h:549
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:684

◆ time_pl_interval()

Datum time_pl_interval ( PG_FUNCTION_ARGS  )

Definition at line 1845 of file date.c.

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

1846 {
1847  TimeADT time = PG_GETARG_TIMEADT(0);
1848  Interval *span = PG_GETARG_INTERVAL_P(1);
1849  TimeADT result;
1850 
1851  result = time + span->time;
1852  result -= result / USECS_PER_DAY * USECS_PER_DAY;
1853  if (result < INT64CONST(0))
1854  result += USECS_PER_DAY;
1855 
1856  PG_RETURN_TIMEADT(result);
1857 }
#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 1306 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.

1307 {
1309 
1310 #ifdef NOT_USED
1311  Oid typelem = PG_GETARG_OID(1);
1312 #endif
1313  int32 typmod = PG_GETARG_INT32(2);
1314  TimeADT result;
1315 
1316  result = pq_getmsgint64(buf);
1317 
1318  if (result < INT64CONST(0) || result > USECS_PER_DAY)
1319  ereport(ERROR,
1320  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1321  errmsg("time out of range")));
1322 
1323  AdjustTimeForTypmod(&result, typmod);
1324 
1325  PG_RETURN_TIMEADT(result);
1326 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:346
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:68
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
int64 TimeADT
Definition: date.h:25
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ time_scale()

Datum time_scale ( PG_FUNCTION_ARGS  )

Definition at line 1414 of file date.c.

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

1415 {
1416  TimeADT time = PG_GETARG_TIMEADT(0);
1417  int32 typmod = PG_GETARG_INT32(1);
1418  TimeADT result;
1419 
1420  result = time;
1421  AdjustTimeForTypmod(&result, typmod);
1422 
1423  PG_RETURN_TIMEADT(result);
1424 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
signed int int32
Definition: c.h:346
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ time_send()

Datum time_send ( PG_FUNCTION_ARGS  )

Definition at line 1332 of file date.c.

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

1333 {
1334  TimeADT time = PG_GETARG_TIMEADT(0);
1336 
1337  pq_begintypsend(&buf);
1338  pq_sendint64(&buf, time);
1340 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
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 1557 of file date.c.

References PG_GETARG_TIMEADT, and PG_RETURN_TIMEADT.

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

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

1395 {
1396  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1397  Node *ret = NULL;
1398 
1399  if (IsA(rawreq, SupportRequestSimplify))
1400  {
1402 
1403  ret = TemporalSimplify(MAX_TIME_PRECISION, (Node *) req->fcall);
1404  }
1405 
1406  PG_RETURN_POINTER(ret);
1407 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Definition: nodes.h:525
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
Node * TemporalSimplify(int32 max_precis, Node *node)
Definition: datetime.c:4467
#define MAX_TIME_PRECISION
Definition: date.h:51

◆ time_timetz()

Datum time_timetz ( PG_FUNCTION_ARGS  )

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

2560 {
2561  TimeADT time = PG_GETARG_TIMEADT(0);
2562  TimeTzADT *result;
2563  struct pg_tm tt,
2564  *tm = &tt;
2565  fsec_t fsec;
2566  int tz;
2567 
2568  GetCurrentDateTime(tm);
2569  time2tm(time, tm, &fsec);
2571 
2572  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2573 
2574  result->time = time;
2575  result->zone = tz;
2576 
2577  PG_RETURN_TIMETZADT_P(result);
2578 }
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:348
#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:1273
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int32 zone
Definition: date.h:30
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1441
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define PG_GETARG_TIMEADT(n)
Definition: date.h:62
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timestamp_cmp_date()

Datum timestamp_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 962 of file date.c.

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

963 {
965  DateADT dateVal = PG_GETARG_DATEADT(1);
966  Timestamp dt2;
967 
968  dt2 = date2timestamp(dateVal);
969 
971 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
int32 DateADT
Definition: date.h:23
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
int64 Timestamp
Definition: timestamp.h:38
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_date()

Datum timestamp_date ( PG_FUNCTION_ARGS  )

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

1145 {
1147  DateADT result;
1148  struct pg_tm tt,
1149  *tm = &tt;
1150  fsec_t fsec;
1151 
1152  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1153  DATE_NOBEGIN(result);
1154  else if (TIMESTAMP_IS_NOEND(timestamp))
1155  DATE_NOEND(result);
1156  else
1157  {
1158  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1159  ereport(ERROR,
1160  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1161  errmsg("timestamp out of range")));
1162 
1163  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1164  }
1165 
1166  PG_RETURN_DATEADT(result);
1167 }
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:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define DATE_NOBEGIN(j)
Definition: date.h:39
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
int64 Timestamp
Definition: timestamp.h:38
int date2j(int y, int m, int d)
Definition: datetime.c:270
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 890 of file date.c.

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

891 {
893  DateADT dateVal = PG_GETARG_DATEADT(1);
894  Timestamp dt2;
895 
896  dt2 = date2timestamp(dateVal);
897 
898  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) == 0);
899 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_ge_date()

Datum timestamp_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 950 of file date.c.

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

951 {
953  DateADT dateVal = PG_GETARG_DATEADT(1);
954  Timestamp dt2;
955 
956  dt2 = date2timestamp(dateVal);
957 
958  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) >= 0);
959 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_gt_date()

Datum timestamp_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 926 of file date.c.

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

927 {
929  DateADT dateVal = PG_GETARG_DATEADT(1);
930  Timestamp dt2;
931 
932  dt2 = date2timestamp(dateVal);
933 
934  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) > 0);
935 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_le_date()

Datum timestamp_le_date ( PG_FUNCTION_ARGS  )

Definition at line 938 of file date.c.

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

939 {
941  DateADT dateVal = PG_GETARG_DATEADT(1);
942  Timestamp dt2;
943 
944  dt2 = date2timestamp(dateVal);
945 
946  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) <= 0);
947 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_lt_date()

Datum timestamp_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 914 of file date.c.

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

915 {
917  DateADT dateVal = PG_GETARG_DATEADT(1);
918  Timestamp dt2;
919 
920  dt2 = date2timestamp(dateVal);
921 
922  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) < 0);
923 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_ne_date()

Datum timestamp_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 902 of file date.c.

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

903 {
905  DateADT dateVal = PG_GETARG_DATEADT(1);
906  Timestamp dt2;
907 
908  dt2 = date2timestamp(dateVal);
909 
910  PG_RETURN_BOOL(timestamp_cmp_internal(dt1, dt2) != 0);
911 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2059
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:349
static TimestampTz date2timestamp(DateADT dateVal)
Definition: date.c:602

◆ timestamp_time()

Datum timestamp_time ( PG_FUNCTION_ARGS  )

Definition at line 1694 of file date.c.

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

1695 {
1697  TimeADT result;
1698  struct pg_tm tt,
1699  *tm = &tt;
1700  fsec_t fsec;
1701 
1702  if (TIMESTAMP_NOT_FINITE(timestamp))
1703  PG_RETURN_NULL();
1704 
1705  if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1706  ereport(ERROR,
1707  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1708  errmsg("timestamp out of range")));
1709 
1710  /*
1711  * Could also do this with time = (timestamp / USECS_PER_DAY *
1712  * USECS_PER_DAY) - timestamp;
1713  */
1714  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1715  USECS_PER_SEC) + fsec;
1716 
1717  PG_RETURN_TIMEADT(result);
1718 }
#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:1791
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:108
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define ereport(elevel, rest)
Definition: elog.h:141
int64 Timestamp
Definition: timestamp.h:38
int errmsg(const char *fmt,...)
Definition: elog.c:784
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ timestamptz_cmp_date()

Datum timestamptz_cmp_date ( PG_FUNCTION_ARGS  )

Definition at line 1046 of file date.c.

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

1047 {
1049  DateADT dateVal = PG_GETARG_DATEADT(1);
1050  TimestampTz dt2;
1051 
1052  dt2 = date2timestamptz(dateVal);
1053 
1055 }
int32 DateADT
Definition: date.h:23
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_DATEADT(n)
Definition: date.h:61
static TimestampTz date2timestamptz(DateADT dateVal)
Definition: date.c:683
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_date()

Datum timestamptz_date ( PG_FUNCTION_ARGS  )

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

1190 {
1192  DateADT result;
1193  struct pg_tm tt,
1194  *tm = &tt;
1195  fsec_t fsec;
1196  int tz;
1197 
1198  if (TIMESTAMP_IS_NOBEGIN(timestamp))
1199  DATE_NOBEGIN(result);
1200  else if (TIMESTAMP_IS_NOEND(timestamp))
1201  DATE_NOEND(result);
1202  else
1203  {
1204  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1205  ereport(ERROR,
1206  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1207  errmsg("timestamp out of range")));
1208 
1209  result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - POSTGRES_EPOCH_JDATE;
1210  }
1211 
1212  PG_RETURN_DATEADT(result);
1213 }
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:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
#define DATE_NOBEGIN(j)
Definition: date.h:39
#define ERROR
Definition: elog.h:43
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
int date2j(int y, int m, int d)
Definition: datetime.c:270
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:784
#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 date2timestamptz(), PG_GETARG_DATEADT, PG_GETARG_TIMESTAMPTZ, PG_RETURN_BOOL, and timestamptz_cmp_internal.

975 {
977  DateADT dateVal = PG_GETARG_DATEADT(1);
978  TimestampTz dt2;
979 
980  dt2 = date2timestamptz(dateVal);
981 
983 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_ge_date()

Datum timestamptz_ge_date ( PG_FUNCTION_ARGS  )

Definition at line 1034 of file date.c.

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

1035 {
1037  DateADT dateVal = PG_GETARG_DATEADT(1);
1038  TimestampTz dt2;
1039 
1040  dt2 = date2timestamptz(dateVal);
1041 
1042  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) >= 0);
1043 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_gt_date()

Datum timestamptz_gt_date ( PG_FUNCTION_ARGS  )

Definition at line 1010 of file date.c.

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

1011 {
1013  DateADT dateVal = PG_GETARG_DATEADT(1);
1014  TimestampTz dt2;
1015 
1016  dt2 = date2timestamptz(dateVal);
1017 
1019 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_le_date()

Datum timestamptz_le_date ( PG_FUNCTION_ARGS  )

Definition at line 1022 of file date.c.

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

1023 {
1025  DateADT dateVal = PG_GETARG_DATEADT(1);
1026  TimestampTz dt2;
1027 
1028  dt2 = date2timestamptz(dateVal);
1029 
1030  PG_RETURN_BOOL(timestamptz_cmp_internal(dt1, dt2) <= 0);
1031 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_lt_date()

Datum timestamptz_lt_date ( PG_FUNCTION_ARGS  )

Definition at line 998 of file date.c.

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

999 {
1001  DateADT dateVal = PG_GETARG_DATEADT(1);
1002  TimestampTz dt2;
1003 
1004  dt2 = date2timestamptz(dateVal);
1005 
1007 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_ne_date()

Datum timestamptz_ne_date ( PG_FUNCTION_ARGS  )

Definition at line 986 of file date.c.

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

987 {
989  DateADT dateVal = PG_GETARG_DATEADT(1);
990  TimestampTz dt2;
991 
992  dt2 = date2timestamptz(dateVal);
993 
995 }
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:683
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:98
#define PG_GETARG_TIMESTAMPTZ(n)
Definition: timestamp.h:36

◆ timestamptz_time()

Datum timestamptz_time ( PG_FUNCTION_ARGS  )

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

1725 {
1727  TimeADT result;
1728  struct pg_tm tt,
1729  *tm = &tt;
1730  int tz;
1731  fsec_t fsec;
1732 
1733  if (TIMESTAMP_NOT_FINITE(timestamp))
1734  PG_RETURN_NULL();
1735 
1736  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1737  ereport(ERROR,
1738  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1739  errmsg("timestamp out of range")));
1740 
1741  /*
1742  * Could also do this with time = (timestamp / USECS_PER_DAY *
1743  * USECS_PER_DAY) - timestamp;
1744  */
1745  result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
1746  USECS_PER_SEC) + fsec;
1747 
1748  PG_RETURN_TIMEADT(result);
1749 }
#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:1791
#define PG_RETURN_TIMEADT(x)
Definition: date.h:66
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:108
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int64 TimeADT
Definition: date.h:25
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:784
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ timestamptz_timetz()

Datum timestamptz_timetz ( PG_FUNCTION_ARGS  )

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

2586 {
2588  TimeTzADT *result;
2589  struct pg_tm tt,
2590  *tm = &tt;
2591  int tz;
2592  fsec_t fsec;
2593 
2594  if (TIMESTAMP_NOT_FINITE(timestamp))
2595  PG_RETURN_NULL();
2596 
2597  if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
2598  ereport(ERROR,
2599  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2600  errmsg("timestamp out of range")));
2601 
2602  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2603 
2604  tm2timetz(tm, fsec, tz, result);
2605 
2606  PG_RETURN_TIMETZADT_P(result);
2607 }
#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:1791
int errcode(int sqlerrcode)
Definition: elog.c:570
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2012
#define TIMESTAMP_NOT_FINITE(j)
Definition: timestamp.h:122
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: date.h:27
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ timetypmodin()

Datum timetypmodin ( PG_FUNCTION_ARGS  )

Definition at line 1343 of file date.c.

References anytime_typmodin(), PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

1344 {
1346 
1347  PG_RETURN_INT32(anytime_typmodin(false, ta));
1348 }
static int32 anytime_typmodin(bool istz, ArrayType *ta)
Definition: date.c:46
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251

◆ timetypmodout()

Datum timetypmodout ( PG_FUNCTION_ARGS  )

Definition at line 1351 of file date.c.

References anytime_typmodout(), PG_GETARG_INT32, and PG_RETURN_CSTRING.

1352 {
1353  int32 typmod = PG_GETARG_INT32(0);
1354 
1355  PG_RETURN_CSTRING(anytime_typmodout(false, typmod));
1356 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
signed int int32
Definition: c.h:346
static char * anytime_typmodout(bool istz, int32 typmod)
Definition: date.c:89
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352

◆ timetz2tm()

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

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

2147 {
2148  TimeOffset trem = time->time;
2149 
2150  tm->tm_hour = trem / USECS_PER_HOUR;
2151  trem -= tm->tm_hour * USECS_PER_HOUR;
2152  tm->tm_min = trem / USECS_PER_MINUTE;
2153  trem -= tm->tm_min * USECS_PER_MINUTE;
2154  tm->tm_sec = trem / USECS_PER_SEC;
2155  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2156 
2157  if (tzp != NULL)
2158  *tzp = time->zone;
2159 
2160  return 0;
2161 }
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 2267 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_INT32, and timetz_cmp_internal().

Referenced by compareDatetime(), and leftmostvalue_timetz().

2268 {
2269  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2270  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2271 
2272  PG_RETURN_INT32(timetz_cmp_internal(time1, time2));
2273 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#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 2186 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().

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

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2214 {
2215  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2216  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2217 
2218  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) == 0);
2219 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_ge()

Datum timetz_ge ( PG_FUNCTION_ARGS  )

Definition at line 2258 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2259 {
2260  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2261  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2262 
2263  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) >= 0);
2264 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_gt()

Datum timetz_gt ( PG_FUNCTION_ARGS  )

Definition at line 2249 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2250 {
2251  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2252  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2253 
2254  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) > 0);
2255 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_hash()

Datum timetz_hash ( PG_FUNCTION_ARGS  )

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

2277 {
2279  uint32 thash;
2280 
2281  /*
2282  * To avoid any problems with padding bytes in the struct, we figure the
2283  * field hashes separately and XOR them.
2284  */
2286  Int64GetDatumFast(key->time)));
2287  thash ^= DatumGetUInt32(hash_uint32(key->zone));
2288  PG_RETURN_UINT32(thash);
2289 }
#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:617
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:345
Datum hash_uint32(uint32 k)
Definition: hashfn.c:613
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
unsigned int uint32
Definition: c.h:358
#define Int64GetDatumFast(X)
Definition: postgres.h:775
Definition: date.h:27

◆ timetz_hash_extended()

Datum timetz_hash_extended ( PG_FUNCTION_ARGS  )

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

2293 {
2295  Datum seed = PG_GETARG_DATUM(1);
2296  uint64 thash;
2297 
2298  /* Same approach as timetz_hash */
2300  Int64GetDatumFast(key->time),
2301  seed));
2303  DatumGetInt64(seed)));
2304  PG_RETURN_UINT64(thash);
2305 }
TimeADT time
Definition: date.h:29
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum hashint8extended(PG_FUNCTION_ARGS)
Definition: hashfunc.c:103
#define PG_RETURN_UINT64(x)
Definition: fmgr.h:358
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:775
#define DatumGetUInt64(X)
Definition: postgres.h:634
Definition: date.h:27
Datum hash_uint32_extended(uint32 k, uint64 seed)
Definition: hashfn.c:634
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:619

◆ timetz_in()

Datum timetz_in ( PG_FUNCTION_ARGS  )

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

2023 {
2024  char *str = PG_GETARG_CSTRING(0);
2025 
2026 #ifdef NOT_USED
2027  Oid typelem = PG_GETARG_OID(1);
2028 #endif
2029  int32 typmod = PG_GETARG_INT32(2);
2030  TimeTzADT *result;
2031  fsec_t fsec;
2032  struct pg_tm tt,
2033  *tm = &tt;
2034  int tz;
2035  int nf;
2036  int dterr;
2037  char workbuf[MAXDATELEN + 1];
2038  char *field[MAXDATEFIELDS];
2039  int dtype;
2040  int ftype[MAXDATEFIELDS];
2041 
2042  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
2043  field, ftype, MAXDATEFIELDS, &nf);
2044  if (dterr == 0)
2045  dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
2046  if (dterr != 0)
2047  DateTimeParseError(dterr, str, "time with time zone");
2048 
2049  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2050  tm2timetz(tm, fsec, tz, result);
2051  AdjustTimeForTypmod(&(result->time), typmod);
2052 
2053  PG_RETURN_TIMETZADT_P(result);
2054 }
#define MAXDATELEN
Definition: datetime.h:201
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3739
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:1717
signed int int32
Definition: c.h:346
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2012
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
int32 fsec_t
Definition: timestamp.h:41
#define MAXDATEFIELDS
Definition: datetime.h:203
void * palloc(Size size)
Definition: mcxt.c:949
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:540
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ timetz_izone()

Datum timetz_izone ( PG_FUNCTION_ARGS  )

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

2841 {
2843  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2844  TimeTzADT *result;
2845  int tz;
2846 
2847  if (zone->month != 0 || zone->day != 0)
2848  ereport(ERROR,
2849  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2850  errmsg("interval time zone \"%s\" must not include months or days",
2852  PointerGetDatum(zone))))));
2853 
2854  tz = -(zone->time / USECS_PER_SEC);
2855 
2856  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2857 
2858  result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
2859  while (result->time < INT64CONST(0))
2860  result->time += USECS_PER_DAY;
2861  while (result->time >= USECS_PER_DAY)
2862  result->time -= USECS_PER_DAY;
2863 
2864  result->zone = tz;
2865 
2866  PG_RETURN_TIMETZADT_P(result);
2867 }
#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:570
Datum interval_out(PG_FUNCTION_ARGS)
Definition: timestamp.c:961
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:617
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
#define ereport(elevel, rest)
Definition: elog.h:141
int32 month
Definition: timestamp.h:48
Definition: zic.c:98
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: date.h:27

◆ timetz_larger()

Datum timetz_larger ( PG_FUNCTION_ARGS  )

Definition at line 2308 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2309 {
2310  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2311  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2312  TimeTzADT *result;
2313 
2314  if (timetz_cmp_internal(time1, time2) > 0)
2315  result = time1;
2316  else
2317  result = time2;
2318  PG_RETURN_TIMETZADT_P(result);
2319 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#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 2240 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2241 {
2242  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2243  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2244 
2245  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) <= 0);
2246 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_lt()

Datum timetz_lt ( PG_FUNCTION_ARGS  )

Definition at line 2231 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2232 {
2233  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2234  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2235 
2236  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) < 0);
2237 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_mi_interval()

Datum timetz_mi_interval ( PG_FUNCTION_ARGS  )

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

2362 {
2363  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2364  Interval *span = PG_GETARG_INTERVAL_P(1);
2365  TimeTzADT *result;
2366 
2367  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2368 
2369  result->time = time->time - span->time;
2370  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2371  if (result->time < INT64CONST(0))
2372  result->time += USECS_PER_DAY;
2373 
2374  result->zone = time->zone;
2375 
2376  PG_RETURN_TIMETZADT_P(result);
2377 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timetz_ne()

Datum timetz_ne ( PG_FUNCTION_ARGS  )

Definition at line 2222 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_BOOL, and timetz_cmp_internal().

2223 {
2224  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2225  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2226 
2227  PG_RETURN_BOOL(timetz_cmp_internal(time1, time2) != 0);
2228 }
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Definition: date.h:27

◆ timetz_out()

Datum timetz_out ( PG_FUNCTION_ARGS  )

Definition at line 2057 of file date.c.

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

2058 {
2059  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2060  char *result;
2061  struct pg_tm tt,
2062  *tm = &tt;
2063  fsec_t fsec;
2064  int tz;
2065  char buf[MAXDATELEN + 1];
2066 
2067  timetz2tm(time, tm, &fsec, &tz);
2068  EncodeTimeOnly(tm, fsec, true, tz, DateStyle, buf);
2069 
2070  result = pstrdup(buf);
2071  PG_RETURN_CSTRING(result);
2072 }
#define MAXDATELEN
Definition: datetime.h:201
char * pstrdup(const char *in)
Definition: mcxt.c:1186
void EncodeTimeOnly(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, int style, char *str)
Definition: datetime.c:3943
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
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:2146
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
int DateStyle
Definition: globals.c:115
Definition: date.h:27

◆ timetz_part()

Datum timetz_part ( PG_FUNCTION_ARGS  )

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

2659 {
2660  text *units = PG_GETARG_TEXT_PP(0);
2661  TimeTzADT *time = PG_GETARG_TIMETZADT_P(1);
2662  float8 result;
2663  int type,
2664  val;
2665  char *lowunits;
2666 
2667  lowunits = downcase_truncate_identifier(VARDATA_ANY(units),
2668  VARSIZE_ANY_EXHDR(units),
2669  false);
2670 
2671  type = DecodeUnits(0, lowunits, &val);
2672  if (type == UNKNOWN_FIELD)
2673  type = DecodeSpecial(0, lowunits, &val);
2674 
2675  if (type == UNITS)
2676  {
2677  double dummy;
2678  int tz;
2679  fsec_t fsec;
2680  struct pg_tm tt,
2681  *tm = &tt;
2682 
2683  timetz2tm(time, tm, &fsec, &tz);
2684 
2685  switch (val)
2686  {
2687  case DTK_TZ:
2688  result = -tz;
2689  break;
2690 
2691  case DTK_TZ_MINUTE:
2692  result = -tz;
2693  result /= SECS_PER_MINUTE;
2694  FMODULO(result, dummy, (double) SECS_PER_MINUTE);
2695  break;
2696 
2697  case DTK_TZ_HOUR:
2698  dummy = -tz;
2699  FMODULO(dummy, result, (double) SECS_PER_HOUR);
2700  break;
2701 
2702  case DTK_MICROSEC:
2703  result = tm->tm_sec * 1000000.0 + fsec;
2704  break;
2705 
2706  case DTK_MILLISEC:
2707  result = tm->tm_sec * 1000.0 + fsec / 1000.0;
2708  break;
2709 
2710  case DTK_SECOND:
2711  result = tm->tm_sec + fsec / 1000000.0;
2712  break;
2713 
2714  case DTK_MINUTE:
2715  result = tm->tm_min;
2716  break;
2717 
2718  case DTK_HOUR:
2719  result = tm->tm_hour;
2720  break;
2721 
2722  case DTK_DAY:
2723  case DTK_MONTH:
2724  case DTK_QUARTER:
2725  case DTK_YEAR:
2726  case DTK_DECADE:
2727  case DTK_CENTURY:
2728  case DTK_MILLENNIUM:
2729  default:
2730  ereport(ERROR,
2731  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2732  errmsg("\"time with time zone\" units \"%s\" not recognized",
2733  lowunits)));
2734  result = 0;
2735  }
2736  }
2737  else if (type == RESERV && val == DTK_EPOCH)
2738  {
2739  result = time->time / 1000000.0 + time->zone;
2740  }
2741  else
2742  {
2743  ereport(ERROR,
2744  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2745  errmsg("\"time with time zone\" units \"%s\" not recognized",
2746  lowunits)));
2747  result = 0;
2748  }
2749 
2750  PG_RETURN_FLOAT8(result);
2751 }
#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:131
#define DTK_QUARTER
Definition: datetime.h:167
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define FMODULO(t, q, u)
Definition: datetime.h:238
#define DTK_MILLENNIUM
Definition: datetime.h:171
int errcode(int sqlerrcode)
Definition: elog.c:570
#define UNKNOWN_FIELD
Definition: datetime.h:125
int DecodeUnits(int field, char *lowtoken, int *val)
Definition: datetime.c:3702
Definition: pgtime.h:25
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
static struct pg_tm tm
Definition: localtime.c:108
#define DTK_MONTH
Definition: datetime.h:166
#define DTK_MILLISEC
Definition: datetime.h:172
#define DTK_DECADE
Definition: datetime.h:169
#define DTK_TZ
Definition: datetime.h:147
#define DTK_HOUR
Definition: datetime.h:163
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:491
#define DTK_SECOND
Definition: datetime.h:161
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
#define DTK_TZ_MINUTE
Definition: datetime.h:179
#define ereport(elevel, rest)
Definition: elog.h:141
#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:2146
#define DTK_DAY
Definition: datetime.h:164
#define RESERV
Definition: datetime.h:91
int DecodeSpecial(int field, char *lowtoken, int *val)
Definition: datetime.c:3011
#define DTK_EPOCH
Definition: datetime.h:153
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:784
Definition: c.h:549
int tm_sec
Definition: pgtime.h:27
Definition: date.h:27
int tm_min
Definition: pgtime.h:28
long val
Definition: informix.c:684

◆ timetz_pl_interval()

Datum timetz_pl_interval ( PG_FUNCTION_ARGS  )

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

2340 {
2341  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2342  Interval *span = PG_GETARG_INTERVAL_P(1);
2343  TimeTzADT *result;
2344 
2345  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2346 
2347  result->time = time->time + span->time;
2348  result->time -= result->time / USECS_PER_DAY * USECS_PER_DAY;
2349  if (result->time < INT64CONST(0))
2350  result->time += USECS_PER_DAY;
2351 
2352  result->zone = time->zone;
2353 
2354  PG_RETURN_TIMETZADT_P(result);
2355 }
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
TimeOffset time
Definition: timestamp.h:45
#define USECS_PER_DAY
Definition: timestamp.h:91
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27

◆ timetz_recv()

Datum timetz_recv ( PG_FUNCTION_ARGS  )

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

2079 {
2081 
2082 #ifdef NOT_USED
2083  Oid typelem = PG_GETARG_OID(1);
2084 #endif
2085  int32 typmod = PG_GETARG_INT32(2);
2086  TimeTzADT *result;
2087 
2088  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2089 
2090  result->time = pq_getmsgint64(buf);
2091 
2092  if (result->time < INT64CONST(0) || result->time > USECS_PER_DAY)
2093  ereport(ERROR,
2094  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
2095  errmsg("time out of range")));
2096 
2097  result->zone = pq_getmsgint(buf, sizeof(result->zone));
2098 
2099  /* Check for sane GMT displacement; see notes in datatype/timestamp.h */
2100  if (result->zone <= -TZDISP_LIMIT || result->zone >= TZDISP_LIMIT)
2101  ereport(ERROR,
2102  (errcode(ERRCODE_INVALID_TIME_ZONE_DISPLACEMENT_VALUE),
2103  errmsg("time zone displacement out of range")));
2104 
2105  AdjustTimeForTypmod(&(result->time), typmod);
2106 
2107  PG_RETURN_TIMETZADT_P(result);
2108 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:570
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:346
#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:270
#define USECS_PER_DAY
Definition: timestamp.h:91
#define ereport(elevel, rest)
Definition: elog.h:141
#define TZDISP_LIMIT
Definition: timestamp.h:104
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:784
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:1434

◆ timetz_scale()

Datum timetz_scale ( PG_FUNCTION_ARGS  )

Definition at line 2168 of file date.c.

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

2169 {
2170  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2171  int32 typmod = PG_GETARG_INT32(1);
2172  TimeTzADT *result;
2173 
2174  result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
2175 
2176  result->time = time->time;
2177  result->zone = time->zone;
2178 
2179  AdjustTimeForTypmod(&(result->time), typmod);
2180 
2181  PG_RETURN_TIMETZADT_P(result);
2182 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
TimeADT time
Definition: date.h:29
signed int int32
Definition: c.h:346
int32 zone
Definition: date.h:30
#define PG_GETARG_TIMETZADT_P(n)
Definition: date.h:63
void * palloc(Size size)
Definition: mcxt.c:949
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1434

◆ timetz_send()

Datum timetz_send ( PG_FUNCTION_ARGS  )

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

2115 {
2116  TimeTzADT *time = PG_GETARG_TIMETZADT_P(0);
2118 
2119  pq_begintypsend(&buf);
2120  pq_sendint64(&buf, time->time);
2121  pq_sendint32(&buf, time->zone);
2123 }
TimeADT time
Definition: date.h:29
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
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 2322 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMETZADT_P, and timetz_cmp_internal().

2323 {
2324  TimeTzADT *time1 = PG_GETARG_TIMETZADT_P(0);
2325  TimeTzADT *time2 = PG_GETARG_TIMETZADT_P(1);
2326  TimeTzADT *result;
2327 
2328  if (timetz_cmp_internal(time1, time2) < 0)
2329  result = time1;
2330  else
2331  result = time2;
2332  PG_RETURN_TIMETZADT_P(result);
2333 }
#define PG_RETURN_TIMETZADT_P(x)
Definition: date.h:67
static int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2)
Definition: date.c:2186
#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 2546 of file date.c.

References PG_GETARG_TIMETZADT_P, PG_RETURN_TIMEADT, and TimeTzADT::time.

2547 {
2548  TimeTzADT *timetz = PG_GETARG_TIMETZADT_P(0);
2549  TimeADT result;
2550 
2551  /* swallow the time zone and just return the time */
2552  result = timetz->time;
2553 
2554  PG_RETURN_TIMEADT(result);
2555 }
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()