PostgreSQL Source Code git master
Loading...
Searching...
No Matches
date.h File Reference
#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 TIMETZ_TYPLEN   12
 
#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 TimeTzADT * DatumGetTimeTzADTP (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_safe (DateADT dateVal, Node *escontext)
 
TimestampTz date2timestamptz_safe (DateADT dateVal, Node *escontext)
 
DateADT timestamp2date_safe (Timestamp timestamp, Node *escontext)
 
DateADT timestamptz2date_safe (TimestampTz timestamp, Node *escontext)
 
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)
 
TimeTzADT * GetSQLCurrentTime (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 46 of file date.h.

◆ DATE_IS_NOEND

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

Definition at line 48 of file date.h.

◆ DATE_NOBEGIN

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

Definition at line 45 of file date.h.

◆ DATE_NOEND

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

Definition at line 47 of file date.h.

◆ DATE_NOT_FINITE

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

Definition at line 49 of file date.h.

◆ DATEVAL_NOBEGIN

#define DATEVAL_NOBEGIN   ((DateADT) PG_INT32_MIN)

Definition at line 42 of file date.h.

◆ DATEVAL_NOEND

#define DATEVAL_NOEND   ((DateADT) PG_INT32_MAX)

Definition at line 43 of file date.h.

◆ MAX_TIME_PRECISION

#define MAX_TIME_PRECISION   6

Definition at line 51 of file date.h.

◆ PG_GETARG_DATEADT

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

Definition at line 95 of file date.h.

◆ PG_GETARG_TIMEADT

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

Definition at line 96 of file date.h.

◆ PG_GETARG_TIMETZADT_P

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

Definition at line 97 of file date.h.

◆ PG_RETURN_DATEADT

#define PG_RETURN_DATEADT (   x)    return DateADTGetDatum(x)

Definition at line 99 of file date.h.

◆ PG_RETURN_TIMEADT

#define PG_RETURN_TIMEADT (   x)    return TimeADTGetDatum(x)

Definition at line 100 of file date.h.

◆ PG_RETURN_TIMETZADT_P

#define PG_RETURN_TIMETZADT_P (   x)    return TimeTzADTPGetDatum(x)

Definition at line 101 of file date.h.

◆ TIMETZ_TYPLEN

#define TIMETZ_TYPLEN   12

Definition at line 37 of file date.h.

Typedef Documentation

◆ DateADT

Definition at line 21 of file date.h.

◆ TimeADT

Definition at line 23 of file date.h.

Function Documentation

◆ AdjustTimeForTypmod()

void AdjustTimeForTypmod ( TimeADT *  time,
int32  typmod 
)
extern

Definition at line 1753 of file date.c.

1754{
1755 static const int64 TimeScales[MAX_TIME_PRECISION + 1] = {
1756 INT64CONST(1000000),
1757 INT64CONST(100000),
1758 INT64CONST(10000),
1759 INT64CONST(1000),
1760 INT64CONST(100),
1761 INT64CONST(10),
1762 INT64CONST(1)
1763 };
1764
1765 static const int64 TimeOffsets[MAX_TIME_PRECISION + 1] = {
1766 INT64CONST(500000),
1767 INT64CONST(50000),
1768 INT64CONST(5000),
1769 INT64CONST(500),
1770 INT64CONST(50),
1771 INT64CONST(5),
1772 INT64CONST(0)
1773 };
1774
1775 if (typmod >= 0 && typmod <= MAX_TIME_PRECISION)
1776 {
1777 if (*time >= INT64CONST(0))
1778 *time = ((*time + TimeOffsets[typmod]) / TimeScales[typmod]) *
1779 TimeScales[typmod];
1780 else
1781 *time = -((((-*time) + TimeOffsets[typmod]) / TimeScales[typmod]) *
1782 TimeScales[typmod]);
1783 }
1784}
#define INT64CONST(x)
Definition c.h:689
int64_t int64
Definition c.h:680
#define MAX_TIME_PRECISION
Definition date.h:51
static int fb(int x)

References fb(), 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 
)
extern

Definition at line 65 of file date.c.

66{
67 if (typmod < 0)
70 errmsg("TIME(%d)%s precision must not be negative",
71 typmod, (istz ? " WITH TIME ZONE" : ""))));
72 if (typmod > MAX_TIME_PRECISION)
73 {
76 errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
77 typmod, (istz ? " WITH TIME ZONE" : ""),
79 typmod = MAX_TIME_PRECISION;
80 }
81
82 return typmod;
83}
int errcode(int sqlerrcode)
Definition elog.c:875
#define WARNING
Definition elog.h:37
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg

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

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

◆ date2timestamp_no_overflow()

double date2timestamp_no_overflow ( DateADT  dateVal)
extern

Definition at line 741 of file date.c.

