PostgreSQL Source Code  git master
date.h File Reference
#include <math.h>
#include "datatype/timestamp.h"
#include "fmgr.h"
#include "pgtime.h"
Include dependency graph for date.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TimeTzADT
 

Macros

#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)
 
#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)
 
#define DATE_NOBEGIN(j)   ((j) = DATEVAL_NOBEGIN)
 
#define DATE_IS_NOBEGIN(j)   ((j) == DATEVAL_NOBEGIN)
 
#define DATE_NOEND(j)   ((j) = DATEVAL_NOEND)
 
#define DATE_IS_NOEND(j)   ((j) == DATEVAL_NOEND)
 
#define DATE_NOT_FINITE(j)   (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))
 
#define MAX_TIME_PRECISION   6
 
#define PG_GETARG_DATEADT(n)   DatumGetDateADT(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TIMEADT(n)   DatumGetTimeADT(PG_GETARG_DATUM(n))
 
#define PG_GETARG_TIMETZADT_P(n)   DatumGetTimeTzADTP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_DATEADT(x)   return DateADTGetDatum(x)
 
#define PG_RETURN_TIMEADT(x)   return TimeADTGetDatum(x)
 
#define PG_RETURN_TIMETZADT_P(x)   return TimeTzADTPGetDatum(x)
 

Typedefs

typedef int32 DateADT
 
typedef int64 TimeADT
 

Functions

static DateADT DatumGetDateADT (Datum X)
 
static TimeADT DatumGetTimeADT (Datum X)
 
static TimeTzADTDatumGetTimeTzADTP (Datum X)
 
static Datum DateADTGetDatum (DateADT X)
 
static Datum TimeADTGetDatum (TimeADT X)
 
static Datum TimeTzADTPGetDatum (const TimeTzADT *X)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
Timestamp date2timestamp_opt_overflow (DateADT dateVal, int *overflow)
 
TimestampTz date2timestamptz_opt_overflow (DateADT dateVal, int *overflow)
 
int32 date_cmp_timestamp_internal (DateADT dateVal, Timestamp dt2)
 
int32 date_cmp_timestamptz_internal (DateADT dateVal, TimestampTz dt2)
 
void EncodeSpecialDate (DateADT dt, char *str)
 
int time2tm (TimeADT time, struct pg_tm *tm, fsec_t *fsec)
 
int timetz2tm (TimeTzADT *time, struct pg_tm *tm, fsec_t *fsec, int *tzp)
 
int tm2time (struct pg_tm *tm, fsec_t fsec, TimeADT *result)
 
int tm2timetz (struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
 
bool time_overflows (int hour, int min, int sec, fsec_t fsec)
 
bool float_time_overflows (int hour, int min, double sec)
 
void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 

Macro Definition Documentation

◆ DATE_IS_NOBEGIN

#define DATE_IS_NOBEGIN (   j)    ((j) == DATEVAL_NOBEGIN)

Definition at line 40 of file date.h.

◆ DATE_IS_NOEND

#define DATE_IS_NOEND (   j)    ((j) == DATEVAL_NOEND)

Definition at line 42 of file date.h.

◆ DATE_NOBEGIN

#define DATE_NOBEGIN (   j)    ((j) = DATEVAL_NOBEGIN)

Definition at line 39 of file date.h.

◆ DATE_NOEND

#define DATE_NOEND (   j)    ((j) = DATEVAL_NOEND)

Definition at line 41 of file date.h.

◆ DATE_NOT_FINITE

#define DATE_NOT_FINITE (   j)    (DATE_IS_NOBEGIN(j) || DATE_IS_NOEND(j))

Definition at line 43 of file date.h.

◆ DATEVAL_NOBEGIN

#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)

Definition at line 36 of file date.h.

◆ DATEVAL_NOEND

#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)

Definition at line 37 of file date.h.

◆ MAX_TIME_PRECISION

#define MAX_TIME_PRECISION   6

Definition at line 45 of file date.h.

◆ PG_GETARG_DATEADT

#define PG_GETARG_DATEADT (   n)    DatumGetDateADT(PG_GETARG_DATUM(n))

Definition at line 89 of file date.h.

◆ PG_GETARG_TIMEADT

#define PG_GETARG_TIMEADT (   n)    DatumGetTimeADT(PG_GETARG_DATUM(n))

Definition at line 90 of file date.h.

◆ PG_GETARG_TIMETZADT_P

#define PG_GETARG_TIMETZADT_P (   n)    DatumGetTimeTzADTP(PG_GETARG_DATUM(n))

Definition at line 91 of file date.h.

◆ PG_RETURN_DATEADT

#define PG_RETURN_DATEADT (   x)    return DateADTGetDatum(x)

Definition at line 93 of file date.h.

◆ PG_RETURN_TIMEADT

#define PG_RETURN_TIMEADT (   x)    return TimeADTGetDatum(x)

Definition at line 94 of file date.h.

◆ PG_RETURN_TIMETZADT_P

#define PG_RETURN_TIMETZADT_P (   x)    return TimeTzADTPGetDatum(x)

Definition at line 95 of file date.h.

Typedef Documentation

◆ DateADT

typedef int32 DateADT

Definition at line 23 of file date.h.

◆ TimeADT

typedef int64 TimeADT

Definition at line 25 of file date.h.

Function Documentation

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT time,
int32  typmod 
)

