PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nabstime.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include "libpq/pqformat.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/datetime.h"
#include "utils/nabstime.h"
Include dependency graph for nabstime.c:

Go to the source code of this file.

Macros

#define MIN_DAYNUM   (-24856) /* December 13, 1901 */
 
#define MAX_DAYNUM   24854 /* January 18, 2038 */
 
#define IsSpace(C)   ((C) == ' ')
 
#define T_INTERVAL_INVAL   0 /* data represents no valid tinterval */
 
#define T_INTERVAL_VALID   1 /* data represents a valid tinterval */
 
#define T_INTERVAL_LEN   80
 
#define INVALID_INTERVAL_STR   "Undefined Range"
 
#define INVALID_INTERVAL_STR_LEN   (sizeof(INVALID_INTERVAL_STR)-1)
 
#define ABSTIMEMIN(t1, t2)
 
#define ABSTIMEMAX(t1, t2)
 

Functions

static AbsoluteTime tm2abstime (struct pg_tm *tm, int tz)
 
static void reltime2tm (RelativeTime time, struct pg_tm *tm)
 
static void parsetinterval (char *i_string, AbsoluteTime *i_start, AbsoluteTime *i_end)
 
AbsoluteTime GetCurrentAbsoluteTime (void)
 
void abstime2tm (AbsoluteTime _time, int *tzp, struct pg_tm *tm, char **tzn)
 
Datum abstimein (PG_FUNCTION_ARGS)
 
Datum abstimeout (PG_FUNCTION_ARGS)
 
Datum abstimerecv (PG_FUNCTION_ARGS)
 
Datum abstimesend (PG_FUNCTION_ARGS)
 
Datum abstime_finite (PG_FUNCTION_ARGS)
 
static int abstime_cmp_internal (AbsoluteTime a, AbsoluteTime b)
 
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 btabstimecmp (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)
 
static int reltime_cmp_internal (RelativeTime a, RelativeTime b)
 
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 btreltimecmp (PG_FUNCTION_ARGS)
 
Datum tintervalsame (PG_FUNCTION_ARGS)
 
static int tinterval_cmp_internal (TimeInterval a, TimeInterval b)
 
Datum tintervaleq (PG_FUNCTION_ARGS)
 
Datum tintervalne (PG_FUNCTION_ARGS)
 
Datum tintervallt (PG_FUNCTION_ARGS)
 
Datum tintervalle (PG_FUNCTION_ARGS)
 
Datum tintervalgt (PG_FUNCTION_ARGS)
 
Datum tintervalge (PG_FUNCTION_ARGS)
 
Datum bttintervalcmp (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)
 

Macro Definition Documentation

#define ABSTIMEMAX (   t1,
  t2 
)
Value:
AbsoluteTimeGetDatum(t2))) ? (t2) : (t1))
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
#define DatumGetBool(X)
Definition: postgres.h:399
Datum abstimelt(PG_FUNCTION_ARGS)
Definition: nabstime.c:385
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586

Definition at line 64 of file nabstime.c.

Referenced by mktinterval(), and tintervalin().

#define ABSTIMEMIN (   t1,
  t2 
)
Value:
AbsoluteTimeGetDatum(t2))) ? (t1) : (t2))
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
Datum abstimele(PG_FUNCTION_ARGS)
Definition: nabstime.c:403
#define DatumGetBool(X)
Definition: postgres.h:399
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586

Definition at line 60 of file nabstime.c.

Referenced by mktinterval(), and tintervalin().

#define INVALID_INTERVAL_STR   "Undefined Range"

Definition at line 57 of file nabstime.c.

Referenced by parsetinterval(), and tintervalout().

#define INVALID_INTERVAL_STR_LEN   (sizeof(INVALID_INTERVAL_STR)-1)

Definition at line 58 of file nabstime.c.

#define IsSpace (   C)    ((C) == ' ')

Definition at line 44 of file nabstime.c.

Referenced by parsetinterval().

#define MAX_DAYNUM   24854 /* January 18, 2038 */

Definition at line 33 of file nabstime.c.

Referenced by tm2abstime().

#define MIN_DAYNUM   (-24856) /* December 13, 1901 */

Definition at line 32 of file nabstime.c.

#define T_INTERVAL_LEN   80

Definition at line 56 of file nabstime.c.

Referenced by tintervalout().

#define T_INTERVAL_VALID   1 /* data represents a valid tinterval */

Definition at line 47 of file nabstime.c.

Referenced by intinterval(), mktinterval(), tintervalin(), tintervalrecv(), and tintervalrel().

Function Documentation

void abstime2tm ( AbsoluteTime  _time,
int *  tzp,
struct pg_tm tm,
char **  tzn 
)

Definition at line 99 of file nabstime.c.

References ereport, errcode(), errmsg(), 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(), and abstimeout().

100 {
101  pg_time_t time = (pg_time_t) _time;
102  struct pg_tm *tx;
103 
104  if (tzp != NULL)
105  tx = pg_localtime(&time, session_timezone);
106  else
107  tx = pg_gmtime(&time);
108 
109  tm->tm_year = tx->tm_year + 1900;
110  tm->tm_mon = tx->tm_mon + 1;
111  tm->tm_mday = tx->tm_mday;
112  tm->tm_hour = tx->tm_hour;
113  tm->tm_min = tx->tm_min;
114  tm->tm_sec = tx->tm_sec;
115  tm->tm_isdst = tx->tm_isdst;
116 
117  tm->tm_gmtoff = tx->tm_gmtoff;
118  tm->tm_zone = tx->tm_zone;
119 
120  if (tzp != NULL)
121  {
122  *tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
123 
124  /*
125  * XXX FreeBSD man pages indicate that this should work - tgl 97/04/23
126  */
127  if (tzn != NULL)
128  {
129  /*
130  * Copy no more than MAXTZLEN bytes of timezone to tzn, in case it
131  * contains an error message, which doesn't fit in the buffer
132  */
133  StrNCpy(*tzn, tm->tm_zone, MAXTZLEN + 1);
134  if (strlen(tm->tm_zone) > MAXTZLEN)
136  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
137  errmsg("invalid time zone name: \"%s\"",
138  tm->tm_zone)));
139  }
140  }
141  else
142  tm->tm_isdst = -1;
143 }
int64 pg_time_t
Definition: pgtime.h:23
struct pg_tm * pg_gmtime(const pg_time_t *timep)
Definition: localtime.c:1355
int tm_isdst
Definition: pgtime.h:35
int tm_hour
Definition: pgtime.h:29
int errcode(int sqlerrcode)
Definition: elog.c:575
#define MAXTZLEN
Definition: miscadmin.h:240
long int tm_gmtoff
Definition: pgtime.h:36
Definition: pgtime.h:25
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
const char * tm_zone
Definition: pgtime.h:37
#define ereport(elevel, rest)
Definition: elog.h:122
#define WARNING
Definition: elog.h:40
#define NULL
Definition: c.h:229
#define StrNCpy(dst, src, len)
Definition: c.h:830
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1314
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
pg_tz * session_timezone
Definition: pgtz.c:28
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
static int abstime_cmp_internal ( AbsoluteTime  a,
AbsoluteTime  b 
)
static

Definition at line 340 of file nabstime.c.

References INVALID_ABSTIME.

Referenced by abstimeeq(), abstimege(), abstimegt(), abstimele(), abstimelt(), abstimene(), and btabstimecmp().

341 {
342  /*
343  * We consider all INVALIDs to be equal and larger than any non-INVALID.
344  * This is somewhat arbitrary; the important thing is to have a consistent
345  * sort order.
346  */
347  if (a == INVALID_ABSTIME)
348  {
349  if (b == INVALID_ABSTIME)
350  return 0; /* INVALID = INVALID */
351  else
352  return 1; /* INVALID > non-INVALID */
353  }
354 
355  if (b == INVALID_ABSTIME)
356  return -1; /* non-INVALID < INVALID */
357 
358  if (a > b)
359  return 1;
360  else if (a == b)
361  return 0;
362  else
363  return -1;
364 }
#define INVALID_ABSTIME
Definition: nabstime.h:76
Datum abstime_finite ( PG_FUNCTION_ARGS  )

Definition at line 326 of file nabstime.c.

References INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

