Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Typedefs | Functions

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

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 TimeIntervalDataTimeInterval

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

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_ABSTIME   ((AbsoluteTime) 0x7FFFFFFE)
#define INVALID_RELTIME   ((RelativeTime) 0x7FFFFFFE)
#define NOEND_ABSTIME   ((AbsoluteTime) 0x7FFFFFFC)
#define NOSTART_ABSTIME   ((AbsoluteTime) INT_MIN)
#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)

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 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   ) 
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   ) 
Datum abstimege ( PG_FUNCTION_ARGS   ) 
Datum abstimegt ( PG_FUNCTION_ARGS   ) 
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   ) 
Datum abstimelt ( PG_FUNCTION_ARGS   ) 
Datum abstimene ( PG_FUNCTION_ARGS   ) 
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   ) 
Datum abstimesend ( PG_FUNCTION_ARGS   ) 
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   ) 
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   ) 
Datum reltimege ( PG_FUNCTION_ARGS   ) 
Datum reltimegt ( PG_FUNCTION_ARGS   ) 
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   ) 
Datum reltimelt ( PG_FUNCTION_ARGS   ) 
Datum reltimene ( PG_FUNCTION_ARGS   ) 
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   ) 
Datum reltimesend ( PG_FUNCTION_ARGS   ) 
Datum timemi ( PG_FUNCTION_ARGS   ) 
Datum timenow ( PG_FUNCTION_ARGS   ) 
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   ) 
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   ) 
Datum tintervalend ( PG_FUNCTION_ARGS   ) 
Datum tintervaleq ( PG_FUNCTION_ARGS   ) 
Datum tintervalge ( PG_FUNCTION_ARGS   ) 
Datum tintervalgt ( PG_FUNCTION_ARGS   ) 
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   ) 
Datum tintervalleneq ( PG_FUNCTION_ARGS   ) 
Datum tintervallenge ( PG_FUNCTION_ARGS   ) 
Datum tintervallengt ( PG_FUNCTION_ARGS   ) 
Datum tintervallenle ( PG_FUNCTION_ARGS   ) 
Datum tintervallenlt ( PG_FUNCTION_ARGS   ) 
Datum tintervallenne ( PG_FUNCTION_ARGS   ) 
Datum tintervallt ( PG_FUNCTION_ARGS   ) 
Datum tintervalne ( PG_FUNCTION_ARGS   ) 
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   ) 
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   ) 
Datum tintervalsame ( PG_FUNCTION_ARGS   ) 
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   )