742{
743 double result;
744
746 result = -DBL_MAX;
747 else if (DATE_IS_NOEND(dateVal))
748 result = DBL_MAX;
749 else
750 {
751 /* date is days since 2000, timestamp is microseconds since same... */
753 }
754
755 return result;
756}
uint32 result
#define USECS_PER_DAY
Definition timestamp.h:131
#define DATE_IS_NOEND(j)
Definition date.h:48
#define DATE_IS_NOBEGIN(j)
Definition date.h:46

References DATE_IS_NOBEGIN, DATE_IS_NOEND, fb(), result, and USECS_PER_DAY.

Referenced by convert_timevalue_to_scalar().

◆ date2timestamp_safe()

Timestamp date2timestamp_safe ( DateADT  dateVal,
Node *  escontext 
)
extern

Definition at line 627 of file date.c.

628{
630
633 else if (DATE_IS_NOEND(dateVal))
635 else
636 {
637 /*
638 * Since dates have the same minimum values as timestamps, only upper
639 * boundary need be checked for overflow.
640 */
642 {
644 ereturn(escontext, result,
646 errmsg("date out of range for timestamp")));
647 }
648
649 /* date is days since 2000, timestamp is microseconds since same... */
651 }
652
653 return result;
654}
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
#define ereturn(context, dummy_value,...)
Definition elog.h:280

References DATE_IS_NOBEGIN, DATE_IS_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, TIMESTAMP_END_JULIAN, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, and USECS_PER_DAY.

Referenced by cvt_date_timestamp(), date2timestamp(), date_cmp_timestamp_internal(), and date_timestamp().

◆ date2timestamptz_safe()

TimestampTz date2timestamptz_safe ( DateADT  dateVal,
Node *  escontext 
)
extern

Definition at line 676 of file date.c.

677{
679 struct pg_tm tt,
680 *tm = &tt;
681 int tz;
682
685 else if (DATE_IS_NOEND(dateVal))
687 else
688 {
689 /*
690 * Since dates have the same minimum values as timestamps, only upper
691 * boundary need be checked for overflow.
692 */
694 {
696 ereturn(escontext, result,
698 errmsg("date out of range for timestamp")));
699 }
700
702 &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
703 tm->tm_hour = 0;
704 tm->tm_min = 0;
705 tm->tm_sec = 0;
707
709
710 /*
711 * Since it is possible to go beyond allowed timestamptz range because
712 * of time zone, check for allowed timestamp range after adding tz.
713 */
715 {
716 if (result < MIN_TIMESTAMP)
718 else
720
721 ereturn(escontext, result,
723 errmsg("date out of range for timestamp")));
724 }
725 }
726
727 return result;
728}
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition datetime.c:1608
void j2date(int jd, int *year, int *month, int *day)
Definition datetime.c:322
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:148
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(), ereturn, errcode(), errmsg, fb(), IS_VALID_TIMESTAMP, j2date(), MIN_TIMESTAMP, POSTGRES_EPOCH_JDATE, result, 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 cvt_date_timestamptz(), date_cmp_timestamptz_internal(), and date_timestamptz().

◆ date_cmp_timestamp_internal()

int32 date_cmp_timestamp_internal ( DateADT  dateVal,
Timestamp  dt2 
)
extern

Definition at line 764 of file date.c.

765{
768
769 dt1 = date2timestamp_safe(dateVal, (Node *) &escontext);
770 if (escontext.error_occurred)
771 {
772 Assert(TIMESTAMP_IS_NOEND(dt1)); /* NOBEGIN case cannot occur */
773
774 /* dt1 is larger than any finite timestamp, but less than infinity */
775 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
776 }
777
779}
int timestamp_cmp_internal(Timestamp dt1, Timestamp dt2)
Definition timestamp.c:2222
#define Assert(condition)
Definition c.h:1002
#define TIMESTAMP_IS_NOEND(j)
Definition timestamp.h:167
Timestamp date2timestamp_safe(DateADT dateVal, Node *escontext)
Definition date.c:627
Definition nodes.h:133

References Assert, date2timestamp_safe(), ErrorSaveContext::error_occurred, fb(), 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 
)
extern

Definition at line 845 of file date.c.

846{
849
850 dt1 = date2timestamptz_safe(dateVal, (Node *) &escontext);
851
852 if (escontext.error_occurred)
853 {
855 {
856 /* dt1 is larger than any finite timestamp, but less than infinity */
857 return TIMESTAMP_IS_NOEND(dt2) ? -1 : +1;
858 }
860 {
861 /* dt1 is less than any finite timestamp, but more than -infinity */
862 return TIMESTAMP_IS_NOBEGIN(dt2) ? +1 : -1;
863 }
864 }
865
867}
#define TIMESTAMP_IS_NOBEGIN(j)
Definition timestamp.h:162
TimestampTz date2timestamptz_safe(DateADT dateVal, Node *escontext)
Definition date.c:676
#define timestamptz_cmp_internal(dt1, dt2)
Definition timestamp.h:143