Definition at line 1653 of file date.c.

1654 {
1655  static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1656  INT64CONST(1000000),
1657  INT64CONST(100000),
1658  INT64CONST(10000),
1659  INT64CONST(1000),
1660  INT64CONST(100),
1661  INT64CONST(10),
1662  INT64CONST(1)
1663  };
1664 
1665  static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1666  INT64CONST(500000),
1667  INT64CONST(50000),
1668  INT64CONST(5000),
1669  INT64CONST(500),
1670  INT64CONST(50),
1671  INT64CONST(5),
1672  INT64CONST(0)
1673  };
1674 
1675  if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1676  {
1677  if (*time >= INT64CONST(0))
1678  *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1679  TimeScales[typmod];
1680  else
1681  *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1682  TimeScales[typmod]);
1683  }
1684 }
#define MAX_TIME_PRECISION
Definition: date.h:45

References MAX_TIME_PRECISION.

Referenced by current_time(), parse_datetime(), sql_localtime(), time_in(), time_recv(), time_scale(), timetz_in(), timetz_recv(), and timetz_scale().

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 728 of file date.c.

729 {
730  double result;
731 
732  if (DATE_IS_NOBEGIN(dateVal))
733  result = -DBL_MAX;
734  else if (DATE_IS_NOEND(dateVal))
735  result = DBL_MAX;
736  else
737  {
738  /* date is days since 2000, timestamp is microseconds since same... */
739  result = dateVal * (double) USECS_PER_DAY;
740  }
741 
742  return result;
743 }
#define USECS_PER_DAY
Definition: timestamp.h:130
#define DATE_IS_NOEND(j)
Definition: date.h:42
#define DATE_IS_NOBEGIN(j)
Definition: date.h:40

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

◆ date2timestamp_opt_overflow()

Timestamp date2timestamp_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 572 of file date.c.

573 {
574  Timestamp result;
575 
576  if (overflow)
577  *overflow = 0;
578 
579  if (DATE_IS_NOBEGIN(dateVal))
580  TIMESTAMP_NOBEGIN(result);
581  else if (DATE_IS_NOEND(dateVal))
582  TIMESTAMP_NOEND(result);
583  else
584  {
585  /*
586  * Since dates have the same minimum values as timestamps, only upper
587  * boundary need be checked for overflow.
588  */
589  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
590  {
591  if (overflow)
592  {
593  *overflow = 1;
594  TIMESTAMP_NOEND(result);
595  return result;
596  }
597  else
598  {
599  ereport(ERROR,
600  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
601  errmsg("date out of range for timestamp")));
602  }
603  }
604 
605  /* date is days since 2000, timestamp is microseconds since same... */
606  result = dateVal * USECS_PER_DAY;
607  }
608 
609  return result;
610 }
int64 Timestamp
Definition: timestamp.h:38
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:158
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:227
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:209
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:163
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

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

