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 DatumGetDateADT(X)   ((DateADT) DatumGetInt32(X))
 
#define DatumGetTimeADT(X)   ((TimeADT) DatumGetInt64(X))
 
#define DatumGetTimeTzADTP(X)   ((TimeTzADT *) DatumGetPointer(X))
 
#define DateADTGetDatum(X)   Int32GetDatum(X)
 
#define TimeADTGetDatum(X)   Int64GetDatum(X)
 
#define TimeTzADTPGetDatum(X)   PointerGetDatum(X)
 
#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

int32 anytime_typmod_check (bool istz, int32 typmod)
 
double date2timestamp_no_overflow (DateADT dateVal)
 
Timestamp date2timestamp_opt_overflow (DateADT dateVal, int *overflow)
 
TimestampTz date2timestamptz_opt_overflow (DateADT dateVal, int *overflow)
 
void EncodeSpecialDate (DateADT dt, char *str)
 
DateADT GetSQLCurrentDate (void)
 
TimeTzADTGetSQLCurrentTime (int32 typmod)
 
TimeADT GetSQLLocalTime (int32 typmod)
 
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)
 
void AdjustTimeForTypmod (TimeADT *time, int32 typmod)
 

Macro Definition Documentation

◆ DATE_IS_NOBEGIN

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

◆ DATE_IS_NOEND

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

◆ DATE_NOBEGIN

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

Definition at line 39 of file date.h.

Referenced by date_in(), timestamp_date(), and timestamptz_date().

◆ DATE_NOEND

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

Definition at line 41 of file date.h.

Referenced by date_in(), timestamp_date(), and timestamptz_date().

◆ DATE_NOT_FINITE

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

◆ DateADTGetDatum

◆ DATEVAL_NOBEGIN

#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)

Definition at line 36 of file date.h.

Referenced by leftmostvalue_date().

◆ DATEVAL_NOEND

#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)

Definition at line 37 of file date.h.

◆ DatumGetDateADT

◆ DatumGetTimeADT

#define DatumGetTimeADT (   X)    ((TimeADT) DatumGetInt64(X))

Definition at line 54 of file date.h.

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

◆ DatumGetTimeTzADTP

#define DatumGetTimeTzADTP (   X)    ((TimeTzADT *) DatumGetPointer(X))

Definition at line 55 of file date.h.

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

◆ MAX_TIME_PRECISION

#define MAX_TIME_PRECISION   6

Definition at line 51 of file date.h.

Referenced by AdjustTimeForTypmod(), anytime_typmod_check(), EncodeTimeOnly(), and time_support().

◆ PG_GETARG_DATEADT

◆ PG_GETARG_TIMEADT

◆ PG_GETARG_TIMETZADT_P

◆ PG_RETURN_DATEADT

#define PG_RETURN_DATEADT (   x)    return DateADTGetDatum(x)

◆ PG_RETURN_TIMEADT

◆ PG_RETURN_TIMETZADT_P

◆ TimeADTGetDatum

#define TimeADTGetDatum (   X)    Int64GetDatum(X)

Definition at line 58 of file date.h.

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

◆ TimeTzADTPGetDatum

#define TimeTzADTPGetDatum (   X)    PointerGetDatum(X)

Definition at line 59 of file date.h.

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

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

References MAX_TIME_PRECISION.

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

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

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 67 of file date.c.

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

Referenced by anytime_typmodin(), and transformSQLValueFunction().

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

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 707 of file date.c.

References DATE_IS_NOBEGIN, DATE_IS_NOEND, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

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

◆ date2timestamp_opt_overflow()

Timestamp date2timestamp_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 562 of file date.c.

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

Referenced by cmpDateToTimestamp(), and date2timestamp().

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

◆ date2timestamptz_opt_overflow()

TimestampTz date2timestamptz_opt_overflow ( DateADT  dateVal,
int *  overflow 
)

Definition at line 616 of file date.c.

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

Referenced by cmpDateToTimestampTz(), and date2timestamptz().

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