327 {
329 
330  PG_RETURN_BOOL(abstime != INVALID_ABSTIME &&
331  abstime != NOSTART_ABSTIME &&
332  abstime != NOEND_ABSTIME);
333 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define NOSTART_ABSTIME
Definition: nabstime.h:78
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum abstime_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 467 of file nabstime.c.

References abstime2tm(), ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, NULL, PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMESTAMP, result, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, and tm2timestamp().

Referenced by convert_timevalue_to_scalar().

468 {
471  struct pg_tm tt,
472  *tm = &tt;
473  int tz;
474  char zone[MAXDATELEN + 1],
475  *tzn = zone;
476 
477  switch (abstime)
478  {
479  case INVALID_ABSTIME:
480  ereport(ERROR,
481  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
482  errmsg("cannot convert abstime \"invalid\" to timestamp")));
483  TIMESTAMP_NOBEGIN(result);
484  break;
485 
486  case NOSTART_ABSTIME:
487  TIMESTAMP_NOBEGIN(result);
488  break;
489 
490  case NOEND_ABSTIME:
491  TIMESTAMP_NOEND(result);
492  break;
493 
494  default:
495  abstime2tm(abstime, &tz, tm, &tzn);
496  if (tm2timestamp(tm, 0, NULL, &result) != 0)
497  ereport(ERROR,
498  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
499  errmsg("timestamp out of range")));
500  break;
501  };
502 
503  PG_RETURN_TIMESTAMP(result);
504 }
#define MAXDATELEN
Definition: datetime.h:203
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define NOSTART_ABSTIME
Definition: nabstime.h:78
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
#define ERROR
Definition: elog.h:43
#define INVALID_ABSTIME
Definition: nabstime.h:76
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
int32 AbsoluteTime
Definition: nabstime.h:36
#define ereport(elevel, rest)
Definition: elog.h:122
int64 Timestamp
Definition: timestamp.h:38
void abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm *tm, char **tzn)
Definition: nabstime.c:99
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1854
#define NULL
Definition: c.h:229
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39
Definition: zic.c:90
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum abstime_timestamptz ( PG_FUNCTION_ARGS  )

Definition at line 540 of file nabstime.c.

References abstime2tm(), ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMESTAMP, result, TIMESTAMP_NOBEGIN, TIMESTAMP_NOEND, tm, and tm2timestamp().

541 {
544  struct pg_tm tt,
545  *tm = &tt;
546  int tz;
547  char zone[MAXDATELEN + 1],
548  *tzn = zone;
549 
550  switch (abstime)
551  {
552  case INVALID_ABSTIME:
553  ereport(ERROR,
554  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
555  errmsg("cannot convert abstime \"invalid\" to timestamp")));
556  TIMESTAMP_NOBEGIN(result);
557  break;
558 
559  case NOSTART_ABSTIME:
560  TIMESTAMP_NOBEGIN(result);
561  break;
562 
563  case NOEND_ABSTIME:
564  TIMESTAMP_NOEND(result);
565  break;
566 
567  default:
568  abstime2tm(abstime, &tz, tm, &tzn);
569  if (tm2timestamp(tm, 0, &tz, &result) != 0)
570  ereport(ERROR,
571  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
572  errmsg("timestamp out of range")));
573  break;
574  };
575 
576  PG_RETURN_TIMESTAMP(result);
577 }
#define MAXDATELEN
Definition: datetime.h:203
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define TIMESTAMP_NOEND(j)
Definition: timestamp.h:117
#define NOSTART_ABSTIME
Definition: nabstime.h:78
int64 TimestampTz
Definition: timestamp.h:39
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
#define ERROR
Definition: elog.h:43
#define INVALID_ABSTIME
Definition: nabstime.h:76
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
int32 AbsoluteTime
Definition: nabstime.h:36
#define ereport(elevel, rest)
Definition: elog.h:122
void abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm *tm, char **tzn)
Definition: nabstime.c:99
int tm2timestamp(struct pg_tm *tm, fsec_t fsec, int *tzp, Timestamp *result)
Definition: timestamp.c:1854
#define PG_RETURN_TIMESTAMP(x)
Definition: timestamp.h:39
Definition: zic.c:90
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum abstimeeq ( PG_FUNCTION_ARGS  )

Definition at line 367 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

Referenced by tintervalsame().

368 {
371 
372  PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) == 0);
373 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimege ( PG_FUNCTION_ARGS  )

Definition at line 412 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

Referenced by intinterval(), and tintervalct().

413 {
416 
417  PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) >= 0);
418 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimegt ( PG_FUNCTION_ARGS  )

Definition at line 394 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

Referenced by tintervalov().

395 {
398 
400 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimein ( PG_FUNCTION_ARGS  )

Definition at line 196 of file nabstime.c.

References DateTimeParseError(), DecodeDateTime(), DTK_DATE, DTK_EARLY, DTK_EPOCH, DTK_INVALID, DTK_LATE, elog, ERROR, INVALID_ABSTIME, MAXDATEFIELDS, MAXDATELEN, NOEND_ABSTIME, NOSTART_ABSTIME, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_ABSOLUTETIME, result, tm, and tm2abstime().

Referenced by parsetinterval().

197 {
198  char *str = PG_GETARG_CSTRING(0);
200  fsec_t fsec;
201  int tz = 0;
202  struct pg_tm date,
203  *tm = &date;
204  int dterr;
205  char *field[MAXDATEFIELDS];
206  char workbuf[MAXDATELEN + 1];
207  int dtype;
208  int nf,
209  ftype[MAXDATEFIELDS];
210 
211  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
212  field, ftype, MAXDATEFIELDS, &nf);
213  if (dterr == 0)
214  dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz);
215  if (dterr != 0)
216  DateTimeParseError(dterr, str, "abstime");
217 
218  switch (dtype)
219  {
220  case DTK_DATE:
221  result = tm2abstime(tm, tz);
222  break;
223 
224  case DTK_EPOCH:
225 
226  /*
227  * Don't bother retaining this as a reserved value, but instead
228  * just set to the actual epoch time (1970-01-01)
229  */
230  result = 0;
231  break;
232 
233  case DTK_LATE:
234  result = NOEND_ABSTIME;
235  break;
236 
237  case DTK_EARLY:
238  result = NOSTART_ABSTIME;
239  break;
240 
241  case DTK_INVALID:
242  result = INVALID_ABSTIME;
243  break;
244 
245  default:
246  elog(ERROR, "unexpected dtype %d while parsing abstime \"%s\"",
247  dtype, str);
248  result = INVALID_ABSTIME;
249  break;
250  };
251 
252  PG_RETURN_ABSOLUTETIME(result);
253 }
#define MAXDATELEN
Definition: datetime.h:203
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3765
#define NOSTART_ABSTIME
Definition: nabstime.h:78
static AbsoluteTime tm2abstime(struct pg_tm *tm, int tz)
Definition: nabstime.c:151
return result
Definition: formatting.c:1633
long date
Definition: pgtypes_date.h:8
Definition: pgtime.h:25
#define DTK_INVALID
Definition: datetime.h:151
static struct pg_tm tm
Definition: localtime.c:111
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Definition: datetime.c:783
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 fsec_t
Definition: timestamp.h:41
int32 AbsoluteTime
Definition: nabstime.h:36
#define DTK_LATE
Definition: datetime.h:154
#define DTK_EARLY
Definition: datetime.h:153
#define MAXDATEFIELDS
Definition: datetime.h:205
#define DTK_EPOCH
Definition: datetime.h:155
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define elog
Definition: elog.h:219
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:562
#define NOEND_ABSTIME
Definition: nabstime.h:77
#define DTK_DATE
Definition: datetime.h:145
Datum abstimele ( PG_FUNCTION_ARGS  )

Definition at line 403 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

Referenced by intinterval(), and tintervalct().

404 {
407 
408  PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) <= 0);
409 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimelt ( PG_FUNCTION_ARGS  )

Definition at line 385 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

Referenced by tintervalov().

