PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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)
 
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)
 
int32 date_cmp_timestamp_internal (DateADT dateVal, Timestamp dt2)
 
int32 date_cmp_timestamptz_internal (DateADT dateVal, TimestampTz dt2)
 
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)
 
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 1710 of file date.c.

1711{
1712 static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1713 INT64CONST(1000000),
1714 INT64CONST(100000),
1715 INT64CONST(10000),
1716 INT64CONST(1000),
1717 INT64CONST(100),
1718 INT64CONST(10),
1719 INT64CONST(1)
1720 };
1721
1722 static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1723 INT64CONST(500000),
1724 INT64CONST(50000),
1725 INT64CONST(5000),
1726 INT64CONST(500),
1727 INT64CONST(50),
1728 INT64CONST(5),
1729 INT64CONST(0)
1730 };
1731
1732 if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1733 {
1734 if (*time >= INT64CONST(0))
1735 *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1736 TimeScales[typmod];
1737 else
1738 *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1739 TimeScales[typmod]);
1740 }
1741}
#define INT64CONST(x)
Definition: c.h:516
int64_t int64
Definition: c.h:499
#define MAX_TIME_PRECISION
Definition: date.h:45

References INT64CONST, and MAX_TIME_PRECISION.

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

◆ anytime_typmod_check()

int32 anytime_typmod_check ( bool  istz,
int32  typmod 
)

Definition at line 72 of file date.c.

73{
74 if (typmod < 0)
76 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
77 errmsg("TIME(%d)%s precision must not be negative",
78 typmod, (istz ? " WITH TIME ZONE" : ""))));
79 if (typmod > MAX_TIME_PRECISION)
80 {
82 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
83 errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
84 typmod, (istz ? " WITH TIME ZONE" : ""),
86 typmod = MAX_TIME_PRECISION;
87 }
88
89 return typmod;
90}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define WARNING
Definition: elog.h:36
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149

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

Referenced by anytime_typmodin(), executeDateTimeMethod(), and transformSQLValueFunction().

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)

Definition at line 785 of file date.c.

786{
787 double result;
788
789 if (DATE_IS_NOBEGIN(dateVal))
790 result = -DBL_MAX;
791 else if (DATE_IS_NOEND(dateVal))
792 result = DBL_MAX;
793 else
794 {
795 /* date is days since 2000, timestamp is microseconds since same... */
796 result = dateVal * (double) USECS_PER_DAY;
797 }
798
799 return result;
800}
#define USECS_PER_DAY
Definition: timestamp.h:131
#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 629 of file date.c.

630{
631 Timestamp result;
632
633 if (overflow)
634 *overflow = 0;
635
636 if (DATE_IS_NOBEGIN(dateVal))
637 TIMESTAMP_NOBEGIN(result);
638 else if (DATE_IS_NOEND(dateVal))
639 TIMESTAMP_NOEND(result);
640 else
641 {
642 /*
643 * Since dates have the same minimum values as timestamps, only upper
644 * boundary need be checked for overflow.
645 */
647 {
648 if (overflow)
649 {
650 *overflow = 1;
651 TIMESTAMP_NOEND(result);
652 return result;
653 }
654 else
655 {
657 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
658 errmsg("date out of range for timestamp")));
659 }
660 }
661
662 /* date is days since 2000, timestamp is microseconds since same... */
663 result = dateVal * USECS_PER_DAY;
664 }
665
666 return result;
667}
int64 Timestamp
Definition: timestamp.h:38
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:159
#define TIMESTAMP_END_JULIAN
Definition: timestamp.h:253
#define POSTGRES_EPOCH_JDATE
Definition: timestamp.h:235
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:164

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

690{
691 TimestampTz result;
692 struct pg_tm tt,
693 *tm = &tt;
694 int tz;
695
696 if (overflow)
697 *overflow = 0;
698
699 if (DATE_IS_NOBEGIN(dateVal))
700 TIMESTAMP_NOBEGIN(result);
701 else if (DATE_IS_NOEND(dateVal))
702 TIMESTAMP_NOEND(result);
703 else
704 {
705 /*
706 * Since dates have the same minimum values as timestamps, only upper
707 * boundary need be checked for overflow.
708 */
710 {
711 if (overflow)
712 {
713 *overflow = 1;
714 TIMESTAMP_NOEND(result);
715 return result;
716 }
717 else
718 {
720 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
721 errmsg("date out of range for timestamp")));
722 }
723 }
724
726 &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
727 tm->tm_hour = 0;
728 tm->tm_min = 0;
729 tm->tm_sec = 0;
731
732 result = dateVal * USECS_PER_DAY + tz * USECS_PER_SEC;
733
734 /*
735 * Since it is possible to go beyond allowed timestamptz range because
736 * of time zone, check for allowed timestamp range after adding tz.
737 */
738 if (!IS_VALID_TIMESTAMP(result))
739 {
740 if (overflow)
741 {
742 if (result < MIN_TIMESTAMP)
743 {
744 *overflow = -1;
745 TIMESTAMP_NOBEGIN(result);
746 }
747 else
748 {
749 *overflow = 1;
750 TIMESTAMP_NOEND(result);
751 }
752 }
753 else
754 {
756 (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
757 errmsg("date out of range for timestamp")));
758 }
759 }
760 }
761
762 return result;
763}
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1595
void j2date(int jd, int *year, int *month, int *day)
Definition: datetime.c:321
int64 TimestampTz
Definition: timestamp.h:39
#define IS_VALID_TIMESTAMP(t)
Definition: timestamp.h:267
#define USECS_PER_SEC
Definition: timestamp.h:134
#define MIN_TIMESTAMP
Definition: timestamp.h:256
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 808 of file date.c.