◆ 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:228
#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:608
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:782
int date2j(int y, int m, int d)
Definition: datetime.c:269
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:822
#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:608
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:108
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2020
#define ERROR
Definition: elog.h:43
int32 fsec_t
Definition: timestamp.h:41
#define ereport(elevel, rest)
Definition: elog.h:141
TimestampTz GetCurrentTransactionStartTimestamp(void)
Definition: xact.c:782
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
Definition: date.h:27
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1442

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 347 of file date.c.

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

Referenced by ExecEvalSQLValueFunction().

348 {
349  TimeADT result;
350  TimestampTz ts;
351  struct pg_tm tt,
352  *tm = &tt;
353  fsec_t fsec;
354  int tz;
355 
357 
358  if (timestamp2tm(ts, &tz, tm, &fsec, NULL, NULL) != 0)
359  ereport(ERROR,
360  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
361  errmsg("timestamp out of range")));
362 
363  tm2time(tm, fsec, &result);
364  AdjustTimeForTypmod(&result, typmod);
365  return result;
366 }
int64 TimestampTz
Definition: timestamp.h:39
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1791
int errcode(int sqlerrcode)
Definition: elog.c:608
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:782
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1266
int errmsg(const char *fmt,...)
Definition: elog.c:822
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1442

◆ time2tm()

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

Definition at line 1281 of file date.c.

References pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, and USECS_PER_SEC.

Referenced by JsonEncodeDateTime(), time_out(), time_part(), and time_timetz().

1282 {
1283  tm->tm_hour = time / USECS_PER_HOUR;
1284  time -= tm->tm_hour * USECS_PER_HOUR;
1285  tm->tm_min = time / USECS_PER_MINUTE;
1286  time -= tm->tm_min * USECS_PER_MINUTE;
1287  tm->tm_sec = time / USECS_PER_SEC;
1288  time -= tm->tm_sec * USECS_PER_SEC;
1289  *fsec = time;
1290  return 0;
1291 }
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define USECS_PER_MINUTE
Definition: timestamp.h:93
#define USECS_PER_HOUR
Definition: timestamp.h:92
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ timetz2tm()

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

Definition at line 2154 of file date.c.

References TimeTzADT::time, pg_tm::tm_hour, pg_tm::tm_min, pg_tm::tm_sec, USECS_PER_HOUR, USECS_PER_MINUTE, USECS_PER_SEC, and TimeTzADT::zone.

Referenced by JsonEncodeDateTime(), timetz_out(), and timetz_part().

2155 {
2156  TimeOffset trem = time->time;
2157 
2158  tm->tm_hour = trem / USECS_PER_HOUR;
2159  trem -= tm->tm_hour * USECS_PER_HOUR;
2160  tm->tm_min = trem / USECS_PER_MINUTE;
2161  trem -= tm->tm_min * USECS_PER_MINUTE;
2162  tm->tm_sec = trem / USECS_PER_SEC;
2163  *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2164 
2165  if (tzp != NULL)
2166  *tzp = time->zone;
2167 
2168  return 0;
2169 }
TimeADT time
Definition: date.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define USECS_PER_MINUTE
Definition: timestamp.h:93
int32 zone
Definition: date.h:30
#define USECS_PER_HOUR
Definition: timestamp.h:92
int64 TimeOffset
Definition: timestamp.h:40
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ tm2time()

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

Definition at line 1266 of file date.c.

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

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

1267 {
1268  *result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
1269  * USECS_PER_SEC) + fsec;
1270  return 0;
1271 }
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28

◆ tm2timetz()

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

Definition at line 2020 of file date.c.

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

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

2021 {
2022  result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
2023  USECS_PER_SEC) + fsec;
2024  result->zone = tz;
2025 
2026  return 0;
2027 }
TimeADT time
Definition: date.h:29
#define USECS_PER_SEC
Definition: timestamp.h:94
int tm_hour
Definition: pgtime.h:29
#define MINS_PER_HOUR
Definition: timestamp.h:89
int32 zone
Definition: date.h:30
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28