PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nabstime.h File Reference
#include <limits.h>
#include "fmgr.h"
#include "pgtime.h"
Include dependency graph for nabstime.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TimeIntervalData
 

Macros

#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) /* 2147483647 (2^31 - 1) */
 
#define NOEND_ABSTIME   ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
 
#define NOSTART_ABSTIME   ((AbsoluteTime) INT_MIN) /* -2147483648 */
 
#define INVALID_RELTIME   ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
 
#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 TimeIntervalDataTimeInterval
 

Functions

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

Macro Definition Documentation

#define AbsoluteTimeGetDatum (   X)    Int32GetDatum(X)

Definition at line 54 of file nabstime.h.

Referenced by intinterval(), tintervalct(), tintervalout(), tintervalov(), and tintervalsame().

#define AbsoluteTimeIsReal (   time)
Value:
((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \
((AbsoluteTime) (time)) != NOSTART_ABSTIME))
#define NOSTART_ABSTIME
Definition: nabstime.h:78
char bool
Definition: c.h:199
int32 AbsoluteTime
Definition: nabstime.h:36
#define NOEND_ABSTIME
Definition: nabstime.h:77

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))
#define DatumGetTimeInterval (   X)    ((TimeInterval) DatumGetPointer(X))

Definition at line 52 of file nabstime.h.

Referenced by convert_timevalue_to_scalar().

#define INVALID_RELTIME   ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
#define NOEND_ABSTIME   ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
#define NOSTART_ABSTIME   ((AbsoluteTime) INT_MIN) /* -2147483648 */
#define PG_RETURN_ABSOLUTETIME (   x)    return AbsoluteTimeGetDatum(x)
#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.

Referenced by timemi(), and timepl().

#define TimeIntervalGetDatum (   X)    PointerGetDatum(X)

Typedef Documentation

Definition at line 36 of file nabstime.h.

Definition at line 37 of file nabstime.h.

Definition at line 45 of file nabstime.h.

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:1295
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:237
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:226
#define StrNCpy(dst, src, len)
Definition: c.h:826
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition: localtime.c:1254
int tm_year
Definition: pgtime.h:32
int errmsg(const char *fmt,...)
Definition: elog.c:797
pg_tz * session_timezone
Definition: pgtz.c:27
int tm_sec
Definition: pgtime.h:27
int tm_min
Definition: pgtime.h:28
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:226
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1533