386 {
389 
391 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimene ( PG_FUNCTION_ARGS  )

Definition at line 376 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_BOOL.

377 {
380 
381  PG_RETURN_BOOL(abstime_cmp_internal(t1, t2) != 0);
382 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum abstimeout ( PG_FUNCTION_ARGS  )

Definition at line 260 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(), result, and tm.

Referenced by tintervalout().

261 {
263  char *result;
264  int tz;
265  double fsec = 0;
266  struct pg_tm tt,
267  *tm = &tt;
268  char buf[MAXDATELEN + 1];
269  char zone[MAXDATELEN + 1],
270  *tzn = zone;
271 
272  switch (time)
273  {
274  /*
275  * Note that timestamp no longer supports 'invalid'. Retain
276  * 'invalid' for abstime for now, but dump it someday.
277  */
278  case INVALID_ABSTIME:
279  strcpy(buf, INVALID);
280  break;
281  case NOEND_ABSTIME:
282  strcpy(buf, LATE);
283  break;
284  case NOSTART_ABSTIME:
285  strcpy(buf, EARLY);
286  break;
287  default:
288  abstime2tm(time, &tz, tm, &tzn);
289  EncodeDateTime(tm, fsec, true, tz, tzn, DateStyle, buf);
290  break;
291  }
292 
293  result = pstrdup(buf);
294  PG_RETURN_CSTRING(result);
295 }
#define MAXDATELEN
Definition: datetime.h:203
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define NOSTART_ABSTIME
Definition: nabstime.h:78
#define LATE
Definition: datetime.h:41
Definition: isn.c:33
char * pstrdup(const char *in)
Definition: mcxt.c:1077
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
static char * buf
Definition: pg_test_fsync.c:66
void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str)
Definition: datetime.c:3999
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
void abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm *tm, char **tzn)
Definition: nabstime.c:99
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
int DateStyle
Definition: globals.c:107
Definition: zic.c:90
#define NOEND_ABSTIME
Definition: nabstime.h:77
#define EARLY
Definition: datetime.h:40
Datum abstimerecv ( PG_FUNCTION_ARGS  )

Definition at line 301 of file nabstime.c.

References buf, PG_GETARG_POINTER, PG_RETURN_ABSOLUTETIME, and pq_getmsgint().

302 {
304 
306 }
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
static char * buf
Definition: pg_test_fsync.c:66
int32 AbsoluteTime
Definition: nabstime.h:36
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
Datum abstimesend ( PG_FUNCTION_ARGS  )

Definition at line 312 of file nabstime.c.

References buf, PG_GETARG_ABSOLUTETIME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().

313 {
316 
317  pq_begintypsend(&buf);
318  pq_sendint(&buf, time, sizeof(time));
320 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:66
int32 AbsoluteTime
Definition: nabstime.h:36
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
Datum btabstimecmp ( PG_FUNCTION_ARGS  )

Definition at line 421 of file nabstime.c.

References abstime_cmp_internal(), PG_GETARG_ABSOLUTETIME, and PG_RETURN_INT32.

422 {
425 
427 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int32 AbsoluteTime
Definition: nabstime.h:36
static int abstime_cmp_internal(AbsoluteTime a, AbsoluteTime b)
Definition: nabstime.c:340
Datum btreltimecmp ( PG_FUNCTION_ARGS  )

Definition at line 1087 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_INT32, and reltime_cmp_internal().

1088 {
1091 
1093 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum bttintervalcmp ( PG_FUNCTION_ARGS  )

Definition at line 1236 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_INT32, and tinterval_cmp_internal().

1237 {
1240 
1242 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
AbsoluteTime GetCurrentAbsoluteTime ( void  )

Definition at line 89 of file nabstime.c.

References now(), and NULL.

Referenced by timenow(), and timetravel().

90 {
91  time_t now;
92 
93  now = time(NULL);
94  return (AbsoluteTime) now;
95 }
int32 AbsoluteTime
Definition: nabstime.h:36
#define NULL
Definition: c.h:229
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1534
Datum interval_reltime ( PG_FUNCTION_ARGS  )

Definition at line 809 of file nabstime.c.

References Interval::day, INT64CONST, INVALID_RELTIME, Interval::month, MONTHS_PER_YEAR, PG_GETARG_INTERVAL_P, PG_RETURN_RELATIVETIME, Interval::time, and USECS_PER_SEC.

810 {
812  RelativeTime time;
813  int year,
814  month,
815  day;
816  TimeOffset span;
817 
818  year = interval->month / MONTHS_PER_YEAR;
819  month = interval->month % MONTHS_PER_YEAR;
820  day = interval->day;
821 
822  span = ((INT64CONST(365250000) * year + INT64CONST(30000000) * month +
823  INT64CONST(1000000) * day) * INT64CONST(86400)) +
824  interval->time;
825  span /= USECS_PER_SEC;
826 
827  if (span < INT_MIN || span > INT_MAX)
828  time = INVALID_RELTIME;
829  else
830  time = span;
831 
833 }
#define PG_RETURN_RELATIVETIME(x)
Definition: nabstime.h:63
#define PG_GETARG_INTERVAL_P(n)
Definition: timestamp.h:37
#define USECS_PER_SEC
Definition: timestamp.h:94
#define INVALID_RELTIME
Definition: nabstime.h:80
int32 day
Definition: timestamp.h:47
#define MONTHS_PER_YEAR
Definition: timestamp.h:69
TimeOffset time
Definition: timestamp.h:45
int32 RelativeTime
Definition: nabstime.h:37
int32 month
Definition: timestamp.h:48
int64 TimeOffset
Definition: timestamp.h:40
#define INT64CONST(x)
Definition: c.h:310
Datum intinterval ( PG_FUNCTION_ARGS  )

Definition at line 952 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.

953 {
955  TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(1);
956 
957  if (tinterval->status == T_INTERVAL_VALID && t != INVALID_ABSTIME)
958  {
961  AbsoluteTimeGetDatum(tinterval->data[0]))) &&
964  AbsoluteTimeGetDatum(tinterval->data[1]))))
965  PG_RETURN_BOOL(true);
966  }
967  PG_RETURN_BOOL(false);
968 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
#define T_INTERVAL_VALID
Definition: nabstime.c:47
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
Datum abstimele(PG_FUNCTION_ARGS)
Definition: nabstime.c:403
#define DatumGetBool(X)
Definition: postgres.h:399
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AbsoluteTime data[2]
Definition: nabstime.h:42
Datum abstimege(PG_FUNCTION_ARGS)
Definition: nabstime.c:412
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum mktinterval ( PG_FUNCTION_ARGS  )

Definition at line 880 of file nabstime.c.

References ABSTIMEMAX, ABSTIMEMIN, TimeIntervalData::data, INVALID_ABSTIME, palloc(), PG_GETARG_ABSOLUTETIME, PG_RETURN_TIMEINTERVAL, TimeIntervalData::status, T_INTERVAL_INVAL, and T_INTERVAL_VALID.