809{
810 Timestamp dt1;
811 int overflow;
812
813 dt1 = date2timestamp_opt_overflow(dateVal, &overflow);
814 if (overflow > 0)
815 {
816 /* dt1 is larger than any finite timestamp, but less than infinity */
817 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
818 }
819 Assert(overflow == 0); /* -1 case cannot occur */
820
821 return timestamp_cmp_internal(dt1, dt2);
822}
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition: timestamp.c:2210
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:167
Timestamp date2timestamp_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:629
Assert(PointerIsAligned(start, uint64))

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

889{
890 TimestampTz dt1;
891 int overflow;
892
893 dt1 = date2timestamptz_opt_overflow(dateVal, &overflow);
894 if (overflow > 0)
895 {
896 /* dt1 is larger than any finite timestamp, but less than infinity */
897 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
898 }
899 if (overflow < 0)
900 {
901 /* dt1 is less than any finite timestamp, but more than -infinity */
902 return TIMESTAMP_IS_NOBEGIN(dt2) ? +1 : -1;
903 }
904
905 return timestamptz_cmp_internal(dt1, dt2);
906}
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:162
TimestampTz date2timestamptz_opt_overflow(DateADT dateVal, int *overflow)
Definition: date.c:689
#define timestamptz_cmp_internal(dt1, dt2)
Definition: timestamp.h:143

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

◆ DatumGetDateADT()

static DateADT DatumGetDateADT ( Datum  X)
inlinestatic

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

References DatumGetInt64().

Referenced by convert_timevalue_to_scalar(), executeDateTimeMethod(), 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:317
Definition: date.h:28

References DatumGetPointer().

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

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)

Definition at line 302 of file date.c.

303{
304 if (DATE_IS_NOBEGIN(dt))
305 strcpy(str, EARLY);
306 else if (DATE_IS_NOEND(dt))
307 strcpy(str, LATE);
308 else /* shouldn't happen */
309 elog(ERROR, "invalid argument for EncodeSpecialDate");
310}
#define elog(elevel,...)
Definition: elog.h:226
const char * str
#define EARLY
Definition: datetime.h:39
#define LATE
Definition: datetime.h:40

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

Referenced by date_out(), and JsonEncodeDateTime().

◆ float_time_overflows()

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

Definition at line 1516 of file date.c.

1517{
1518 /* Range-check the fields individually. */
1519 if (hour < 0 || hour > HOURS_PER_DAY ||
1520 min < 0 || min >= MINS_PER_HOUR)
1521 return true;
1522
1523 /*
1524 * "sec", being double, requires extra care. Cope with NaN, and round off
1525 * before applying the range check to avoid unexpected errors due to
1526 * imprecise input. (We assume rint() behaves sanely with infinities.)
1527 */
1528 if (isnan(sec))
1529 return true;
1530 sec = rint(sec * USECS_PER_SEC);
1531 if (sec < 0 || sec > SECS_PER_MINUTE * USECS_PER_SEC)
1532 return true;
1533
1534 /*
1535 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1536 * that the total time value doesn't exceed 24:00:00. This must match the
1537 * way that callers will convert the fields to a time.
1538 */
1539 if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1540 * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1541 return true;
1542
1543 return false;
1544}
#define MINS_PER_HOUR
Definition: timestamp.h:129
#define SECS_PER_MINUTE
Definition: timestamp.h:128
#define HOURS_PER_DAY
Definition: timestamp.h:118

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

◆ GetSQLCurrentDate()

DateADT GetSQLCurrentDate ( void  )

Definition at line 317 of file date.c.