Referenced by date2timestamp(), and date_cmp_timestamp_internal().

◆ date2timestamptz_opt_overflow()

TimestampTz date2timestamptz_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 632 of file date.c.

633 {
634  TimestampTz result;
635  struct pg_tm tt,
636  *tm = &tt;
637  int tz;
638 
639  if (overflow)
640  *overflow = 0;
641 
642  if (DATE_IS_NOBEGIN(dateVal))
643  TIMESTAMP_NOBEGIN(result);
644  else if (DATE_IS_NOEND(dateVal))
645  TIMESTAMP_NOEND(result);
646  else
647  {
648  /*
649  * Since dates have the same minimum values as timestamps, only upper
650  * boundary need be checked for overflow.
651  */
652  if (dateVal >= (TIMESTAMP_END_JULIAN - POSTGRES_EPOCH_JDATE))
653  {
654  if (overflow)
655  {
656  *overflow = 1;
657  TIMESTAMP_NOEND(result);
658  return result;
659  }
660  else
661  {
662  ereport(ERROR,
663  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
664  errmsg("date out of range for timestamp")));
665  }
666  }
667 
668  j2date(dateVal + POSTGRES_EPOCH_JDATE,
669  &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
670  tm->tm_hour = 0;
671  tm->tm_min = 0;
672  tm->tm_sec = 0;
674 
675  result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
676 
677  /*
678  * Since it is possible to go beyond allowed timestamptz range because
679  * of time zone, check for allowed timestamp range after adding tz.
680  */
681  if (!IS_VALID_TIMESTAMP(result))
682  {
683  if (overflow)
684  {
685  if (result < MIN_TIMESTAMP)
686  {
687  *overflow = -1;
688  TIMESTAMP_NOBEGIN(result);
689  }
690  else
691  {
692  *overflow = 1;
693  TIMESTAMP_NOEND(result);
694  }
695  }
696  else
697  {
698  ereport(ERROR,
699  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
700  errmsg("date out of range for timestamp")));
701  }
702  }
703  }
704 
705  return result;
706 }
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1650
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:312
int64 TimestampTz
Definition: timestamp.h:39
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:241
#define USECS_PER_SEC
Definition: timestamp.h:133
#define MIN_TIMESTAMP
Definition: timestamp.h:230
static struct pg_tm tm
Definition: localtime.c:104
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28
Definition: pgtime.h:35
int tm_hour
Definition: pgtime.h:38
int tm_mday
Definition: pgtime.h:39
int tm_mon
Definition: pgtime.h:40
int tm_min
Definition: pgtime.h:37
int tm_sec
Definition: pgtime.h:36
int tm_year
Definition: pgtime.h:41

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

Referenced by date2timestamptz(), and date_cmp_timestamptz_internal().

◆ date_cmp_timestamp_internal()

int32 date_cmp_timestamp_internal ( DateADT  dateVal,
Timestamp  dt2 
)

Definition at line 751 of file date.c.

752 {
753  Timestamp dt1;
754  int overflow;
755 
756  dt1 = date2timestamp_opt_overflow(dateVal, &overflow);
757  if (overflow > 0)
758  {
759  /* dt1 is larger than any finite timestamp, but less than infinity */
760  return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
761  }
762  Assert(overflow == 0); /* -1 case cannot occur */
763 
764  return timestamp_cmp_internal(dt1, dt2);
765 }
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2136
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:166
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:572
Assert(fmt[strlen(fmt) - 1] !='\n')

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

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

◆ date_cmp_timestamptz_internal()

int32 date_cmp_timestamptz_internal ( DateADT  dateVal,
TimestampTz  dt2 
)

Definition at line 831 of file date.c.

