1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* nabstime.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
* parse almost any absolute date getdate(3) can (& some it can't)
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1998-12-14 00:34:17 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.47 1998/12/13 23:34:17 thomas Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
1997-01-10 21:19:49 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "postgres.h"
|
1997-03-18 17:36:50 +01:00
|
|
|
#include <miscadmin.h>
|
1997-03-26 04:14:37 +01:00
|
|
|
#ifdef HAVE_FLOAT_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#include <float.h>
|
1997-03-26 04:14:37 +01:00
|
|
|
#endif
|
1997-03-28 07:54:51 +01:00
|
|
|
#ifdef HAVE_LIMITS_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#include <limits.h>
|
1997-03-28 07:54:51 +01:00
|
|
|
#endif
|
1997-01-10 19:22:41 +01:00
|
|
|
#ifndef USE_POSIX_TIME
|
|
|
|
#include <sys/timeb.h>
|
|
|
|
#endif
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "access/xact.h"
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
static AbsoluteTime tm2abstime(struct tm * tm, int tz);
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MIN_DAYNUM -24856 /* December 13, 1901 */
|
|
|
|
#define MAX_DAYNUM 24854 /* January 18, 2038 */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
1997-03-18 17:36:50 +01:00
|
|
|
/* GetCurrentAbsoluteTime()
|
|
|
|
* Get the current system time. Set timezone parameters if not specified elsewhere.
|
|
|
|
* Define HasTZSet to allow clients to specify the default timezone.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Returns the number of seconds since epoch (January 1 1970 GMT)
|
|
|
|
*/
|
|
|
|
AbsoluteTime
|
1997-03-15 00:21:12 +01:00
|
|
|
GetCurrentAbsoluteTime(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
time_t now;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
#ifdef USE_POSIX_TIME
|
1997-09-08 04:41:22 +02:00
|
|
|
struct tm *tm;
|
1997-04-25 20:40:50 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
now = time(NULL);
|
|
|
|
#else /* ! USE_POSIX_TIME */
|
1997-09-08 04:41:22 +02:00
|
|
|
struct timeb tb; /* the old V7-ism */
|
1997-03-18 17:36:50 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
ftime(&tb);
|
|
|
|
now = tb.time;
|
1997-03-18 17:36:50 +01:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!HasCTZSet)
|
|
|
|
{
|
1997-03-18 17:36:50 +01:00
|
|
|
#ifdef USE_POSIX_TIME
|
1998-12-14 00:34:17 +01:00
|
|
|
#ifdef HAVE_TM_ZONE
|
1997-09-07 07:04:48 +02:00
|
|
|
tm = localtime(&now);
|
|
|
|
|
|
|
|
CTimeZone = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
|
|
|
|
CDayLight = (tm->tm_isdst > 0);
|
|
|
|
|
1998-12-14 00:34:17 +01:00
|
|
|
#if 0
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
|
|
|
* XXX is there a better way to get local timezone string w/o
|
|
|
|
* tzname? - tgl 97/03/18
|
|
|
|
*/
|
|
|
|
strftime(CTZName, MAXTZLEN, "%Z", tm);
|
1998-12-14 00:34:17 +01:00
|
|
|
#endif
|
|
|
|
/* XXX FreeBSD man pages indicate that this should work - thomas 1998-12-12 */
|
|
|
|
if (tzn != NULL)
|
|
|
|
strcpy(tzn, tm->tm_zone);
|
|
|
|
|
|
|
|
#elif defined(HAVE_INT_TIMEZONE)
|
|
|
|
tm = localtime(&now);
|
|
|
|
|
|
|
|
CDayLight = tm->tm_isdst;
|
|
|
|
CTimeZone = (tm->tm_isdst ? (timezone - 3600) : timezone);
|
|
|
|
strcpy(CTZName, tzname[tm->tm_isdst]);
|
|
|
|
#else
|
|
|
|
#error USE_POSIX_TIME defined but no time zone available
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
|
|
|
#else /* ! USE_POSIX_TIME */
|
|
|
|
CTimeZone = tb.timezone * 60;
|
|
|
|
CDayLight = (tb.dstflag != 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX does this work to get the local timezone string in V7? -
|
|
|
|
* tgl 97/03/18
|
|
|
|
*/
|
|
|
|
strftime(CTZName, MAXTZLEN, "%Z", localtime(&now));
|
1996-10-18 01:59:45 +02:00
|
|
|
#endif
|
1997-09-07 07:04:48 +02:00
|
|
|
};
|
1997-03-18 17:36:50 +01:00
|
|
|
|
|
|
|
#ifdef DATEDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
printf("GetCurrentAbsoluteTime- timezone is %s -> %d seconds from UTC\n",
|
|
|
|
CTZName, CTimeZone);
|
1997-03-18 17:36:50 +01:00
|
|
|
#endif
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return (AbsoluteTime) now;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* GetCurrentAbsoluteTime() */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
void
|
1997-09-07 07:04:48 +02:00
|
|
|
GetCurrentTime(struct tm * tm)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int tz;
|
1997-04-25 20:40:50 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
abstime2tm(GetCurrentTransactionStartTime(), &tz, tm, NULL);
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* GetCurrentTime() */
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
1997-09-07 07:04:48 +02:00
|
|
|
abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn)
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
{
|
1997-06-23 16:56:15 +02:00
|
|
|
#ifdef USE_POSIX_TIME
|
1997-09-08 04:41:22 +02:00
|
|
|
struct tm *tx;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#else /* ! USE_POSIX_TIME */
|
1997-09-08 04:41:22 +02:00
|
|
|
struct timeb tb; /* the old V7-ism */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
ftime(&tb);
|
1997-04-22 19:36:57 +02:00
|
|
|
#endif
|
1997-06-23 16:56:15 +02:00
|
|
|
|
|
|
|
#ifdef USE_POSIX_TIME
|
1997-09-07 07:04:48 +02:00
|
|
|
if (tzp != NULL)
|
1997-09-08 23:56:23 +02:00
|
|
|
tx = localtime((time_t *) &time);
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
|
|
|
{
|
1997-09-08 23:56:23 +02:00
|
|
|
tx = gmtime((time_t *) &time);
|
1997-09-07 07:04:48 +02:00
|
|
|
};
|
1997-06-23 16:56:15 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-02-02 02:28:12 +01:00
|
|
|
#if defined(DATEDEBUG)
|
1998-12-14 00:34:17 +01:00
|
|
|
#if (! defined(HAVE_TM_ZONE)) && defined(HAVE_INT_TIMEZONE)
|
1997-09-07 07:04:48 +02:00
|
|
|
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s %s dst=%d\n",
|
|
|
|
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
|
|
|
|
tzname[0], tzname[1], tx->tm_isdst);
|
1997-06-23 16:56:15 +02:00
|
|
|
#else
|
1997-09-07 07:04:48 +02:00
|
|
|
printf("datetime2tm- (localtime) %d.%02d.%02d %02d:%02d:%02d %s dst=%d\n",
|
|
|
|
tx->tm_year, tx->tm_mon, tx->tm_mday, tx->tm_hour, tx->tm_min, tx->tm_sec,
|
|
|
|
tx->tm_zone, tx->tm_isdst);
|
1997-06-23 16:56:15 +02:00
|
|
|
#endif
|
1998-02-02 02:28:12 +01:00
|
|
|
#endif
|
1997-06-23 16:56:15 +02:00
|
|
|
|
1997-10-30 15:06:47 +01:00
|
|
|
#ifdef USE_POSIX_TIME
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
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;
|
1997-06-23 16:56:15 +02:00
|
|
|
|
1998-12-14 00:34:17 +01:00
|
|
|
#ifdef HAVE_TM_ZONE
|
1997-09-07 07:04:48 +02:00
|
|
|
tm->tm_gmtoff = tx->tm_gmtoff;
|
|
|
|
tm->tm_zone = tx->tm_zone;
|
|
|
|
|
|
|
|
if (tzp != NULL)
|
|
|
|
*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)
|
|
|
|
strcpy(tzn, tm->tm_zone);
|
1998-12-14 00:34:17 +01:00
|
|
|
#elif defined(HAVE_INT_TIMEZONE)
|
|
|
|
if (tzp != NULL)
|
|
|
|
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
|
|
|
|
if (tzn != NULL)
|
|
|
|
strcpy(tzn, tzname[tm->tm_isdst]);
|
|
|
|
#else /* !HAVE_INT_TIMEZONE */
|
|
|
|
#error POSIX time support is broken
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
|
|
|
#else /* ! USE_POSIX_TIME */
|
|
|
|
if (tzp != NULL)
|
|
|
|
*tzp = tb.timezone * 60;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX does this work to get the local timezone string in V7? - tgl
|
|
|
|
* 97/03/18
|
|
|
|
*/
|
|
|
|
if (tzn != NULL)
|
|
|
|
strftime(tzn, MAXTZLEN, "%Z", localtime(&now));
|
1997-06-23 16:56:15 +02:00
|
|
|
#endif
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* abstime2tm() */
|
1997-03-15 00:21:12 +01:00
|
|
|
|
|
|
|
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
/* tm2abstime()
|
|
|
|
* Convert a tm structure to abstime.
|
|
|
|
* Note that tm has full year (not 1900-based) and 1-based month.
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static AbsoluteTime
|
1997-09-07 07:04:48 +02:00
|
|
|
tm2abstime(struct tm * tm, int tz)
|
1997-03-25 09:11:24 +01:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int day,
|
|
|
|
sec;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* validate, before going out of range on some members */
|
|
|
|
if (tm->tm_year < 1901 || tm->tm_year > 2038
|
|
|
|
|| tm->tm_mon < 1 || tm->tm_mon > 12
|
|
|
|
|| tm->tm_mday < 1 || tm->tm_mday > 31
|
|
|
|
|| tm->tm_hour < 0 || tm->tm_hour >= 24
|
|
|
|
|| tm->tm_min < 0 || tm->tm_min > 59
|
|
|
|
|| tm->tm_sec < 0 || tm->tm_sec > 59)
|
1998-09-01 05:29:17 +02:00
|
|
|
return INVALID_ABSTIME;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
day = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(1970, 1, 1));
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* check for time out of range */
|
|
|
|
if ((day < MIN_DAYNUM) || (day > MAX_DAYNUM))
|
1998-09-01 05:29:17 +02:00
|
|
|
return INVALID_ABSTIME;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* convert to seconds */
|
|
|
|
sec = tm->tm_sec + tz + (tm->tm_min + (day * 24 + tm->tm_hour) * 60) * 60;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* check for overflow */
|
|
|
|
if ((day == MAX_DAYNUM && sec < 0) ||
|
|
|
|
(day == MIN_DAYNUM && sec > 0))
|
1998-09-01 05:29:17 +02:00
|
|
|
return INVALID_ABSTIME;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* check for reserved values (e.g. "current" on edge of usual range */
|
|
|
|
if (!AbsoluteTimeIsReal(sec))
|
1998-09-01 05:29:17 +02:00
|
|
|
return INVALID_ABSTIME;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return sec;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* tm2abstime() */
|
1997-03-25 09:11:24 +01:00
|
|
|
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
/* nabstimein()
|
|
|
|
* Decode date/time string and return abstime.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-03-15 00:21:12 +01:00
|
|
|
AbsoluteTime
|
1997-09-07 07:04:48 +02:00
|
|
|
nabstimein(char *str)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
AbsoluteTime result;
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
double fsec;
|
|
|
|
int tz = 0;
|
|
|
|
struct tm date,
|
|
|
|
*tm = &date;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
char *field[MAXDATEFIELDS];
|
|
|
|
char lowstr[MAXDATELEN + 1];
|
|
|
|
int dtype;
|
|
|
|
int nf,
|
|
|
|
ftype[MAXDATEFIELDS];
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (!PointerIsValid(str))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Bad (null) abstime external representation", NULL);
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (strlen(str) > MAXDATELEN)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Bad (length) abstime external representation '%s'", str);
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
|
|
|
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Bad abstime external representation '%s'", str);
|
1997-03-15 00:21:12 +01:00
|
|
|
|
|
|
|
#ifdef DATEDEBUG
|
1997-09-07 07:04:48 +02:00
|
|
|
printf("nabstimein- %d fields are type %d (DTK_DATE=%d)\n", nf, dtype, DTK_DATE);
|
1997-03-15 00:21:12 +01:00
|
|
|
#endif
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (dtype)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_DATE:
|
|
|
|
result = tm2abstime(tm, tz);
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_EPOCH:
|
|
|
|
result = EPOCH_ABSTIME;
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_CURRENT:
|
|
|
|
result = CURRENT_ABSTIME;
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_LATE:
|
|
|
|
result = NOEND_ABSTIME;
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_EARLY:
|
|
|
|
result = NOSTART_ABSTIME;
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case DTK_INVALID:
|
|
|
|
result = INVALID_ABSTIME;
|
|
|
|
break;
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Bad abstime (internal coding error) '%s'", str);
|
1997-09-08 04:41:22 +02:00
|
|
|
result = INVALID_ABSTIME;
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
};
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
return result;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* nabstimein() */
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-06-23 16:56:15 +02:00
|
|
|
/* nabstimeout()
|
1996-07-09 08:22:35 +02:00
|
|
|
* Given an AbsoluteTime return the English text version of the date
|
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
char *
|
1996-07-09 08:22:35 +02:00
|
|
|
nabstimeout(AbsoluteTime time)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *result;
|
|
|
|
int tz;
|
|
|
|
double fsec = 0;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
char buf[MAXDATELEN + 1];
|
|
|
|
char zone[MAXDATELEN + 1],
|
|
|
|
*tzn = zone;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
switch (time)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case EPOCH_ABSTIME:
|
|
|
|
strcpy(buf, EPOCH);
|
|
|
|
break;
|
|
|
|
case INVALID_ABSTIME:
|
|
|
|
strcpy(buf, INVALID);
|
|
|
|
break;
|
|
|
|
case CURRENT_ABSTIME:
|
|
|
|
strcpy(buf, DCURRENT);
|
|
|
|
break;
|
|
|
|
case NOEND_ABSTIME:
|
|
|
|
strcpy(buf, LATE);
|
|
|
|
break;
|
|
|
|
case NOSTART_ABSTIME:
|
|
|
|
strcpy(buf, EARLY);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abstime2tm(time, &tz, tm, tzn);
|
1997-06-23 16:56:15 +02:00
|
|
|
#if DATEDEBUG
|
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
EncodeDateTime(tm, fsec, &tz, &tzn, DateStyle, buf);
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1998-01-07 19:47:07 +01:00
|
|
|
result = palloc(strlen(buf) + 1);
|
1997-09-07 07:04:48 +02:00
|
|
|
strcpy(result, buf);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* nabstimeout() */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* AbsoluteTimeIsBefore -- true iff time1 is before time2.
|
|
|
|
* AbsoluteTimeIsBefore -- true iff time1 is after time2.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Assert(AbsoluteTimeIsValid(time1));
|
|
|
|
Assert(AbsoluteTimeIsValid(time2));
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (time1 == CURRENT_ABSTIME)
|
|
|
|
time1 = GetCurrentTransactionStartTime();
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (time2 == CURRENT_ABSTIME)
|
|
|
|
time2 = GetCurrentTransactionStartTime();
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return time1 < time2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1998-10-08 20:30:52 +02:00
|
|
|
#ifdef NOT_USED
|
1996-07-09 08:22:35 +02:00
|
|
|
bool
|
|
|
|
AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
Assert(AbsoluteTimeIsValid(time1));
|
|
|
|
Assert(AbsoluteTimeIsValid(time2));
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (time1 == CURRENT_ABSTIME)
|
|
|
|
time1 = GetCurrentTransactionStartTime();
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (time2 == CURRENT_ABSTIME)
|
|
|
|
time2 = GetCurrentTransactionStartTime();
|
1997-03-15 00:21:12 +01:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return time1 > time2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1998-10-08 20:30:52 +02:00
|
|
|
#endif
|
1996-07-09 08:22:35 +02:00
|
|
|
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
/* abstime_finite()
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
abstime_finite(AbsoluteTime abstime)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
return ((abstime != INVALID_ABSTIME)
|
|
|
|
&& (abstime != NOSTART_ABSTIME) && (abstime != NOEND_ABSTIME));
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* abstime_finite() */
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* abstimeeq - returns 1, iff arguments are equal
|
|
|
|
* abstimene - returns 1, iff arguments are not equal
|
|
|
|
* abstimelt - returns 1, iff t1 less than t2
|
|
|
|
* abstimegt - returns 1, iff t1 greater than t2
|
|
|
|
* abstimele - returns 1, iff t1 less than or equal to t2
|
|
|
|
* abstimege - returns 1, iff t1 greater than or equal to t2
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimeeq(AbsoluteTime t1, AbsoluteTime t2)
|
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 == t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimene(AbsoluteTime t1, AbsoluteTime t2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 != t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimelt(AbsoluteTime t1, AbsoluteTime t2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 < t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimegt(AbsoluteTime t1, AbsoluteTime t2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 > t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimele(AbsoluteTime t1, AbsoluteTime t2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 <= t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-03-15 00:21:12 +01:00
|
|
|
bool
|
1996-07-09 08:22:35 +02:00
|
|
|
abstimege(AbsoluteTime t1, AbsoluteTime t2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
if (t1 == INVALID_ABSTIME || t2 == INVALID_ABSTIME)
|
1998-09-01 05:29:17 +02:00
|
|
|
return FALSE;
|
1997-09-07 07:04:48 +02:00
|
|
|
if (t1 == CURRENT_ABSTIME)
|
|
|
|
t1 = GetCurrentTransactionStartTime();
|
|
|
|
if (t2 == CURRENT_ABSTIME)
|
|
|
|
t2 = GetCurrentTransactionStartTime();
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return t1 >= t2;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-03-25 09:11:24 +01:00
|
|
|
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-03-25 09:11:24 +01:00
|
|
|
/* datetime_abstime()
|
|
|
|
* Convert datetime to abstime.
|
|
|
|
*/
|
|
|
|
AbsoluteTime
|
1997-09-08 23:56:23 +02:00
|
|
|
datetime_abstime(DateTime *datetime)
|
1997-03-25 09:11:24 +01:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
AbsoluteTime result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
double fsec;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (!PointerIsValid(datetime))
|
|
|
|
{
|
|
|
|
result = INVALID_ABSTIME;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (DATETIME_IS_INVALID(*datetime))
|
|
|
|
{
|
|
|
|
result = INVALID_ABSTIME;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (DATETIME_IS_NOBEGIN(*datetime))
|
|
|
|
{
|
|
|
|
result = NOSTART_ABSTIME;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (DATETIME_IS_NOEND(*datetime))
|
|
|
|
{
|
|
|
|
result = NOEND_ABSTIME;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (DATETIME_IS_RELATIVE(*datetime))
|
|
|
|
{
|
|
|
|
datetime2tm(SetDateTime(*datetime), NULL, tm, &fsec, NULL);
|
|
|
|
result = tm2abstime(tm, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (datetime2tm(*datetime, NULL, tm, &fsec, NULL) == 0)
|
|
|
|
{
|
|
|
|
result = tm2abstime(tm, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = INVALID_ABSTIME;
|
|
|
|
};
|
1997-03-25 09:11:24 +01:00
|
|
|
};
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* datetime_abstime() */
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
|
|
|
/* abstime_datetime()
|
1997-10-25 07:21:10 +02:00
|
|
|
* Convert abstime to datetime.
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
DateTime *
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
abstime_datetime(AbsoluteTime abstime)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
DateTime *result;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1998-01-07 19:47:07 +01:00
|
|
|
if (!PointerIsValid(result = palloc(sizeof(DateTime))))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "Unable to allocate space to convert abstime to datetime", NULL);
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
switch (abstime)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case INVALID_ABSTIME:
|
|
|
|
DATETIME_INVALID(*result);
|
|
|
|
break;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case NOSTART_ABSTIME:
|
|
|
|
DATETIME_NOBEGIN(*result);
|
|
|
|
break;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case NOEND_ABSTIME:
|
|
|
|
DATETIME_NOEND(*result);
|
|
|
|
break;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case EPOCH_ABSTIME:
|
|
|
|
DATETIME_EPOCH(*result);
|
|
|
|
break;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case CURRENT_ABSTIME:
|
|
|
|
DATETIME_CURRENT(*result);
|
|
|
|
break;
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
default:
|
|
|
|
*result = abstime + ((date2j(1970, 1, 1) - date2j(2000, 1, 1)) * 86400);
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
};
|
From: Thomas Lockhart <Thomas.G.Lockhart@jpl.nasa.gov>
Subject: [HACKERS] More date time functions
Here are some additional patches mostly related to the date and time
data types. It includes some type conversion routines to move between
the different date types and some other date manipulation routines such
as date_part(units,datetime).
I noticed Edmund Mergl et al's neat trick for getting function overloading
for builtin functions, so started to use that for the date and time stuff.
Later, if someone figures out how to get function overloading directly
for internal C code, then we can move to that technique.
These patches include documentation updates (don't faint!) for the built-in
man page. Doesn't yet include mention of timestamp, since I don't know
much about it and since it may change a bit to become a _real_ ANSI timestamp
which would include parser support for the declaration syntax (what do you
think, Dan?).
The patches were developed on the 970330 release, but have been rebuilt
off of the 970402 release. The first patch below is to get libpq to compile,
on my Linux box, but is not related to the rest of the patches and you can
choose not to apply that one at this time. Thanks in advance, scrappy!
1997-04-02 20:36:24 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1998-02-26 05:46:47 +01:00
|
|
|
} /* abstime_datetime() */
|