881 {
884  AbsoluteTime tstart = ABSTIMEMIN(t1, t2);
885  AbsoluteTime tend = ABSTIMEMAX(t1, t2);
886  TimeInterval tinterval;
887 
888  tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
889 
890  if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
891  tinterval->status = T_INTERVAL_INVAL;
892 
893  else
894  {
895  tinterval->status = T_INTERVAL_VALID;
896  tinterval->data[0] = tstart;
897  tinterval->data[1] = tend;
898  }
899 
900  PG_RETURN_TIMEINTERVAL(tinterval);
901 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
TimeIntervalData * TimeInterval
Definition: nabstime.h:45
#define PG_RETURN_TIMEINTERVAL(x)
Definition: nabstime.h:64
#define T_INTERVAL_VALID
Definition: nabstime.c:47
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
#define ABSTIMEMAX(t1, t2)
Definition: nabstime.c:64
AbsoluteTime data[2]
Definition: nabstime.h:42
#define ABSTIMEMIN(t1, t2)
Definition: nabstime.c:60
void * palloc(Size size)
Definition: mcxt.c:849
static void parsetinterval ( char *  i_string,
AbsoluteTime i_start,
AbsoluteTime i_end 
)
static

Definition at line 1432 of file nabstime.c.

References abstimein(), CStringGetDatum, DatumGetAbsoluteTime, DirectFunctionCall1, ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, INVALID_INTERVAL_STR, and IsSpace.

Referenced by tintervalin().

1435 {
1436  char *p,
1437  *p1;
1438  char c;
1439 
1440  p = i_string;
1441  /* skip leading blanks up to '[' */
1442  while ((c = *p) != '\0')
1443  {
1444  if (IsSpace(c))
1445  p++;
1446  else if (c != '[')
1447  goto bogus; /* syntax error */
1448  else
1449  break;
1450  }
1451  if (c == '\0')
1452  goto bogus; /* syntax error */
1453  p++;
1454  /* skip leading blanks up to '"' */
1455  while ((c = *p) != '\0')
1456  {
1457  if (IsSpace(c))
1458  p++;
1459  else if (c != '"')
1460  goto bogus; /* syntax error */
1461  else
1462  break;
1463  }
1464  if (c == '\0')
1465  goto bogus; /* syntax error */
1466  p++;
1467  if (strncmp(INVALID_INTERVAL_STR, p, strlen(INVALID_INTERVAL_STR)) == 0)
1468  goto bogus; /* undefined range, handled like a syntax err. */
1469  /* search for the end of the first date and change it to a \0 */
1470  p1 = p;
1471  while ((c = *p1) != '\0')
1472  {
1473  if (c == '"')
1474  break;
1475  p1++;
1476  }
1477  if (c == '\0')
1478  goto bogus; /* syntax error */
1479  *p1 = '\0';
1480  /* get the first date */
1482  CStringGetDatum(p)));
1483  /* undo change to \0 */
1484  *p1 = c;
1485  p = ++p1;
1486  /* skip blanks up to '"', beginning of second date */
1487  while ((c = *p) != '\0')
1488  {
1489  if (IsSpace(c))
1490  p++;
1491  else if (c != '"')
1492  goto bogus; /* syntax error */
1493  else
1494  break;
1495  }
1496  if (c == '\0')
1497  goto bogus; /* syntax error */
1498  p++;
1499  /* search for the end of the second date and change it to a \0 */
1500  p1 = p;
1501  while ((c = *p1) != '\0')
1502  {
1503  if (c == '"')
1504  break;
1505  p1++;
1506  }
1507  if (c == '\0')
1508  goto bogus; /* syntax error */
1509  *p1 = '\0';
1510  /* get the second date */
1512  CStringGetDatum(p)));
1513  /* undo change to \0 */
1514  *p1 = c;
1515  p = ++p1;
1516  /* skip blanks up to ']' */
1517  while ((c = *p) != '\0')
1518  {
1519  if (IsSpace(c))
1520  p++;
1521  else if (c != ']')
1522  goto bogus; /* syntax error */
1523  else
1524  break;
1525  }
1526  if (c == '\0')
1527  goto bogus; /* syntax error */
1528  p++;
1529  c = *p;
1530  if (c != '\0')
1531  goto bogus; /* syntax error */
1532 
1533  /* it seems to be a valid tinterval */
1534  return;
1535 
1536 bogus:
1537  ereport(ERROR,
1538  (errcode(ERRCODE_INVALID_DATETIME_FORMAT),
1539  errmsg("invalid input syntax for type %s: \"%s\"",
1540  "tinterval", i_string)));
1541  *i_start = *i_end = INVALID_ABSTIME; /* keep compiler quiet */
1542 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define ERROR
Definition: elog.h:43
char * c
#define CStringGetDatum(X)
Definition: postgres.h:584
#define INVALID_ABSTIME
Definition: nabstime.h:76
Datum abstimein(PG_FUNCTION_ARGS)
Definition: nabstime.c:196
#define IsSpace(C)
Definition: nabstime.c:44
#define ereport(elevel, rest)
Definition: elog.h:122
#define INVALID_INTERVAL_STR
Definition: nabstime.c:57
#define DatumGetAbsoluteTime(X)
Definition: nabstime.h:50
int errmsg(const char *fmt,...)
Definition: elog.c:797
static void reltime2tm ( RelativeTime  time,
struct pg_tm tm 
)
static

Definition at line 683 of file nabstime.c.

References FMODULO, SECS_PER_DAY, SECS_PER_HOUR, SECS_PER_MINUTE, 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.

Referenced by reltimeout().

684 {
685  double dtime = time;
686 
687  FMODULO(dtime, tm->tm_year, 31557600);
688  FMODULO(dtime, tm->tm_mon, 2592000);
689  FMODULO(dtime, tm->tm_mday, SECS_PER_DAY);
690  FMODULO(dtime, tm->tm_hour, SECS_PER_HOUR);
691  FMODULO(dtime, tm->tm_min, SECS_PER_MINUTE);
692  FMODULO(dtime, tm->tm_sec, 1);
693 }
int tm_hour
Definition: pgtime.h:29
#define FMODULO(t, q, u)
Definition: datetime.h:240
#define SECS_PER_DAY
Definition: timestamp.h:86
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define SECS_PER_HOUR
Definition: timestamp.h:87
int tm_year
Definition: pgtime.h:32
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
static int reltime_cmp_internal ( RelativeTime  a,
RelativeTime  b 
)
static

Definition at line 1006 of file nabstime.c.

References INVALID_RELTIME.

Referenced by btreltimecmp(), reltimeeq(), reltimege(), reltimegt(), reltimele(), reltimelt(), and reltimene().

1007 {
1008  /*
1009  * We consider all INVALIDs to be equal and larger than any non-INVALID.
1010  * This is somewhat arbitrary; the important thing is to have a consistent
1011  * sort order.
1012  */
1013  if (a == INVALID_RELTIME)
1014  {
1015  if (b == INVALID_RELTIME)
1016  return 0; /* INVALID = INVALID */
1017  else
1018  return 1; /* INVALID > non-INVALID */
1019  }
1020 
1021  if (b == INVALID_RELTIME)
1022  return -1; /* non-INVALID < INVALID */
1023 
1024  if (a > b)
1025  return 1;
1026  else if (a == b)
1027  return 0;
1028  else
1029  return -1;
1030 }
#define INVALID_RELTIME
Definition: nabstime.h:80
Datum reltime_interval ( PG_FUNCTION_ARGS  )

Definition at line 837 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, result, SECS_PER_DAY, SECS_PER_YEAR, Interval::time, and USECS_PER_SEC.

838 {
840  Interval *result;
841  int year,
842  month,
843  day;
844 
845  result = (Interval *) palloc(sizeof(Interval));
846 
847  switch (reltime)
848  {
849  case INVALID_RELTIME:
850  ereport(ERROR,
851  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
852  errmsg("cannot convert reltime \"invalid\" to interval")));
853  result->time = 0;
854  result->day = 0;
855  result->month = 0;
856  break;
857 
858  default:
859  year = reltime / SECS_PER_YEAR;
860  reltime -= year * SECS_PER_YEAR;
861  month = reltime / (DAYS_PER_MONTH * SECS_PER_DAY);
862  reltime -= month * (DAYS_PER_MONTH * SECS_PER_DAY);
863  day = reltime / SECS_PER_DAY;
864  reltime -= day * SECS_PER_DAY;
865 
866  result->time = (reltime * USECS_PER_SEC);
867  result->month = MONTHS_PER_YEAR * year + month;
868  result->day = day;
869  break;
870  }
871 
872  PG_RETURN_INTERVAL_P(result);
873 }
#define PG_RETURN_INTERVAL_P(x)
Definition: timestamp.h:41
#define USECS_PER_SEC
Definition: timestamp.h:94
#define INVALID_RELTIME
Definition: nabstime.h:80
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
int32 day
Definition: timestamp.h:47
#define MONTHS_PER_YEAR
Definition: timestamp.h:69
#define ERROR
Definition: elog.h:43
#define SECS_PER_DAY
Definition: timestamp.h:86
TimeOffset time
Definition: timestamp.h:45
int32 RelativeTime
Definition: nabstime.h:37
#define ereport(elevel, rest)
Definition: elog.h:122
int32 month
Definition: timestamp.h:48
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define DAYS_PER_MONTH
Definition: timestamp.h:77
#define SECS_PER_YEAR
Definition: timestamp.h:85
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum reltimeeq ( PG_FUNCTION_ARGS  )

Definition at line 1033 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1034 {
1037 
1038  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) == 0);
1039 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimege ( PG_FUNCTION_ARGS  )

Definition at line 1078 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1079 {
1082 
1083  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) >= 0);
1084 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimegt ( PG_FUNCTION_ARGS  )

Definition at line 1060 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1061 {
1064 
1065  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) > 0);
1066 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimein ( PG_FUNCTION_ARGS  )

Definition at line 588 of file nabstime.c.

References DateTimeParseError(), DAYS_PER_MONTH, DecodeInterval(), DecodeISO8601Interval(), DTERR_BAD_FORMAT, DTERR_FIELD_OVERFLOW, DTERR_INTERVAL_OVERFLOW, DTK_DELTA, elog, ERROR, INTERVAL_FULL_RANGE, INVALID_RELTIME, MAXDATEFIELDS, MAXDATELEN, MINS_PER_HOUR, ParseDateTime(), PG_GETARG_CSTRING, PG_RETURN_RELATIVETIME, result, SECS_PER_DAY, 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.