832 {
833  TimestampTz dt1;
834  int overflow;
835 
836  dt1 = date2timestamptz_opt_overflow(dateVal, &overflow);
837  if (overflow > 0)
838  {
839  /* dt1 is larger than any finite timestamp, but less than infinity */
840  return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
841  }
842  if (overflow < 0)
843  {
844  /* dt1 is less than any finite timestamp, but more than -infinity */
845  return TIMESTAMP_IS_NOBEGIN(dt2) ? +1 : -1;
846  }
847 
848  return timestamptz_cmp_internal(dt1, dt2);
849 }
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:161
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:632
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:127

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

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

◆ DateADTGetDatum()

static Datum DateADTGetDatum ( DateADT  X)
inlinestatic

◆ DatumGetDateADT()

static DateADT DatumGetDateADT ( Datum  X)
inlinestatic

Definition at line 54 of file date.h.

55 {
56  return (DateADT) DatumGetInt32(X);
57 }
int32 DateADT
Definition: date.h:23
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202

References DatumGetInt32().

Referenced by compareDatetime(), convert_timevalue_to_scalar(), daterange_canonical(), gbt_num_compress(), JsonEncodeDateTime(), and map_sql_value_to_xml_value().

◆ DatumGetTimeADT()

static TimeADT DatumGetTimeADT ( Datum  X)
inlinestatic

Definition at line 60 of file date.h.

61 {
62  return (TimeADT) DatumGetInt64(X);
63 }
int64 TimeADT
Definition: date.h:25
static int64 DatumGetInt64(Datum X)
Definition: postgres.h:385

References DatumGetInt64().

Referenced by convert_timevalue_to_scalar(), gbt_num_compress(), and JsonEncodeDateTime().

◆ DatumGetTimeTzADTP()

static TimeTzADT* DatumGetTimeTzADTP ( Datum  X)
inlinestatic

Definition at line 66 of file date.h.

67 {
68  return (TimeTzADT *) DatumGetPointer(X);
69 }
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
Definition: date.h:28

References DatumGetPointer().

Referenced by convert_timevalue_to_scalar(), gbt_timetz_compress(), and JsonEncodeDateTime().

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 292 of file date.c.

293 {
294  if (DATE_IS_NOBEGIN(dt))
295  strcpy(str, EARLY);
296  else if (DATE_IS_NOEND(dt))
297  strcpy(str, LATE);
298  else /* shouldn't happen */
299  elog(ERROR, "invalid argument for EncodeSpecialDate");
300 }
#define EARLY
Definition: datetime.h:39
#define LATE
Definition: datetime.h:40

References DATE_IS_NOBEGIN, DATE_IS_NOEND, EARLY, elog(), ERROR, LATE, and generate_unaccent_rules::str.

Referenced by date_out(), and JsonEncodeDateTime().

◆ float_time_overflows()

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

Definition at line 1459 of file date.c.

1460 {
1461  /* Range-check the fields individually. */
1462  if (hour < 0 || hour > HOURS_PER_DAY ||
1463  min < 0 || min >= MINS_PER_HOUR)
1464  return true;
1465 
1466  /*
1467  * "sec", being double, requires extra care. Cope with NaN, and round off
1468  * before applying the range check to avoid unexpected errors due to
1469  * imprecise input. (We assume rint() behaves sanely with infinities.)
1470  */
1471  if (isnan(sec))
1472  return true;
1473  sec = rint(sec * USECS_PER_SEC);
1474  if (sec < 0 || sec > SECS_PER_MINUTE * USECS_PER_SEC)
1475  return true;
1476 
1477  /*
1478  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1479  * that the total time value doesn't exceed 24:00:00. This must match the
1480  * way that callers will convert the fields to a time.
1481  */
1482  if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1483  * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1484  return true;
1485 
1486  return false;
1487 }
#define MINS_PER_HOUR
Definition: timestamp.h:128
#define SECS_PER_MINUTE
Definition: timestamp.h:127
#define HOURS_PER_DAY
Definition: timestamp.h:117

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

Referenced by make_time(), and make_timestamp_internal().