References date2timestamptz_safe(), ErrorSaveContext::error_occurred, fb(), 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 66 of file date.h.

67{
68 return (TimeADT) DatumGetInt64(X);
69}
int64 TimeADT
Definition date.h:23
static int64 DatumGetInt64(Datum X)
Definition postgres.h:416

References DatumGetInt64(), and fb().

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

◆ DatumGetTimeTzADTP()

static TimeTzADT * DatumGetTimeTzADTP ( Datum  X)
inlinestatic

Definition at line 72 of file date.h.

73{
74 return (TimeTzADT *) DatumGetPointer(X);
75}
static Pointer DatumGetPointer(Datum X)
Definition postgres.h:332

References DatumGetPointer(), and fb().

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

◆ EncodeSpecialDate()

void EncodeSpecialDate ( DateADT  dt,
char *  str 
)
extern

Definition at line 297 of file date.c.

298{
299 if (DATE_IS_NOBEGIN(dt))
300 strcpy(str, EARLY);
301 else if (DATE_IS_NOEND(dt))
302 strcpy(str, LATE);
303 else /* shouldn't happen */
304 elog(ERROR, "invalid argument for EncodeSpecialDate");
305}
#define elog(elevel,...)
Definition elog.h:228
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, fb(), LATE, and str.

Referenced by date_out(), and JsonEncodeDateTime().

◆ float_time_overflows()

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

Definition at line 1555 of file date.c.

1556{
1557 /* Range-check the fields individually. */
1560 return true;
1561
1562 /*
1563 * "sec", being double, requires extra care. Cope with NaN, and round off
1564 * before applying the range check to avoid unexpected errors due to
1565 * imprecise input. (We assume rint() behaves sanely with infinities.)
1566 */
1567 if (isnan(sec))
1568 return true;
1569 sec = rint(sec * USECS_PER_SEC);
1571 return true;
1572
1573 /*
1574 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1575 * that the total time value doesn't exceed 24:00:00. This must match the
1576 * way that callers will convert the fields to a time.
1577 */
1578 if (((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1579 * USECS_PER_SEC) + (int64) sec) > USECS_PER_DAY)
1580 return true;
1581
1582 return false;
1583}
#define MINS_PER_HOUR
Definition timestamp.h:129
#define SECS_PER_MINUTE
Definition timestamp.h:128
#define HOURS_PER_DAY
Definition timestamp.h:118
#define min(a, b)
Definition private.h:155

References fb(), HOURS_PER_DAY, min, 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  )
extern

Definition at line 312 of file date.c.

313{
314 struct pg_tm tm;
315
316 static int cache_year = 0;
317 static int cache_mon = 0;
318 static int cache_mday = 0;
319 static DateADT cache_date;
320
322
323 /*
324 * date2j involves several integer divisions; moreover, unless our session
325 * lives across local midnight, we don't really have to do it more than
326 * once. So it seems worth having a separate cache here.
327 */
328 if (tm.tm_year != cache_year ||
329 tm.tm_mon != cache_mon ||
331 {
336 }
337
338 return cache_date;
339}
void GetCurrentDateTime(struct pg_tm *tm)
Definition datetime.c:377
int date2j(int year, int month, int day)
Definition datetime.c:297

References date2j(), fb(), 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)
extern

Definition at line 345 of file date.c.

346{
348 struct pg_tm tt,
349 *tm = &tt;
350 fsec_t fsec;
351 int tz;
352
353 GetCurrentTimeUsec(tm, &fsec, &tz);
354
356 tm2timetz(tm, fsec, tz, result);
357 AdjustTimeForTypmod(&(result->time), typmod);
358 return result;
359}
void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition datetime.c:398
int32 fsec_t
Definition timestamp.h:41
int tm2timetz(struct pg_tm *tm, fsec_t fsec, int tz, TimeTzADT *result)
Definition date.c:2382
void AdjustTimeForTypmod(TimeADT *time, int32 typmod)
Definition date.c:1753
#define palloc_object(type)
Definition fe_memutils.h:89

References AdjustTimeForTypmod(), fb(), GetCurrentTimeUsec(), palloc_object, result, tm, and tm2timetz().

Referenced by ExecEvalSQLValueFunction().

◆ GetSQLLocalTime()

TimeADT GetSQLLocalTime ( int32  typmod)
extern

Definition at line 365 of file date.c.

