#include <limits.h>
#include "fmgr.h"
#include "pgtime.h"
Go to the source code of this file.
Data Structures | |
struct | TimeIntervalData |
Defines | |
#define | DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X)) |
#define | DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X)) |
#define | DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X)) |
#define | AbsoluteTimeGetDatum(X) Int32GetDatum(X) |
#define | RelativeTimeGetDatum(X) Int32GetDatum(X) |
#define | TimeIntervalGetDatum(X) PointerGetDatum(X) |
#define | PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n)) |
#define | PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n)) |
#define | PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n)) |
#define | PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x) |
#define | PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x) |
#define | PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x) |
#define | INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) |
#define | NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) |
#define | NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) |
#define | INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) |
#define | AbsoluteTimeIsValid(time) ((bool) ((time) != INVALID_ABSTIME)) |
#define | AbsoluteTimeIsReal(time) |
#define | RelativeTimeIsValid(time) ((bool) (((RelativeTime) (time)) != INVALID_RELTIME)) |
Typedefs | |
typedef int32 | AbsoluteTime |
typedef int32 | RelativeTime |
typedef TimeIntervalData * | TimeInterval |
Functions | |
Datum | abstimein (PG_FUNCTION_ARGS) |
Datum | abstimeout (PG_FUNCTION_ARGS) |
Datum | abstimerecv (PG_FUNCTION_ARGS) |
Datum | abstimesend (PG_FUNCTION_ARGS) |
Datum | abstimeeq (PG_FUNCTION_ARGS) |
Datum | abstimene (PG_FUNCTION_ARGS) |
Datum | abstimelt (PG_FUNCTION_ARGS) |
Datum | abstimegt (PG_FUNCTION_ARGS) |
Datum | abstimele (PG_FUNCTION_ARGS) |
Datum | abstimege (PG_FUNCTION_ARGS) |
Datum | abstime_finite (PG_FUNCTION_ARGS) |
Datum | timestamp_abstime (PG_FUNCTION_ARGS) |
Datum | abstime_timestamp (PG_FUNCTION_ARGS) |
Datum | timestamptz_abstime (PG_FUNCTION_ARGS) |
Datum | abstime_timestamptz (PG_FUNCTION_ARGS) |
Datum | reltimein (PG_FUNCTION_ARGS) |
Datum | reltimeout (PG_FUNCTION_ARGS) |
Datum | reltimerecv (PG_FUNCTION_ARGS) |
Datum | reltimesend (PG_FUNCTION_ARGS) |
Datum | tintervalin (PG_FUNCTION_ARGS) |
Datum | tintervalout (PG_FUNCTION_ARGS) |
Datum | tintervalrecv (PG_FUNCTION_ARGS) |
Datum | tintervalsend (PG_FUNCTION_ARGS) |
Datum | interval_reltime (PG_FUNCTION_ARGS) |
Datum | reltime_interval (PG_FUNCTION_ARGS) |
Datum | mktinterval (PG_FUNCTION_ARGS) |
Datum | timepl (PG_FUNCTION_ARGS) |
Datum | timemi (PG_FUNCTION_ARGS) |
Datum | intinterval (PG_FUNCTION_ARGS) |
Datum | tintervalrel (PG_FUNCTION_ARGS) |
Datum | timenow (PG_FUNCTION_ARGS) |
Datum | reltimeeq (PG_FUNCTION_ARGS) |
Datum | reltimene (PG_FUNCTION_ARGS) |
Datum | reltimelt (PG_FUNCTION_ARGS) |
Datum | reltimegt (PG_FUNCTION_ARGS) |
Datum | reltimele (PG_FUNCTION_ARGS) |
Datum | reltimege (PG_FUNCTION_ARGS) |
Datum | tintervalsame (PG_FUNCTION_ARGS) |
Datum | tintervaleq (PG_FUNCTION_ARGS) |
Datum | tintervalne (PG_FUNCTION_ARGS) |
Datum | tintervallt (PG_FUNCTION_ARGS) |
Datum | tintervalgt (PG_FUNCTION_ARGS) |
Datum | tintervalle (PG_FUNCTION_ARGS) |
Datum | tintervalge (PG_FUNCTION_ARGS) |
Datum | tintervalleneq (PG_FUNCTION_ARGS) |
Datum | tintervallenne (PG_FUNCTION_ARGS) |
Datum | tintervallenlt (PG_FUNCTION_ARGS) |
Datum | tintervallengt (PG_FUNCTION_ARGS) |
Datum | tintervallenle (PG_FUNCTION_ARGS) |
Datum | tintervallenge (PG_FUNCTION_ARGS) |
Datum | tintervalct (PG_FUNCTION_ARGS) |
Datum | tintervalov (PG_FUNCTION_ARGS) |
Datum | tintervalstart (PG_FUNCTION_ARGS) |
Datum | tintervalend (PG_FUNCTION_ARGS) |
Datum | timeofday (PG_FUNCTION_ARGS) |
AbsoluteTime | GetCurrentAbsoluteTime (void) |
void | abstime2tm (AbsoluteTime time, int *tzp, struct pg_tm *tm, char **tzn) |
#define AbsoluteTimeGetDatum | ( | X | ) | Int32GetDatum(X) |
Definition at line 54 of file nabstime.h.
Referenced by intinterval(), tintervalct(), tintervalout(), tintervalov(), and tintervalsame().
#define AbsoluteTimeIsReal | ( | time | ) |
((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \ ((AbsoluteTime) (time)) != NOSTART_ABSTIME))
Definition at line 91 of file nabstime.h.
Referenced by timemi(), timepl(), tintervalrel(), and tm2abstime().
#define AbsoluteTimeIsValid | ( | time | ) | ((bool) ((time) != INVALID_ABSTIME)) |
Definition at line 82 of file nabstime.h.
#define DatumGetAbsoluteTime | ( | X | ) | ((AbsoluteTime) DatumGetInt32(X)) |
Definition at line 50 of file nabstime.h.
Referenced by parsetinterval().
#define DatumGetRelativeTime | ( | X | ) | ((RelativeTime) DatumGetInt32(X)) |
Definition at line 51 of file nabstime.h.
Referenced by convert_timevalue_to_scalar(), tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), and tintervallenne().
#define DatumGetTimeInterval | ( | X | ) | ((TimeInterval) DatumGetPointer(X)) |
Definition at line 52 of file nabstime.h.
Referenced by convert_timevalue_to_scalar().
#define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) |
Definition at line 76 of file nabstime.h.
Referenced by abstime_cmp_internal(), abstime_date(), abstime_finite(), abstime_timestamp(), abstime_timestamptz(), abstimeout(), intinterval(), mktinterval(), timemi(), timepl(), tinterval_cmp_internal(), tintervalend(), tintervalin(), tintervalrecv(), tintervalstart(), and tm2abstime().
#define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) |
Definition at line 80 of file nabstime.h.
Referenced by reltime_cmp_internal(), reltime_interval(), tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), tintervallenne(), and tintervalrel().
#define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) |
Definition at line 77 of file nabstime.h.
Referenced by abstime_date(), abstime_finite(), abstime_timestamp(), abstime_timestamptz(), abstimeout(), timemi(), timepl(), and timetravel().
#define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) |
Definition at line 78 of file nabstime.h.
Referenced by abstime_date(), abstime_finite(), abstime_timestamp(), abstime_timestamptz(), abstimeout(), timemi(), and timepl().
#define PG_GETARG_ABSOLUTETIME | ( | n | ) | DatumGetAbsoluteTime(PG_GETARG_DATUM(n)) |
Definition at line 58 of file nabstime.h.
Referenced by abstime_date(), abstime_finite(), abstime_timestamp(), abstime_timestamptz(), abstimeeq(), abstimege(), abstimegt(), abstimele(), abstimelt(), abstimene(), abstimeout(), abstimesend(), btabstimecmp(), intinterval(), mktinterval(), timemi(), and timepl().
#define PG_GETARG_RELATIVETIME | ( | n | ) | DatumGetRelativeTime(PG_GETARG_DATUM(n)) |
Definition at line 59 of file nabstime.h.
Referenced by btreltimecmp(), reltime_interval(), reltimeeq(), reltimege(), reltimegt(), reltimele(), reltimelt(), reltimene(), reltimeout(), reltimesend(), timemi(), timepl(), tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), and tintervallenne().
#define PG_GETARG_TIMEINTERVAL | ( | n | ) | DatumGetTimeInterval(PG_GETARG_DATUM(n)) |
Definition at line 60 of file nabstime.h.
Referenced by bttintervalcmp(), intinterval(), tintervalct(), tintervalend(), tintervaleq(), tintervalge(), tintervalgt(), tintervalle(), tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), tintervallenne(), tintervallt(), tintervalne(), tintervalout(), tintervalov(), tintervalrel(), tintervalsame(), tintervalsend(), and tintervalstart().
#define PG_RETURN_ABSOLUTETIME | ( | x | ) | return AbsoluteTimeGetDatum(x) |
Definition at line 62 of file nabstime.h.
Referenced by abstimein(), abstimerecv(), timemi(), timenow(), timepl(), timestamp_abstime(), timestamptz_abstime(), tintervalend(), and tintervalstart().
#define PG_RETURN_RELATIVETIME | ( | x | ) | return RelativeTimeGetDatum(x) |
Definition at line 63 of file nabstime.h.
Referenced by interval_reltime(), reltimein(), reltimerecv(), and tintervalrel().
#define PG_RETURN_TIMEINTERVAL | ( | x | ) | return TimeIntervalGetDatum(x) |
Definition at line 64 of file nabstime.h.
Referenced by mktinterval(), tintervalin(), and tintervalrecv().
#define RelativeTimeGetDatum | ( | X | ) | Int32GetDatum(X) |
Definition at line 55 of file nabstime.h.
#define RelativeTimeIsValid | ( | time | ) | ((bool) (((RelativeTime) (time)) != INVALID_RELTIME)) |
Definition at line 95 of file nabstime.h.
#define TimeIntervalGetDatum | ( | X | ) | PointerGetDatum(X) |
Definition at line 56 of file nabstime.h.
Referenced by tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), and tintervallenne().
typedef int32 AbsoluteTime |
Definition at line 36 of file nabstime.h.
typedef int32 RelativeTime |
Definition at line 37 of file nabstime.h.
typedef TimeIntervalData* TimeInterval |
Definition at line 45 of file nabstime.h.
void abstime2tm | ( | AbsoluteTime | time, | |
int * | tzp, | |||
struct pg_tm * | tm, | |||
char ** | tzn | |||
) |
Definition at line 98 of file nabstime.c.
References CTimeZone, ereport, errcode(), errmsg(), HasCTZSet, MAXTZLEN, NULL, pg_gmtime(), pg_localtime(), session_timezone, StrNCpy, pg_tm::tm_gmtoff, pg_tm::tm_hour, pg_tm::tm_isdst, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, pg_tm::tm_zone, and WARNING.
Referenced by abstime_date(), abstime_timestamp(), abstime_timestamptz(), abstimeout(), and GetCurrentDateTime().
{ pg_time_t time = (pg_time_t) _time; struct pg_tm *tx; /* * If HasCTZSet is true then we have a brute force time zone specified. Go * ahead and rotate to the local time zone since we will later bypass any * calls which adjust the tm fields. */ if (HasCTZSet && (tzp != NULL)) time -= CTimeZone; if (!HasCTZSet && tzp != NULL) tx = pg_localtime(&time, session_timezone); else tx = pg_gmtime(&time); tm->tm_year = tx->tm_year + 1900; tm->tm_mon = tx->tm_mon + 1; tm->tm_mday = tx->tm_mday; tm->tm_hour = tx->tm_hour; tm->tm_min = tx->tm_min; tm->tm_sec = tx->tm_sec; tm->tm_isdst = tx->tm_isdst; tm->tm_gmtoff = tx->tm_gmtoff; tm->tm_zone = tx->tm_zone; if (tzp != NULL) { /* * We have a brute force time zone per SQL99? Then use it without * change since we have already rotated to the time zone. */ if (HasCTZSet) { *tzp = CTimeZone; tm->tm_gmtoff = CTimeZone; tm->tm_isdst = 0; tm->tm_zone = NULL; if (tzn != NULL) *tzn = NULL; } else { *tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */ /* * XXX FreeBSD man pages indicate that this should work - tgl * 97/04/23 */ if (tzn != NULL) { /* * Copy no more than MAXTZLEN bytes of timezone to tzn, in * case it contains an error message, which doesn't fit in the * buffer */ StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1); if (strlen(tm->tm_zone) > MAXTZLEN) ereport(WARNING, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid time zone name: \"%s\"", tm->tm_zone))); } } } else tm->tm_isdst = -1; }
Datum abstime_finite | ( | PG_FUNCTION_ARGS | ) |
Definition at line 351 of file nabstime.c.
References INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
{ AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); PG_RETURN_BOOL(abstime != INVALID_ABSTIME && abstime != NOSTART_ABSTIME && abstime != NOEND_ABSTIME); }
Datum abstime_timestamp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 492 of file nabstime.c.
References abstime2tm(), ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, NULL, PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMESTAMP, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, and tm2timestamp().
Referenced by convert_timevalue_to_scalar().
{ AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); Timestamp result; struct pg_tm tt, *tm = &tt; int tz; char zone[MAXDATELEN + 1], *tzn = zone; switch (abstime) { case INVALID_ABSTIME: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert abstime \"invalid\" to timestamp"))); TIMESTAMP_NOBEGIN(result); break; case NOSTART_ABSTIME: TIMESTAMP_NOBEGIN(result); break; case NOEND_ABSTIME: TIMESTAMP_NOEND(result); break; default: abstime2tm(abstime, &tz, tm, &tzn); if (tm2timestamp(tm, 0, NULL, &result) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); break; }; PG_RETURN_TIMESTAMP(result); }
Datum abstime_timestamptz | ( | PG_FUNCTION_ARGS | ) |
Definition at line 565 of file nabstime.c.
References abstime2tm(), ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMESTAMP, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, and tm2timestamp().
{ AbsoluteTime abstime = PG_GETARG_ABSOLUTETIME(0); TimestampTz result; struct pg_tm tt, *tm = &tt; int tz; char zone[MAXDATELEN + 1], *tzn = zone; switch (abstime) { case INVALID_ABSTIME: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert abstime \"invalid\" to timestamp"))); TIMESTAMP_NOBEGIN(result); break; case NOSTART_ABSTIME: TIMESTAMP_NOBEGIN(result); break; case NOEND_ABSTIME: TIMESTAMP_NOEND(result); break; default: abstime2tm(abstime, &tz, tm, &tzn); if (tm2timestamp(tm, 0, &tz, &result) != 0) ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); break; }; PG_RETURN_TIMESTAMP(result); }
Datum abstimeeq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 392 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
Referenced by tintervalsame().
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) == 0); }
Datum abstimege | ( | PG_FUNCTION_ARGS | ) |
Definition at line 437 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
Referenced by intinterval(), and tintervalct().
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) >= 0); }
Datum abstimegt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 419 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
Referenced by tintervalov().
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) > 0); }
Datum abstimein | ( | PG_FUNCTION_ARGS | ) |
Definition at line 221 of file nabstime.c.
References DateTimeParseError(), DecodeDateTime(), DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_INVALID, DTK_LATE, elog, ERROR, MAXDATEFIELDS, MAXDATELEN, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_ABSOLUTETIME, tm, and tm2abstime().
Referenced by parsetinterval().
{ char *str = PG_GETARG_CSTRING(0); AbsoluteTime result; fsec_t fsec; int tz = 0; struct pg_tm date, *tm = &date; int dterr; char *field[MAXDATEFIELDS]; char workbuf[MAXDATELEN + 1]; int dtype; int nf, ftype[MAXDATEFIELDS]; dterr = ParseDateTime(str, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf); if (dterr == 0) dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz); if (dterr != 0) DateTimeParseError(dterr, str, "abstime"); switch (dtype) { case DTK_DATE: result = tm2abstime(tm, tz); break; case DTK_EPOCH: /* * Don't bother retaining this as a reserved value, but instead * just set to the actual epoch time (1970-01-01) */ result = 0; break; case DTK_LATE: result = NOEND_ABSTIME; break; case DTK_EARLY: result = NOSTART_ABSTIME; break; case DTK_INVALID: result = INVALID_ABSTIME; break; default: elog(ERROR, "unexpected dtype %d while parsing abstime \"%s\"", dtype, str); result = INVALID_ABSTIME; break; }; PG_RETURN_ABSOLUTETIME(result); }
Datum abstimele | ( | PG_FUNCTION_ARGS | ) |
Definition at line 428 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
Referenced by intinterval(), and tintervalct().
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) <= 0); }
Datum abstimelt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 410 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
Referenced by tintervalov().
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) < 0); }
Datum abstimene | ( | PG_FUNCTION_ARGS | ) |
Definition at line 401 of file nabstime.c.
References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) != 0); }
Datum abstimeout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 285 of file nabstime.c.
References abstime2tm(), buf, DateStyle, EARLY, EncodeDateTime(), INVALID, INVALID_ABSTIME, LATE, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_RETURN_CSTRING, pstrdup(), and tm.
Referenced by tintervalout().
{ AbsoluteTime time = PG_GETARG_ABSOLUTETIME(0); char *result; int tz; double fsec = 0; struct pg_tm tt, *tm = &tt; char buf[MAXDATELEN + 1]; char zone[MAXDATELEN + 1], *tzn = zone; switch (time) { /* * Note that timestamp no longer supports 'invalid'. Retain * 'invalid' for abstime for now, but dump it someday. */ case INVALID_ABSTIME: strcpy(buf, INVALID); break; case NOEND_ABSTIME: strcpy(buf, LATE); break; case NOSTART_ABSTIME: strcpy(buf, EARLY); break; default: abstime2tm(time, &tz, tm, &tzn); EncodeDateTime(tm, fsec, true, tz, tzn, DateStyle, buf); break; } result = pstrdup(buf); PG_RETURN_CSTRING(result); }
Datum abstimerecv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 326 of file nabstime.c.
References buf, PG_GETARG_POINTER, PG_RETURN_ABSOLUTETIME, and pq_getmsgint().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); PG_RETURN_ABSOLUTETIME((AbsoluteTime) pq_getmsgint(buf, sizeof(AbsoluteTime))); }
Datum abstimesend | ( | PG_FUNCTION_ARGS | ) |
Definition at line 337 of file nabstime.c.
References buf, PG_GETARG_ABSOLUTETIME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().
{ AbsoluteTime time = PG_GETARG_ABSOLUTETIME(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, time, sizeof(time)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
AbsoluteTime GetCurrentAbsoluteTime | ( | void | ) |
Definition at line 88 of file nabstime.c.
References NULL.
Referenced by timenow(), and timetravel().
{ time_t now; now = time(NULL); return (AbsoluteTime) now; }
Datum interval_reltime | ( | PG_FUNCTION_ARGS | ) |
Definition at line 834 of file nabstime.c.
References Interval::day, DAYS_PER_MONTH, DAYS_PER_YEAR, INT64CONST, Interval::month, PG_GETARG_INTERVAL_P, PG_RETURN_RELATIVETIME, SECS_PER_DAY, Interval::time, and USECS_PER_SEC.
{ Interval *interval = PG_GETARG_INTERVAL_P(0); RelativeTime time; int year, month, day; TimeOffset span; year = interval->month / MONTHS_PER_YEAR; month = interval->month % MONTHS_PER_YEAR; day = interval->day; #ifdef HAVE_INT64_TIMESTAMP span = ((INT64CONST(365250000) * year + INT64CONST(30000000) * month + INT64CONST(1000000) * day) * INT64CONST(86400)) + interval->time; span /= USECS_PER_SEC; #else span = (DAYS_PER_YEAR * year + (double) DAYS_PER_MONTH * month + day) * SECS_PER_DAY + interval->time; #endif if (span < INT_MIN || span > INT_MAX) time = INVALID_RELTIME; else time = span; PG_RETURN_RELATIVETIME(time); }
Datum intinterval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 989 of file nabstime.c.
References AbsoluteTimeGetDatum, abstimege(), abstimele(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, INVALID_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_VALID.
{ AbsoluteTime t = PG_GETARG_ABSOLUTETIME(0); TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(1); if (tinterval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME) { if (DatumGetBool(DirectFunctionCall2(abstimege, AbsoluteTimeGetDatum(t), AbsoluteTimeGetDatum(tinterval->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimele, AbsoluteTimeGetDatum(t), AbsoluteTimeGetDatum(tinterval->data[1])))) PG_RETURN_BOOL(true); } PG_RETURN_BOOL(false); }
Datum mktinterval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 917 of file nabstime.c.
References ABSTIMEMAX, ABSTIMEMIN, TimeIntervalData::data, INVALID_ABSTIME, palloc(), PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMEINTERVAL, and TimeIntervalData::status.
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); AbsoluteTime t2 = PG_GETARG_ABSOLUTETIME(1); AbsoluteTime tstart = ABSTIMEMIN(t1, t2); AbsoluteTime tend = ABSTIMEMAX(t1, t2); TimeInterval tinterval; tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData)); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) tinterval->status = T_INTERVAL_INVAL; else { tinterval->status = T_INTERVAL_VALID; tinterval->data[0] = tstart; tinterval->data[1] = tend; } PG_RETURN_TIMEINTERVAL(tinterval); }
Datum reltime_interval | ( | PG_FUNCTION_ARGS | ) |
Definition at line 866 of file nabstime.c.
References Interval::day, DAYS_PER_MONTH, ereport, errcode(), errmsg(), ERROR, INVALID_RELTIME, Interval::month, MONTHS_PER_YEAR, palloc(), PG_GETARG_RELATIVETIME, PG_RETURN_INTERVAL_P, Interval::time, and TMODULO.
{ RelativeTime reltime = PG_GETARG_RELATIVETIME(0); Interval *result; int year, month, day; result = (Interval *) palloc(sizeof(Interval)); switch (reltime) { case INVALID_RELTIME: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert reltime \"invalid\" to interval"))); result->time = 0; result->day = 0; result->month = 0; break; default: #ifdef HAVE_INT64_TIMESTAMP year = reltime / SECS_PER_YEAR; reltime -= year * SECS_PER_YEAR; month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY); reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY); day = reltime / SECS_PER_DAY; reltime -= day * SECS_PER_DAY; result->time = (reltime * USECS_PER_SEC); #else TMODULO(reltime, year, SECS_PER_YEAR); TMODULO(reltime, month, DAYS_PER_MONTH * SECS_PER_DAY); TMODULO(reltime, day, SECS_PER_DAY); result->time = reltime; #endif result->month = MONTHS_PER_YEAR * year + month; result->day = day; break; } PG_RETURN_INTERVAL_P(result); }
Datum reltimeeq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1070 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) == 0); }
Datum reltimege | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1115 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) >= 0); }
Datum reltimegt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1097 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) > 0); }
Datum reltimein | ( | PG_FUNCTION_ARGS | ) |
Definition at line 613 of file nabstime.c.
References DateTimeParseError(), DecodeInterval(), DecodeISO8601Interval(), DTERR_BAD_FORMAT, DTERR_FIELD_OVERFLOW, DTK_DELTA, elog, ERROR, INTERVAL_FULL_RANGE, MAXDATEFIELDS, MAXDATELEN, MINS_PER_HOUR, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_RELATIVETIME, SECS_PER_MINUTE, SECS_PER_YEAR, tm, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, and pg_tm::tm_year.
{ char *str = PG_GETARG_CSTRING(0); RelativeTime result; struct pg_tm tt, *tm = &tt; fsec_t fsec; int dtype; int dterr; char *field[MAXDATEFIELDS]; int nf, ftype[MAXDATEFIELDS]; char workbuf[MAXDATELEN + 1]; dterr = ParseDateTime(str, workbuf, sizeof(workbuf), field, ftype, MAXDATEFIELDS, &nf); if (dterr == 0) dterr = DecodeInterval(field, ftype, nf, INTERVAL_FULL_RANGE, &dtype, tm, &fsec); /* if those functions think it's a bad format, try ISO8601 style */ if (dterr == DTERR_BAD_FORMAT) dterr = DecodeISO8601Interval(str, &dtype, tm, &fsec); if (dterr != 0) { if (dterr == DTERR_FIELD_OVERFLOW) dterr = DTERR_INTERVAL_OVERFLOW; DateTimeParseError(dterr, str, "reltime"); } switch (dtype) { case DTK_DELTA: result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec; result += tm->tm_year * SECS_PER_YEAR + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY; break; default: elog(ERROR, "unexpected dtype %d while parsing reltime \"%s\"", dtype, str); result = INVALID_RELTIME; break; } PG_RETURN_RELATIVETIME(result); }
Datum reltimele | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1106 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) <= 0); }
Datum reltimelt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1088 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) < 0); }
Datum reltimene | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1079 of file nabstime.c.
References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().
{ RelativeTime t1 = PG_GETARG_RELATIVETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) != 0); }
Datum reltimeout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 666 of file nabstime.c.
References buf, EncodeInterval(), IntervalStyle, MAXDATELEN, PG_GETARG_RELATIVETIME, PG_RETURN_CSTRING, pstrdup(), reltime2tm(), and tm.
{ RelativeTime time = PG_GETARG_RELATIVETIME(0); char *result; struct pg_tm tt, *tm = &tt; char buf[MAXDATELEN + 1]; reltime2tm(time, tm); EncodeInterval(tm, 0, IntervalStyle, buf); result = pstrdup(buf); PG_RETURN_CSTRING(result); }
Datum reltimerecv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 685 of file nabstime.c.
References buf, PG_GETARG_POINTER, PG_RETURN_RELATIVETIME, and pq_getmsgint().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); PG_RETURN_RELATIVETIME((RelativeTime) pq_getmsgint(buf, sizeof(RelativeTime))); }
Datum reltimesend | ( | PG_FUNCTION_ARGS | ) |
Definition at line 696 of file nabstime.c.
References buf, PG_GETARG_RELATIVETIME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().
{ RelativeTime time = PG_GETARG_RELATIVETIME(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, time, sizeof(time)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum timemi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 970 of file nabstime.c.
References AbsoluteTimeIsReal, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_GETARG_RELATIVETIME, PG_RETURN_ABSOLUTETIME, and RelativeTimeIsValid.
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (AbsoluteTimeIsReal(t1) && RelativeTimeIsValid(t2) && ((t2 > 0 && t1 > NOSTART_ABSTIME + t2) || (t2 <= 0 && t1 < NOEND_ABSTIME + t2))) /* prevent overflow */ PG_RETURN_ABSOLUTETIME(t1 - t2); PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); }
Datum timenow | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1034 of file nabstime.c.
References GetCurrentAbsoluteTime(), and PG_RETURN_ABSOLUTETIME.
Datum timeofday | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1594 of file nabstime.c.
References buf, cstring_to_text(), gettimeofday(), NULL, pg_localtime(), PG_RETURN_TEXT_P, pg_strftime(), session_timezone, and snprintf().
{ struct timeval tp; char templ[128]; char buf[128]; pg_time_t tt; gettimeofday(&tp, NULL); tt = (pg_time_t) tp.tv_sec; pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z", pg_localtime(&tt, session_timezone)); snprintf(buf, sizeof(buf), templ, tp.tv_usec); PG_RETURN_TEXT_P(cstring_to_text(buf)); }
Datum timepl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 951 of file nabstime.c.
References AbsoluteTimeIsReal, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_GETARG_RELATIVETIME, PG_RETURN_ABSOLUTETIME, and RelativeTimeIsValid.
{ AbsoluteTime t1 = PG_GETARG_ABSOLUTETIME(0); RelativeTime t2 = PG_GETARG_RELATIVETIME(1); if (AbsoluteTimeIsReal(t1) && RelativeTimeIsValid(t2) && ((t2 > 0 && t1 < NOEND_ABSTIME - t2) || (t2 <= 0 && t1 > NOSTART_ABSTIME - t2))) /* prevent overflow */ PG_RETURN_ABSOLUTETIME(t1 + t2); PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); }
Datum timestamp_abstime | ( | PG_FUNCTION_ARGS | ) |
Definition at line 459 of file nabstime.c.
References DetermineTimeZoneOffset(), ereport, errcode(), errmsg(), ERROR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_ABSOLUTETIME, session_timezone, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, and tm2abstime().
{ Timestamp timestamp = PG_GETARG_TIMESTAMP(0); AbsoluteTime result; fsec_t fsec; int tz; struct pg_tm tt, *tm = &tt; if (TIMESTAMP_IS_NOBEGIN(timestamp)) result = NOSTART_ABSTIME; else if (TIMESTAMP_IS_NOEND(timestamp)) result = NOEND_ABSTIME; else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) == 0) { tz = DetermineTimeZoneOffset(tm, session_timezone); result = tm2abstime(tm, tz); } else { ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); result = INVALID_ABSTIME; } PG_RETURN_ABSOLUTETIME(result); }
Datum timestamptz_abstime | ( | PG_FUNCTION_ARGS | ) |
Definition at line 536 of file nabstime.c.
References ereport, errcode(), errmsg(), ERROR, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_ABSOLUTETIME, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, and tm2abstime().
{ TimestampTz timestamp = PG_GETARG_TIMESTAMP(0); AbsoluteTime result; fsec_t fsec; struct pg_tm tt, *tm = &tt; if (TIMESTAMP_IS_NOBEGIN(timestamp)) result = NOSTART_ABSTIME; else if (TIMESTAMP_IS_NOEND(timestamp)) result = NOEND_ABSTIME; else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) == 0) result = tm2abstime(tm, 0); else { ereport(ERROR, (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), errmsg("timestamp out of range"))); result = INVALID_ABSTIME; } PG_RETURN_ABSOLUTETIME(result); }
Datum tintervalct | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1384 of file nabstime.c.
References AbsoluteTimeGetDatum, abstimege(), abstimele(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimele, AbsoluteTimeGetDatum(i1->data[0]), AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimege, AbsoluteTimeGetDatum(i1->data[1]), AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); }
Datum tintervalend | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1439 of file nabstime.c.
References TimeIntervalData::data, i, INVALID_ABSTIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_ABSOLUTETIME, TimeIntervalData::status, and T_INTERVAL_INVAL.
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); PG_RETURN_ABSOLUTETIME(i->data[1]); }
Datum tintervaleq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1219 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) == 0); }
Datum tintervalge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1264 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) >= 0); }
Datum tintervalgt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1255 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) > 0); }
Datum tintervalin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 725 of file nabstime.c.
References ABSTIMEMAX, ABSTIMEMIN, TimeIntervalData::data, INVALID_ABSTIME, palloc(), parsetinterval(), PG_GETARG_CSTRING, PG_RETURN_TIMEINTERVAL, and TimeIntervalData::status.
{ char *tintervalstr = PG_GETARG_CSTRING(0); TimeInterval tinterval; AbsoluteTime i_start, i_end, t1, t2; parsetinterval(tintervalstr, &t1, &t2); tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData)); if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME) tinterval->status = T_INTERVAL_INVAL; /* undefined */ else tinterval->status = T_INTERVAL_VALID; i_start = ABSTIMEMIN(t1, t2); i_end = ABSTIMEMAX(t1, t2); tinterval->data[0] = i_start; tinterval->data[1] = i_end; PG_RETURN_TIMEINTERVAL(tinterval); }
Datum tintervalle | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1246 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) <= 0); }
Datum tintervalleneq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1297 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt == t); }
Datum tintervallenge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1367 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt >= t); }
Datum tintervallengt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1339 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt > t); }
Datum tintervallenle | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1353 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt <= t); }
Datum tintervallenlt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1325 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt < t); }
Datum tintervallenne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1311 of file nabstime.c.
References DatumGetRelativeTime, DirectFunctionCall1, i, INVALID_RELTIME, PG_GETARG_RELATIVETIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, T_INTERVAL_INVAL, TimeIntervalGetDatum, and tintervalrel().
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); RelativeTime t = PG_GETARG_RELATIVETIME(1); RelativeTime rt; if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME) PG_RETURN_BOOL(false); rt = DatumGetRelativeTime(DirectFunctionCall1(tintervalrel, TimeIntervalGetDatum(i))); PG_RETURN_BOOL(rt != INVALID_RELTIME && rt != t); }
Datum tintervallt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1237 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) < 0); }
Datum tintervalne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1228 of file nabstime.c.
References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) != 0); }
Datum tintervalout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 756 of file nabstime.c.
References AbsoluteTimeGetDatum, abstimeout(), TimeIntervalData::data, DatumGetCString, DirectFunctionCall1, INVALID_INTERVAL_STR, palloc(), pfree(), PG_GETARG_TIMEINTERVAL, PG_RETURN_CSTRING, TimeIntervalData::status, T_INTERVAL_INVAL, and T_INTERVAL_LEN.
{ TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0); char *i_str, *p; i_str = (char *) palloc(T_INTERVAL_LEN); /* ["..." "..."] */ strcpy(i_str, "[\""); if (tinterval->status == T_INTERVAL_INVAL) strcat(i_str, INVALID_INTERVAL_STR); else { p = DatumGetCString(DirectFunctionCall1(abstimeout, AbsoluteTimeGetDatum(tinterval->data[0]))); strcat(i_str, p); pfree(p); strcat(i_str, "\" \""); p = DatumGetCString(DirectFunctionCall1(abstimeout, AbsoluteTimeGetDatum(tinterval->data[1]))); strcat(i_str, p); pfree(p); } strcat(i_str, "\"]"); PG_RETURN_CSTRING(i_str); }
Datum tintervalov | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1405 of file nabstime.c.
References AbsoluteTimeGetDatum, abstimegt(), abstimelt(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimelt, AbsoluteTimeGetDatum(i1->data[1]), AbsoluteTimeGetDatum(i2->data[0]))) || DatumGetBool(DirectFunctionCall2(abstimegt, AbsoluteTimeGetDatum(i1->data[0]), AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(false); PG_RETURN_BOOL(true); }
Datum tintervalrecv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 786 of file nabstime.c.
References buf, TimeIntervalData::data, ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, palloc(), PG_GETARG_POINTER, PG_RETURN_TIMEINTERVAL, pq_getmsgint(), and TimeIntervalData::status.
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); TimeInterval tinterval; int32 status; tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData)); tinterval->status = pq_getmsgint(buf, sizeof(tinterval->status)); tinterval->data[0] = pq_getmsgint(buf, sizeof(tinterval->data[0])); tinterval->data[1] = pq_getmsgint(buf, sizeof(tinterval->data[1])); if (tinterval->data[0] == INVALID_ABSTIME || tinterval->data[1] == INVALID_ABSTIME) status = T_INTERVAL_INVAL; /* undefined */ else status = T_INTERVAL_VALID; if (status != tinterval->status) ereport(ERROR, (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION), errmsg("invalid status in external \"tinterval\" value"))); PG_RETURN_TIMEINTERVAL(tinterval); }
Datum tintervalrel | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1011 of file nabstime.c.
References AbsoluteTimeIsReal, TimeIntervalData::data, INVALID_RELTIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_RELATIVETIME, TimeIntervalData::status, and T_INTERVAL_VALID.
Referenced by tintervalleneq(), tintervallenge(), tintervallengt(), tintervallenle(), tintervallenlt(), and tintervallenne().
{ TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0); AbsoluteTime t1 = tinterval->data[0]; AbsoluteTime t2 = tinterval->data[1]; if (tinterval->status != T_INTERVAL_VALID) PG_RETURN_RELATIVETIME(INVALID_RELTIME); if (AbsoluteTimeIsReal(t1) && AbsoluteTimeIsReal(t2)) PG_RETURN_RELATIVETIME(t2 - t1); PG_RETURN_RELATIVETIME(INVALID_RELTIME); }
Datum tintervalsame | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1138 of file nabstime.c.
References AbsoluteTimeGetDatum, abstimeeq(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.
{ TimeInterval i1 = PG_GETARG_TIMEINTERVAL(0); TimeInterval i2 = PG_GETARG_TIMEINTERVAL(1); if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL) PG_RETURN_BOOL(false); if (DatumGetBool(DirectFunctionCall2(abstimeeq, AbsoluteTimeGetDatum(i1->data[0]), AbsoluteTimeGetDatum(i2->data[0]))) && DatumGetBool(DirectFunctionCall2(abstimeeq, AbsoluteTimeGetDatum(i1->data[1]), AbsoluteTimeGetDatum(i2->data[1])))) PG_RETURN_BOOL(true); PG_RETURN_BOOL(false); }
Datum tintervalsend | ( | PG_FUNCTION_ARGS | ) |
Definition at line 816 of file nabstime.c.
References buf, TimeIntervalData::data, PG_GETARG_TIMEINTERVAL, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint(), and TimeIntervalData::status.
{ TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendint(&buf, tinterval->status, sizeof(tinterval->status)); pq_sendint(&buf, tinterval->data[0], sizeof(tinterval->data[0])); pq_sendint(&buf, tinterval->data[1], sizeof(tinterval->data[1])); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum tintervalstart | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1426 of file nabstime.c.
References TimeIntervalData::data, i, INVALID_ABSTIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_ABSOLUTETIME, TimeIntervalData::status, and T_INTERVAL_INVAL.
{ TimeInterval i = PG_GETARG_TIMEINTERVAL(0); if (i->status == T_INTERVAL_INVAL) PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); PG_RETURN_ABSOLUTETIME(i->data[0]); }