589 {
590  char *str = PG_GETARG_CSTRING(0);
592  struct pg_tm tt,
593  *tm = &tt;
594  fsec_t fsec;
595  int dtype;
596  int dterr;
597  char *field[MAXDATEFIELDS];
598  int nf,
599  ftype[MAXDATEFIELDS];
600  char workbuf[MAXDATELEN + 1];
601 
602  dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
603  field, ftype, MAXDATEFIELDS, &nf);
604  if (dterr == 0)
605  dterr = DecodeInterval(field, ftype, nf, INTERVAL_FULL_RANGE,
606  &dtype, tm, &fsec);
607 
608  /* if those functions think it's a bad format, try ISO8601 style */
609  if (dterr == DTERR_BAD_FORMAT)
610  dterr = DecodeISO8601Interval(str,
611  &dtype, tm, &fsec);
612 
613  if (dterr != 0)
614  {
615  if (dterr == DTERR_FIELD_OVERFLOW)
616  dterr = DTERR_INTERVAL_OVERFLOW;
617  DateTimeParseError(dterr, str, "reltime");
618  }
619 
620  switch (dtype)
621  {
622  case DTK_DELTA:
623  result = ((tm->tm_hour * MINS_PER_HOUR + tm->tm_min) * SECS_PER_MINUTE) + tm->tm_sec;
624  result += tm->tm_year * SECS_PER_YEAR + ((tm->tm_mon * DAYS_PER_MONTH) + tm->tm_mday) * SECS_PER_DAY;
625  break;
626 
627  default:
628  elog(ERROR, "unexpected dtype %d while parsing reltime \"%s\"",
629  dtype, str);
630  result = INVALID_RELTIME;
631  break;
632  }
633 
634  PG_RETURN_RELATIVETIME(result);
635 }
#define MAXDATELEN
Definition: datetime.h:203
#define DTERR_BAD_FORMAT
Definition: datetime.h:282
#define PG_RETURN_RELATIVETIME(x)
Definition: nabstime.h:63
void DateTimeParseError(int dterr, const char *str, const char *datatype)
Definition: datetime.c:3765
#define DTK_DELTA
Definition: datetime.h:162
int tm_hour
Definition: pgtime.h:29
#define INVALID_RELTIME
Definition: nabstime.h:80
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
#define INTERVAL_FULL_RANGE
Definition: timestamp.h:48
#define MINS_PER_HOUR
Definition: timestamp.h:89
static struct pg_tm tm
Definition: localtime.c:111
#define ERROR
Definition: elog.h:43
#define DTERR_FIELD_OVERFLOW
Definition: datetime.h:283
#define SECS_PER_DAY
Definition: timestamp.h:86
#define DTERR_INTERVAL_OVERFLOW
Definition: datetime.h:285
int tm_mday
Definition: pgtime.h:30
int tm_mon
Definition: pgtime.h:31
#define SECS_PER_MINUTE
Definition: timestamp.h:88
int32 fsec_t
Definition: timestamp.h:41
int32 RelativeTime
Definition: nabstime.h:37
int DecodeISO8601Interval(char *str, int *dtype, struct pg_tm *tm, fsec_t *fsec)
Definition: datetime.c:3521
#define DAYS_PER_MONTH
Definition: timestamp.h:77
#define SECS_PER_YEAR
Definition: timestamp.h:85
#define MAXDATEFIELDS
Definition: datetime.h:205
int tm_year
Definition: pgtime.h:32
int DecodeInterval(char **field, int *ftype, int nf, int range, int *dtype, struct pg_tm *tm, fsec_t *fsec)
Definition: datetime.c:3095
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define elog
Definition: elog.h:219
int tm_sec
Definition: pgtime.h:27
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
Definition: datetime.c:562
int tm_min
Definition: pgtime.h:28
Datum reltimele ( PG_FUNCTION_ARGS  )

Definition at line 1069 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1070 {
1073 
1074  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) <= 0);
1075 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimelt ( PG_FUNCTION_ARGS  )

Definition at line 1051 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1052 {
1055 
1056  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) < 0);
1057 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimene ( PG_FUNCTION_ARGS  )

Definition at line 1042 of file nabstime.c.

References PG_GETARG_RELATIVETIME, PG_RETURN_BOOL, and reltime_cmp_internal().

1043 {
1046 
1047  PG_RETURN_BOOL(reltime_cmp_internal(t1, t2) != 0);
1048 }
static int reltime_cmp_internal(RelativeTime a, RelativeTime b)
Definition: nabstime.c:1006
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum reltimeout ( PG_FUNCTION_ARGS  )

Definition at line 641 of file nabstime.c.

References buf, EncodeInterval(), IntervalStyle, MAXDATELEN, PG_GETARG_RELATIVETIME, PG_RETURN_CSTRING, pstrdup(), reltime2tm(), result, and tm.

642 {
644  char *result;
645  struct pg_tm tt,
646  *tm = &tt;
647  char buf[MAXDATELEN + 1];
648 
649  reltime2tm(time, tm);
650  EncodeInterval(tm, 0, IntervalStyle, buf);
651 
652  result = pstrdup(buf);
653  PG_RETURN_CSTRING(result);
654 }
#define MAXDATELEN
Definition: datetime.h:203
static void reltime2tm(RelativeTime time, struct pg_tm *tm)
Definition: nabstime.c:683
char * pstrdup(const char *in)
Definition: mcxt.c:1077
int IntervalStyle
Definition: globals.c:109
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
static char * buf
Definition: pg_test_fsync.c:66
int32 RelativeTime
Definition: nabstime.h:37
void EncodeInterval(struct pg_tm *tm, fsec_t fsec, int style, char *str)
Definition: datetime.c:4241
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
Datum reltimerecv ( PG_FUNCTION_ARGS  )

Definition at line 660 of file nabstime.c.

References buf, PG_GETARG_POINTER, PG_RETURN_RELATIVETIME, and pq_getmsgint().

661 {
663 
665 }
#define PG_RETURN_RELATIVETIME(x)
Definition: nabstime.h:63
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static char * buf
Definition: pg_test_fsync.c:66
int32 RelativeTime
Definition: nabstime.h:37
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
Datum reltimesend ( PG_FUNCTION_ARGS  )

Definition at line 671 of file nabstime.c.

References buf, PG_GETARG_RELATIVETIME, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().