◆ time2tm()

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

Definition at line 1496 of file date.c.

1497 {
1498  tm->tm_hour = time / USECS_PER_HOUR;
1499  time -= tm->tm_hour * USECS_PER_HOUR;
1500  tm->tm_min = time / USECS_PER_MINUTE;
1501  time -= tm->tm_min * USECS_PER_MINUTE;
1502  tm->tm_sec = time / USECS_PER_SEC;
1503  time -= tm->tm_sec * USECS_PER_SEC;
1504  *fsec = time;
1505  return 0;
1506 }
#define USECS_PER_HOUR
Definition: timestamp.h:131
#define USECS_PER_MINUTE
Definition: timestamp.h:132

References tm, 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_common(), and time_timetz().

◆ time_overflows()

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

Definition at line 1435 of file date.c.

1436 {
1437  /* Range-check the fields individually. */
1438  if (hour < 0 || hour > HOURS_PER_DAY ||
1439  min < 0 || min >= MINS_PER_HOUR ||
1440  sec < 0 || sec > SECS_PER_MINUTE ||
1441  fsec < 0 || fsec > USECS_PER_SEC)
1442  return true;
1443 
1444  /*
1445  * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1446  * that the total time value doesn't exceed 24:00:00.
1447  */
1448  if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1449  + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1450  return true;
1451 
1452  return false;
1453 }

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

Referenced by DecodeDateTime(), and DecodeTimeOnly().

◆ TimeADTGetDatum()

static Datum TimeADTGetDatum ( TimeADT  X)
inlinestatic

Definition at line 78 of file date.h.

79 {
80  return Int64GetDatum(X);
81 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1794

References Int64GetDatum().

Referenced by gbt_num_fetch(), leftmostvalue_time(), parse_datetime(), and sql_localtime().

◆ timetz2tm()

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

Definition at line 2403 of file date.c.

2404 {
2405  TimeOffset trem = time->time;
2406 
2407  tm->tm_hour = trem / USECS_PER_HOUR;
2408  trem -= tm->tm_hour * USECS_PER_HOUR;
2409  tm->tm_min = trem / USECS_PER_MINUTE;
2410  trem -= tm->tm_min * USECS_PER_MINUTE;
2411  tm->tm_sec = trem / USECS_PER_SEC;
2412  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2413 
2414  if (tzp != NULL)
2415  *tzp = time->zone;
2416 
2417  return 0;
2418 }
int64 TimeOffset
Definition: timestamp.h:40
TimeADT time
Definition: date.h:29
int32 zone
Definition: date.h:30

References TimeTzADT::time, tm, 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_common().

◆ TimeTzADTPGetDatum()

static Datum TimeTzADTPGetDatum ( const TimeTzADT X)
inlinestatic

Definition at line 84 of file date.h.

85 {
86  return PointerGetDatum(X);
87 }
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322

References PointerGetDatum().

Referenced by current_time(), leftmostvalue_timetz(), and parse_datetime().

◆ tm2time()

int tm2time ( struct pg_tm tm,
fsec_t  fsec,
TimeADT result 
)

Definition at line 1424 of file date.c.

1425 {
1426  *result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
1427  * USECS_PER_SEC) + fsec;
1428  return 0;
1429 }

References MINS_PER_HOUR, SECS_PER_MINUTE, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, and USECS_PER_SEC.

Referenced by parse_datetime(), sql_localtime(), and time_in().

◆ tm2timetz()

int tm2timetz ( struct pg_tm tm,
fsec_t  fsec,
int  tz,
TimeTzADT result 
)

Definition at line 2263 of file date.c.

2264 {
2265  result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
2266  USECS_PER_SEC) + fsec;
2267  result->zone = tz;
2268 
2269  return 0;
2270 }

References MINS_PER_HOUR, SECS_PER_MINUTE, TimeTzADT::time, tm, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_SEC, and TimeTzADT::zone.

Referenced by current_time(), parse_datetime(), timestamptz_timetz(), and timetz_in().