366{
368 struct pg_tm tt,
369 *tm = &tt;
370 fsec_t fsec;
371 int tz;
372
373 GetCurrentTimeUsec(tm, &fsec, &tz);
374
375 tm2time(tm, fsec, &result);
376 AdjustTimeForTypmod(&result, typmod);
377 return result;
378}
int tm2time(struct pg_tm *tm, fsec_t fsec, TimeADT *result)
Definition date.c:1518

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

Referenced by ExecEvalSQLValueFunction().

◆ time2tm()

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

Definition at line 1593 of file date.c.

1594{
1595 tm->tm_hour = time / USECS_PER_HOUR;
1596 time -= tm->tm_hour * USECS_PER_HOUR;
1597 tm->tm_min = time / USECS_PER_MINUTE;
1598 time -= tm->tm_min * USECS_PER_MINUTE;
1599 tm->tm_sec = time / USECS_PER_SEC;
1600 time -= tm->tm_sec * USECS_PER_SEC;
1601 *fsec = time;
1602 return 0;
1603}
#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 
)
extern

Definition at line 1530 of file date.c.

1531{
1532 /* Range-check the fields individually. */
1537 return true;
1538
1539 /*
1540 * Because we allow, eg, hour = 24 or sec = 60, we must check separately
1541 * that the total time value doesn't exceed 24:00:00.
1542 */
1543 if ((((((hour * MINS_PER_HOUR + min) * SECS_PER_MINUTE)
1544 + sec) * USECS_PER_SEC) + fsec) > USECS_PER_DAY)
1545 return true;
1546
1547 return false;
1548}

References fb(), HOURS_PER_DAY, min, MINS_PER_HOUR, SECS_PER_MINUTE, USECS_PER_DAY, and USECS_PER_SEC.

Referenced by DecodeDateTime(), and DecodeTimeOnly().

◆ TimeADTGetDatum()

◆ timestamp2date_safe()

DateADT timestamp2date_safe ( Timestamp  timestamp,
Node *  escontext 
)
extern

Definition at line 1356 of file date.c.

1357{
1359 struct pg_tm tt,
1360 *tm = &tt;
1361 fsec_t fsec;
1362
1365 else if (TIMESTAMP_IS_NOEND(timestamp))
1367 else
1368 {
1369 if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
1370 {
1371 if (timestamp < 0)
1373 else
1374 DATE_NOEND(result); /* not actually reachable */
1375
1376 ereturn(escontext, result,
1378 errmsg("timestamp out of range")));
1379 }
1380
1382 }
1383
1384 return result;
1385}
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition timestamp.c:1918
#define DATE_NOEND(j)
Definition date.h:47
#define DATE_NOBEGIN(j)
Definition date.h:45
int64 timestamp

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by cvt_timestamp_date(), and timestamp_date().

◆ timestamptz2date_safe()

DateADT timestamptz2date_safe ( TimestampTz  timestamp,
Node *  escontext 
)
extern

Definition at line 1437 of file date.c.

1438{
1440 struct pg_tm tt,
1441 *tm = &tt;
1442 fsec_t fsec;
1443 int tz;
1444
1447 else if (TIMESTAMP_IS_NOEND(timestamp))
1449 else
1450 {
1451 if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
1452 {
1453 if (timestamp < 0)
1455 else
1456 DATE_NOEND(result); /* not actually reachable */
1457
1458 ereturn(escontext, result,
1460 errmsg("timestamp out of range")));
1461 }
1462
1464 }
1465
1466 return result;
1467}

References date2j(), DATE_NOBEGIN, DATE_NOEND, ereturn, errcode(), errmsg, fb(), POSTGRES_EPOCH_JDATE, result, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, pg_tm::tm_mday, pg_tm::tm_mon, and pg_tm::tm_year.

Referenced by cvt_timestamptz_date(), and timestamptz_date().

◆ timetz2tm()

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

Definition at line 2523 of file date.c.

2524{
2525 TimeOffset trem = time->time;
2526
2532 *fsec = trem - tm->tm_sec * USECS_PER_SEC;
2533
2534 if (tzp != NULL)
2535 *tzp = time->zone;
2536
2537 return 0;
2538}
int64 TimeOffset
Definition timestamp.h:40
TimeADT time
Definition date.h:27
int32 zone
Definition date.h:28

References fb(), 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 90 of file date.h.

91{
92 return PointerGetDatum(X);
93}
#define PointerGetDatum(X)
Definition postgres.h:354

References fb(), and PointerGetDatum.

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

◆ tm2time()

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

Definition at line 1518 of file date.c.

1519{
1521 * USECS_PER_SEC) + fsec;
1522 return 0;
1523}

References MINS_PER_HOUR, result, 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 
)
extern

Definition at line 2382 of file date.c.

2383{
2384 result->time = ((((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec) *
2385 USECS_PER_SEC) + fsec;
2386 result->zone = tz;
2387
2388 return 0;
2389}

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

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