672 {
675 
676  pq_begintypsend(&buf);
677  pq_sendint(&buf, time, sizeof(time));
679 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:66
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
Datum timemi ( PG_FUNCTION_ARGS  )

Definition at line 933 of file nabstime.c.

References AbsoluteTimeIsReal, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_GETARG_RELATIVETIME, PG_RETURN_ABSOLUTETIME, and RelativeTimeIsValid.

934 {
937 
938  if (AbsoluteTimeIsReal(t1) &&
939  RelativeTimeIsValid(t2) &&
940  ((t2 > 0 && t1 > NOSTART_ABSTIME + t2) ||
941  (t2 <= 0 && t1 < NOEND_ABSTIME + t2))) /* prevent overflow */
942  PG_RETURN_ABSOLUTETIME(t1 - t2);
943 
945 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define NOSTART_ABSTIME
Definition: nabstime.h:78
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 RelativeTime
Definition: nabstime.h:37
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define AbsoluteTimeIsReal(time)
Definition: nabstime.h:91
#define RelativeTimeIsValid(time)
Definition: nabstime.h:95
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum timenow ( PG_FUNCTION_ARGS  )

Definition at line 997 of file nabstime.c.

References GetCurrentAbsoluteTime(), and PG_RETURN_ABSOLUTETIME.

Referenced by cache_locale_time().

998 {
1000 }
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
AbsoluteTime GetCurrentAbsoluteTime(void)
Definition: nabstime.c:89
Datum timeofday ( PG_FUNCTION_ARGS  )

Definition at line 1557 of file nabstime.c.

References buf, cstring_to_text(), gettimeofday(), NULL, pg_localtime(), PG_RETURN_TEXT_P, pg_strftime(), session_timezone, and snprintf().

1558 {
1559  struct timeval tp;
1560  char templ[128];
1561  char buf[128];
1562  pg_time_t tt;
1563 
1564  gettimeofday(&tp, NULL);
1565  tt = (pg_time_t) tp.tv_sec;
1566  pg_strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
1568  snprintf(buf, sizeof(buf), templ, tp.tv_usec);
1569 
1571 }
size_t pg_strftime(char *s, size_t max, const char *format, const struct pg_tm *tm)
Definition: strftime.c:122
int gettimeofday(struct timeval *tp, struct timezone *tzp)
Definition: gettimeofday.c:105
int64 pg_time_t
Definition: pgtime.h:23
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
static char * buf
Definition: pg_test_fsync.c:66
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
text * cstring_to_text(const char *s)
Definition: varlena.c:149
#define NULL
Definition: c.h:229
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1314
pg_tz * session_timezone
Definition: pgtz.c:28
Datum timepl ( PG_FUNCTION_ARGS  )

Definition at line 914 of file nabstime.c.

References AbsoluteTimeIsReal, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, PG_GETARG_ABSOLUTETIME, PG_GETARG_RELATIVETIME, PG_RETURN_ABSOLUTETIME, and RelativeTimeIsValid.

915 {
918 
919  if (AbsoluteTimeIsReal(t1) &&
920  RelativeTimeIsValid(t2) &&
921  ((t2 > 0 && t1 < NOEND_ABSTIME - t2) ||
922  (t2 <= 0 && t1 > NOSTART_ABSTIME - t2))) /* prevent overflow */
923  PG_RETURN_ABSOLUTETIME(t1 + t2);
924 
926 }
#define PG_GETARG_ABSOLUTETIME(n)
Definition: nabstime.h:58
#define NOSTART_ABSTIME
Definition: nabstime.h:78
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 RelativeTime
Definition: nabstime.h:37
int32 AbsoluteTime
Definition: nabstime.h:36
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
#define AbsoluteTimeIsReal(time)
Definition: nabstime.h:91
#define RelativeTimeIsValid(time)
Definition: nabstime.h:95
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum timestamp_abstime ( PG_FUNCTION_ARGS  )

Definition at line 434 of file nabstime.c.

References DetermineTimeZoneOffset(), ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_ABSOLUTETIME, result, session_timezone, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, and tm2abstime().

435 {
438  fsec_t fsec;
439  int tz;
440  struct pg_tm tt,
441  *tm = &tt;
442 
443  if (TIMESTAMP_IS_NOBEGIN(timestamp))
444  result = NOSTART_ABSTIME;
445  else if (TIMESTAMP_IS_NOEND(timestamp))
446  result = NOEND_ABSTIME;
447  else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) == 0)
448  {
450  result = tm2abstime(tm, tz);
451  }
452  else
453  {
454  ereport(ERROR,
455  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
456  errmsg("timestamp out of range")));
457  result = INVALID_ABSTIME;
458  }
459 
460  PG_RETURN_ABSOLUTETIME(result);
461 }
#define NOSTART_ABSTIME
Definition: nabstime.h:78
int64 timestamp
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
static AbsoluteTime tm2abstime(struct pg_tm *tm, int tz)
Definition: nabstime.c:151
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
int DetermineTimeZoneOffset(struct pg_tm *tm, pg_tz *tzp)
Definition: datetime.c:1471
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 fsec_t
Definition: timestamp.h:41
int32 AbsoluteTime
Definition: nabstime.h:36
#define ereport(elevel, rest)
Definition: elog.h:122
int64 Timestamp
Definition: timestamp.h:38
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:115
pg_tz * session_timezone
Definition: pgtz.c:28
#define NOEND_ABSTIME
Definition: nabstime.h:77
Datum timestamptz_abstime ( PG_FUNCTION_ARGS  )

Definition at line 511 of file nabstime.c.

References ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, NOEND_ABSTIME, NOSTART_ABSTIME, NULL, PG_GETARG_TIMESTAMP, PG_RETURN_ABSOLUTETIME, result, timestamp2tm(), TIMESTAMP_IS_NOBEGIN, TIMESTAMP_IS_NOEND, tm, and tm2abstime().

512 {
515  fsec_t fsec;
516  struct pg_tm tt,
517  *tm = &tt;
518 
519  if (TIMESTAMP_IS_NOBEGIN(timestamp))
520  result = NOSTART_ABSTIME;
521  else if (TIMESTAMP_IS_NOEND(timestamp))
522  result = NOEND_ABSTIME;
523  else if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) == 0)
524  result = tm2abstime(tm, 0);
525  else
526  {
527  ereport(ERROR,
528  (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
529  errmsg("timestamp out of range")));
530  result = INVALID_ABSTIME;
531  }
532 
533  PG_RETURN_ABSOLUTETIME(result);
534 }
#define NOSTART_ABSTIME
Definition: nabstime.h:78
int64 timestamp
int64 TimestampTz
Definition: timestamp.h:39
#define PG_GETARG_TIMESTAMP(n)
Definition: timestamp.h:35
int timestamp2tm(Timestamp dt, int *tzp, struct pg_tm *tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
Definition: timestamp.c:1758
static AbsoluteTime tm2abstime(struct pg_tm *tm, int tz)
Definition: nabstime.c:151
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1633
Definition: pgtime.h:25
static struct pg_tm tm
Definition: localtime.c:111
#define ERROR
Definition: elog.h:43
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 fsec_t
Definition: timestamp.h:41
int32 AbsoluteTime
Definition: nabstime.h:36
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define TIMESTAMP_IS_NOEND(j)
Definition: timestamp.h:120
#define TIMESTAMP_IS_NOBEGIN(j)
Definition: timestamp.h:115
#define NOEND_ABSTIME
Definition: nabstime.h:77
static int tinterval_cmp_internal ( TimeInterval  a,
TimeInterval  b 
)
static

Definition at line 1140 of file nabstime.c.

References TimeIntervalData::data, INVALID_ABSTIME, TimeIntervalData::status, and T_INTERVAL_INVAL.

Referenced by bttintervalcmp(), tintervaleq(), tintervalge(), tintervalgt(), tintervalle(), tintervallt(), and tintervalne().

1141 {
1142  bool a_invalid;
1143  bool b_invalid;
1144  AbsoluteTime a_len;
1145  AbsoluteTime b_len;
1146 
1147  /*
1148  * We consider all INVALIDs to be equal and larger than any non-INVALID.
1149  * This is somewhat arbitrary; the important thing is to have a consistent
1150  * sort order.
1151  */
1152  a_invalid = a->status == T_INTERVAL_INVAL ||
1153  a->data[0] == INVALID_ABSTIME ||
1154  a->data[1] == INVALID_ABSTIME;
1155  b_invalid = b->status == T_INTERVAL_INVAL ||
1156  b->data[0] == INVALID_ABSTIME ||
1157  b->data[1] == INVALID_ABSTIME;
1158 
1159  if (a_invalid)
1160  {
1161  if (b_invalid)
1162  return 0; /* INVALID = INVALID */
1163  else
1164  return 1; /* INVALID > non-INVALID */
1165  }
1166 
1167  if (b_invalid)
1168  return -1; /* non-INVALID < INVALID */
1169 
1170  a_len = a->data[1] - a->data[0];
1171  b_len = b->data[1] - b->data[0];
1172 
1173  if (a_len > b_len)
1174  return 1;
1175  else if (a_len == b_len)
1176  return 0;
1177  else
1178  return -1;
1179 }
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
AbsoluteTime data[2]
Definition: nabstime.h:42
Datum tintervalct ( PG_FUNCTION_ARGS  )

Definition at line 1347 of file nabstime.c.

References AbsoluteTimeGetDatum, abstimege(), abstimele(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.

1348 {
1351 
1352  if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
1353  PG_RETURN_BOOL(false);
1355  AbsoluteTimeGetDatum(i1->data[0]),
1356  AbsoluteTimeGetDatum(i2->data[0]))) &&
1358  AbsoluteTimeGetDatum(i1->data[1]),
1359  AbsoluteTimeGetDatum(i2->data[1]))))
1360  PG_RETURN_BOOL(true);
1361  PG_RETURN_BOOL(false);
1362 }
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
Datum abstimele(PG_FUNCTION_ARGS)
Definition: nabstime.c:403
#define DatumGetBool(X)
Definition: postgres.h:399
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AbsoluteTime data[2]
Definition: nabstime.h:42
Datum abstimege(PG_FUNCTION_ARGS)
Definition: nabstime.c:412
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum tintervalend ( PG_FUNCTION_ARGS  )

Definition at line 1402 of file nabstime.c.

References TimeIntervalData::data, i, INVALID_ABSTIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_ABSOLUTETIME, TimeIntervalData::status, and T_INTERVAL_INVAL.

1403 {
1405 
1406  if (i->status == T_INTERVAL_INVAL)
1409 }
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
AbsoluteTime data[2]
Definition: nabstime.h:42
int i
Datum tintervaleq ( PG_FUNCTION_ARGS  )