318{
319 struct pg_tm tm;
320
321 static int cache_year = 0;
322 static int cache_mon = 0;
323 static int cache_mday = 0;
324 static DateADT cache_date;
325
327
328 /*
329 * date2j involves several integer divisions; moreover, unless our session
330 * lives across local midnight, we don't really have to do it more than
331 * once. So it seems worth having a separate cache here.
332 */
333 if (tm.tm_year != cache_year ||
334 tm.tm_mon != cache_mon ||
335 tm.tm_mday != cache_mday)
336 {
338 cache_year = tm.tm_year;
339 cache_mon = tm.tm_mon;
340 cache_mday = tm.tm_mday;
341 }
342
343 return cache_date;
344}
void GetCurrentDateTime(struct pg_tm *tm)
Definition: datetime.c:376
int date2j(int year, int month, int day)
Definition: datetime.c:296

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

Referenced by ExecEvalSQLValueFunction().

◆ GetSQLCurrentTime()

TimeTzADT * GetSQLCurrentTime ( int32  typmod)

Definition at line 350 of file date.c.

351{
352 TimeTzADT *result;
353 struct pg_tm tt,
354 *tm = &tt;
355 fsec_t fsec;
356 int tz;
357
358 GetCurrentTimeUsec(tm, &fsec, &tz);
359
360 result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
361 tm2timetz(tm, fsec, tz, result);
362 AdjustTimeForTypmod(&(result->time), typmod);
363 return result;
364}
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:397
int32 fsec_t
Definition: timestamp.h:41
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition: date.c:2328
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition: date.c:1710
void * palloc(Size size)
Definition: mcxt.c:1940
TimeADT time
Definition: date.h:29

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

Referenced by ExecEvalSQLValueFunction().

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)

Definition at line 370 of file date.c.

371{
372 TimeADT result;
373 struct pg_tm tt,
374 *tm = &tt;
375 fsec_t fsec;
376 int tz;
377
378 GetCurrentTimeUsec(tm, &fsec, &tz);
379
380 tm2time(tm, fsec, &result);
381 AdjustTimeForTypmod(&result, typmod);
382 return result;
383}
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition: date.c:1481

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

Referenced by ExecEvalSQLValueFunction().

◆ time2tm()

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

Definition at line 1553 of file date.c.

1554{
1555 tm->tm_hour = time / USECS_PER_HOUR;
1556 time -= tm->tm_hour * USECS_PER_HOUR;
1557 tm->tm_min = time / USECS_PER_MINUTE;
1558 time -= tm->tm_min * USECS_PER_MINUTE;
1559 tm->tm_sec = time / USECS_PER_SEC;
1560 time -= tm->tm_sec * USECS_PER_SEC;
1561 *fsec = time;
1562 return 0;
1563}
#define USECS_PER_HOUR
Definition: timestamp.h:132
#define USECS_PER_MINUTE
Definition: timestamp.h:133

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

1493{
1494 /* Range-check the fields individually. */
1495 if (hour < 0 || hour > HOURS_PER_DAY ||
1496 min < 0 || min >= MINS_PER_HOUR ||
1497 sec < 0 || sec > SECS_PER_MINUTE ||
1498 fsec < 0 || fsec > USECS_PER_SEC)
1499 return true;
1500
1501 /*
1502 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1503 * that the total time value doesn't exceed 24:00:00.
1504 */
1505 if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1506 + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1507 return true;
1508
1509 return false;
1510}

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:1807

References Int64GetDatum().

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

◆ timetz2tm()

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

Definition at line 2468 of file date.c.

2469{
2470 TimeOffset trem = time->time;
2471
2472 tm->tm_hour = trem / USECS_PER_HOUR;
2473 trem -= tm->tm_hour * USECS_PER_HOUR;
2474 tm->tm_min = trem / USECS_PER_MINUTE;
2475 trem -= tm->tm_min * USECS_PER_MINUTE;
2476 tm->tm_sec = trem / USECS_PER_SEC;
2477 *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2478
2479 if (tzp != NULL)
2480 *tzp = time->zone;
2481
2482 return 0;
2483}
int64 TimeOffset
Definition: timestamp.h:40
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:327

References PointerGetDatum().

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

◆ tm2time()

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

Definition at line 1481 of file date.c.

1482{
1483 *result = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec)
1484 * USECS_PER_SEC) + fsec;
1485 return 0;
1486}

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 GetSQLLocalTime(), parse_datetime(), and time_in().

◆ tm2timetz()

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

Definition at line 2328 of file date.c.

2329{
2330 result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
2331 USECS_PER_SEC) + fsec;
2332 result->zone = tz;
2333
2334 return 0;
2335}

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 GetSQLCurrentTime(), parse_datetime(), timestamptz_timetz(), and timetz_in().