Definition at line 1182 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1183 {
1186 
1187  PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) == 0);
1188 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalge ( PG_FUNCTION_ARGS  )

Definition at line 1227 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1228 {
1231 
1232  PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) >= 0);
1233 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalgt ( PG_FUNCTION_ARGS  )

Definition at line 1218 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1219 {
1222 
1224 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalin ( PG_FUNCTION_ARGS  )

Definition at line 700 of file nabstime.c.

References ABSTIMEMAX, ABSTIMEMIN, TimeIntervalData::data, INVALID_ABSTIME, palloc(), parsetinterval(), PG_GETARG_CSTRING, PG_RETURN_TIMEINTERVAL, TimeIntervalData::status, T_INTERVAL_INVAL, and T_INTERVAL_VALID.

701 {
702  char *tintervalstr = PG_GETARG_CSTRING(0);
703  TimeInterval tinterval;
704  AbsoluteTime i_start,
705  i_end,
706  t1,
707  t2;
708 
709  parsetinterval(tintervalstr, &t1, &t2);
710 
711  tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
712 
713  if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
714  tinterval->status = T_INTERVAL_INVAL; /* undefined */
715  else
716  tinterval->status = T_INTERVAL_VALID;
717 
718  i_start = ABSTIMEMIN(t1, t2);
719  i_end = ABSTIMEMAX(t1, t2);
720  tinterval->data[0] = i_start;
721  tinterval->data[1] = i_end;
722 
723  PG_RETURN_TIMEINTERVAL(tinterval);
724 }
static void parsetinterval(char *i_string, AbsoluteTime *i_start, AbsoluteTime *i_end)
Definition: nabstime.c:1432
TimeIntervalData * TimeInterval
Definition: nabstime.h:45
#define PG_RETURN_TIMEINTERVAL(x)
Definition: nabstime.h:64
#define T_INTERVAL_VALID
Definition: nabstime.c:47
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
#define ABSTIMEMAX(t1, t2)
Definition: nabstime.c:64
AbsoluteTime data[2]
Definition: nabstime.h:42
#define ABSTIMEMIN(t1, t2)
Definition: nabstime.c:60
void * palloc(Size size)
Definition: mcxt.c:849
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
Datum tintervalle ( PG_FUNCTION_ARGS  )

Definition at line 1209 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1210 {
1213 
1214  PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) <= 0);
1215 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalleneq ( PG_FUNCTION_ARGS  )

Definition at line 1260 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().

1261 {
1264  RelativeTime rt;
1265 
1266  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1267  PG_RETURN_BOOL(false);
1269  TimeIntervalGetDatum(i)));
1270  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt == t);
1271 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallenge ( PG_FUNCTION_ARGS  )

Definition at line 1330 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().

1331 {
1334  RelativeTime rt;
1335 
1336  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1337  PG_RETURN_BOOL(false);
1339  TimeIntervalGetDatum(i)));
1340  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt >= t);
1341 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallengt ( PG_FUNCTION_ARGS  )

Definition at line 1302 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().

1303 {
1306  RelativeTime rt;
1307 
1308  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1309  PG_RETURN_BOOL(false);
1311  TimeIntervalGetDatum(i)));
1312  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt > t);
1313 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallenle ( PG_FUNCTION_ARGS  )

Definition at line 1316 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().

1317 {
1320  RelativeTime rt;
1321 
1322  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1323  PG_RETURN_BOOL(false);
1325  TimeIntervalGetDatum(i)));
1326  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt <= t);
1327 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallenlt ( PG_FUNCTION_ARGS  )

Definition at line 1288 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().

1289 {
1292  RelativeTime rt;
1293 
1294  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1295  PG_RETURN_BOOL(false);
1297  TimeIntervalGetDatum(i)));
1298  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt < t);
1299 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallenne ( PG_FUNCTION_ARGS  )

Definition at line 1274 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().

1275 {
1278  RelativeTime rt;
1279 
1280  if (i->status == T_INTERVAL_INVAL || t == INVALID_RELTIME)
1281  PG_RETURN_BOOL(false);
1283  TimeIntervalGetDatum(i)));
1284  PG_RETURN_BOOL(rt != INVALID_RELTIME && rt != t);
1285 }
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetRelativeTime(X)
Definition: nabstime.h:51
int32 RelativeTime
Definition: nabstime.h:37
#define PG_GETARG_RELATIVETIME(n)
Definition: nabstime.h:59
Datum tintervalrel(PG_FUNCTION_ARGS)
Definition: nabstime.c:974
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define TimeIntervalGetDatum(X)
Definition: nabstime.h:56
int i
Datum tintervallt ( PG_FUNCTION_ARGS  )

Definition at line 1200 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1201 {
1204 
1206 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalne ( PG_FUNCTION_ARGS  )

Definition at line 1191 of file nabstime.c.

References PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, and tinterval_cmp_internal().

1192 {
1195 
1196  PG_RETURN_BOOL(tinterval_cmp_internal(i1, i2) != 0);
1197 }
static int tinterval_cmp_internal(TimeInterval a, TimeInterval b)
Definition: nabstime.c:1140
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum tintervalout ( PG_FUNCTION_ARGS  )

Definition at line 731 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.

732 {
733  TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
734  char *i_str,
735  *p;
736 
737  i_str = (char *) palloc(T_INTERVAL_LEN); /* ["..." "..."] */
738  strcpy(i_str, "[\"");
739  if (tinterval->status == T_INTERVAL_INVAL)
740  strcat(i_str, INVALID_INTERVAL_STR);
741  else
742  {
744  AbsoluteTimeGetDatum(tinterval->data[0])));
745  strcat(i_str, p);
746  pfree(p);
747  strcat(i_str, "\" \"");
749  AbsoluteTimeGetDatum(tinterval->data[1])));
750  strcat(i_str, p);
751  pfree(p);
752  }
753  strcat(i_str, "\"]");
754  PG_RETURN_CSTRING(i_str);
755 }
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
Datum abstimeout(PG_FUNCTION_ARGS)
Definition: nabstime.c:260
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:584
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
void pfree(void *pointer)
Definition: mcxt.c:950
#define DatumGetCString(X)
Definition: postgres.h:572
#define INVALID_INTERVAL_STR
Definition: nabstime.c:57
AbsoluteTime data[2]
Definition: nabstime.h:42
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
#define T_INTERVAL_LEN
Definition: nabstime.c:56
void * palloc(Size size)
Definition: mcxt.c:849
Datum tintervalov ( PG_FUNCTION_ARGS  )

Definition at line 1368 of file nabstime.c.

References AbsoluteTimeGetDatum, abstimegt(), abstimelt(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.

1369 {
1372 
1373  if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
1374  PG_RETURN_BOOL(false);
1376  AbsoluteTimeGetDatum(i1->data[1]),
1377  AbsoluteTimeGetDatum(i2->data[0]))) ||
1379  AbsoluteTimeGetDatum(i1->data[0]),
1380  AbsoluteTimeGetDatum(i2->data[1]))))
1381  PG_RETURN_BOOL(false);
1382  PG_RETURN_BOOL(true);
1383 }
Datum abstimegt(PG_FUNCTION_ARGS)
Definition: nabstime.c:394
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetBool(X)
Definition: postgres.h:399
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AbsoluteTime data[2]
Definition: nabstime.h:42
Datum abstimelt(PG_FUNCTION_ARGS)
Definition: nabstime.c:385
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum tintervalrecv ( PG_FUNCTION_ARGS  )

Definition at line 761 of file nabstime.c.

References buf, TimeIntervalData::data, ereport, errcode(), errmsg(), ERROR, INVALID_ABSTIME, palloc(), PG_GETARG_POINTER, PG_RETURN_TIMEINTERVAL, pq_getmsgint(), TimeIntervalData::status, status(), T_INTERVAL_INVAL, and T_INTERVAL_VALID.

762 {
764  TimeInterval tinterval;
765  int32 status;
766 
767  tinterval = (TimeInterval) palloc(sizeof(TimeIntervalData));
768 
769  tinterval->status = pq_getmsgint(buf, sizeof(tinterval->status));
770  tinterval->data[0] = pq_getmsgint(buf, sizeof(tinterval->data[0]));
771  tinterval->data[1] = pq_getmsgint(buf, sizeof(tinterval->data[1]));
772 
773  if (tinterval->data[0] == INVALID_ABSTIME ||
774  tinterval->data[1] == INVALID_ABSTIME)
775  status = T_INTERVAL_INVAL; /* undefined */
776  else
777  status = T_INTERVAL_VALID;
778 
779  if (status != tinterval->status)
780  ereport(ERROR,
781  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
782  errmsg("invalid status in external \"tinterval\" value")));
783 
784  PG_RETURN_TIMEINTERVAL(tinterval);
785 }
TimeIntervalData * TimeInterval
Definition: nabstime.h:45
#define PG_RETURN_TIMEINTERVAL(x)
Definition: nabstime.h:64
#define T_INTERVAL_VALID
Definition: nabstime.c:47
StringInfoData * StringInfo
Definition: stringinfo.h:43
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
signed int int32
Definition: c.h:256
#define ERROR
Definition: elog.h:43
static char * buf
Definition: pg_test_fsync.c:66
#define INVALID_ABSTIME
Definition: nabstime.h:76
#define ereport(elevel, rest)
Definition: elog.h:122
AbsoluteTime data[2]
Definition: nabstime.h:42
void * palloc(Size size)
Definition: mcxt.c:849
int errmsg(const char *fmt,...)
Definition: elog.c:797
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:448
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
Datum tintervalrel ( PG_FUNCTION_ARGS  )

Definition at line 974 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().

975 {
976  TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
977  AbsoluteTime t1 = tinterval->data[0];
978  AbsoluteTime t2 = tinterval->data[1];
979 
980  if (tinterval->status != T_INTERVAL_VALID)
982 
983  if (AbsoluteTimeIsReal(t1) &&
984  AbsoluteTimeIsReal(t2))
985  PG_RETURN_RELATIVETIME(t2 - t1);
986 
988 }
#define PG_RETURN_RELATIVETIME(x)
Definition: nabstime.h:63
#define T_INTERVAL_VALID
Definition: nabstime.c:47
#define INVALID_RELTIME
Definition: nabstime.h:80
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
int32 AbsoluteTime
Definition: nabstime.h:36
AbsoluteTime data[2]
Definition: nabstime.h:42
#define AbsoluteTimeIsReal(time)
Definition: nabstime.h:91
Datum tintervalsame ( PG_FUNCTION_ARGS  )

Definition at line 1101 of file nabstime.c.

References AbsoluteTimeGetDatum, abstimeeq(), TimeIntervalData::data, DatumGetBool, DirectFunctionCall2, PG_GETARG_TIMEINTERVAL, PG_RETURN_BOOL, TimeIntervalData::status, and T_INTERVAL_INVAL.

1102 {
1105 
1106  if (i1->status == T_INTERVAL_INVAL || i2->status == T_INTERVAL_INVAL)
1107  PG_RETURN_BOOL(false);
1108 
1110  AbsoluteTimeGetDatum(i1->data[0]),
1111  AbsoluteTimeGetDatum(i2->data[0]))) &&
1113  AbsoluteTimeGetDatum(i1->data[1]),
1114  AbsoluteTimeGetDatum(i2->data[1]))))
1115  PG_RETURN_BOOL(true);
1116  PG_RETURN_BOOL(false);
1117 }
Datum abstimeeq(PG_FUNCTION_ARGS)
Definition: nabstime.c:367
#define AbsoluteTimeGetDatum(X)
Definition: nabstime.h:54
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define DatumGetBool(X)
Definition: postgres.h:399
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
AbsoluteTime data[2]
Definition: nabstime.h:42
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum tintervalsend ( PG_FUNCTION_ARGS  )

Definition at line 791 of file nabstime.c.

References buf, TimeIntervalData::data, PG_GETARG_TIMEINTERVAL, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), pq_sendint(), and TimeIntervalData::status.

792 {
793  TimeInterval tinterval = PG_GETARG_TIMEINTERVAL(0);
795 
796  pq_begintypsend(&buf);
797  pq_sendint(&buf, tinterval->status, sizeof(tinterval->status));
798  pq_sendint(&buf, tinterval->data[0], sizeof(tinterval->data[0]));
799  pq_sendint(&buf, tinterval->data[1], sizeof(tinterval->data[1]));
801 }
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:359
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:379
static char * buf
Definition: pg_test_fsync.c:66
AbsoluteTime data[2]
Definition: nabstime.h:42
void pq_sendint(StringInfo buf, int i, int b)
Definition: pqformat.c:236
Datum tintervalstart ( PG_FUNCTION_ARGS  )

Definition at line 1389 of file nabstime.c.

References TimeIntervalData::data, i, INVALID_ABSTIME, PG_GETARG_TIMEINTERVAL, PG_RETURN_ABSOLUTETIME, TimeIntervalData::status, and T_INTERVAL_INVAL.

1390 {
1392 
1393  if (i->status == T_INTERVAL_INVAL)
1396 }
#define PG_GETARG_TIMEINTERVAL(n)
Definition: nabstime.h:60
#define T_INTERVAL_INVAL
Definition: nabstime.c:46
#define PG_RETURN_ABSOLUTETIME(x)
Definition: nabstime.h:62
#define INVALID_ABSTIME
Definition: nabstime.h:76
AbsoluteTime data[2]
Definition: nabstime.h:42
int i
static AbsoluteTime tm2abstime ( struct pg_tm tm,
int  tz 
)
static

Definition at line 151 of file nabstime.c.

References AbsoluteTimeIsReal, date2j(), HOURS_PER_DAY, INVALID_ABSTIME, MAX_DAYNUM, MINS_PER_HOUR, MONTHS_PER_YEAR, SECS_PER_MINUTE, pg_tm::tm_hour, pg_tm::tm_mday, pg_tm::tm_min, pg_tm::tm_mon, pg_tm::tm_sec, pg_tm::tm_year, and UNIX_EPOCH_JDATE.

Referenced by abstimein(), timestamp_abstime(), and timestamptz_abstime().

152 {
153  int day;
154  AbsoluteTime sec;
155 
156  /* validate, before going out of range on some members */
157  if (tm->tm_year < 1901 || tm->tm_year > 2038 ||
158  tm->tm_mon < 1 || tm->tm_mon > MONTHS_PER_YEAR ||
159  tm->tm_mday < 1 || tm->tm_mday > 31 ||
160  tm->tm_hour < 0 ||
161  tm->tm_hour > HOURS_PER_DAY || /* test for > 24:00:00 */
162  (tm->tm_hour == HOURS_PER_DAY && (tm->tm_min > 0 || tm->tm_sec > 0)) ||
163  tm->tm_min < 0 || tm->tm_min > MINS_PER_HOUR - 1 ||
164  tm->tm_sec < 0 || tm->tm_sec > SECS_PER_MINUTE)
165  return INVALID_ABSTIME;
166 
167  day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;
168 
169  /* check for time out of range */
170  if (day < MIN_DAYNUM || day > MAX_DAYNUM)
171  return INVALID_ABSTIME;
172 
173  /* convert to seconds */
174  sec = tm->tm_sec + tz + (tm->tm_min + (day * HOURS_PER_DAY + tm->tm_hour) * MINS_PER_HOUR) * SECS_PER_MINUTE;
175 
176  /*
177  * check for overflow. We need a little slop here because the H/M/S plus
178  * TZ offset could add up to more than 1 day.
179  */
180  if ((day >= MAX_DAYNUM - 10 && sec < 0) ||
181  (day <= MIN_DAYNUM + 10 && sec > 0))
182  return INVALID_ABSTIME;
183 
184  /* check for reserved values (e.g. "current" on edge of usual range */
185  if (!AbsoluteTimeIsReal(sec))
186  return INVALID_ABSTIME;
187 
188  return sec;
189 }
int tm_hour
Definition: pgtime.h:29
#define MAX_DAYNUM
Definition: nabstime.c:33
#define MINS_PER_HOUR
Definition: timestamp.h:89
#define MONTHS_PER_YEAR
Definition: timestamp.h:69
int tm_mday
Definition: pgtime.h:30
#define HOURS_PER_DAY
Definition: timestamp.h:78
int tm_mon
Definition: pgtime.h:31
#define SECS_PER_MINUTE
Definition: timestamp.h:88
#define INVALID_ABSTIME
Definition: nabstime.h:76
int32 AbsoluteTime
Definition: nabstime.h:36
int date2j(int y, int m, int d)
Definition: datetime.c:292
#define AbsoluteTimeIsReal(time)
Definition: nabstime.h:91
int tm_year
Definition: pgtime.h:32
#define UNIX_EPOCH_JDATE
Definition: timestamp.h:162
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28