1996-07-09 06:22:35 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-13 23:22:53 +00:00
|
|
|
* date.c
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
* implements DATE and TIME data types specified in SQL-92 standard
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
2000-01-26 05:58:53 +00:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
* Portions Copyright (c) 1994-5, Regents of the University of California
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-03-14 23:06:59 +00:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.43 2000/03/14 23:06:35 thomas Exp $
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
#include <limits.h>
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
#include "postgres.h"
|
1997-04-04 08:53:08 +00:00
|
|
|
#ifdef HAVE_FLOAT_H
|
1997-09-07 05:04:48 +00:00
|
|
|
#include <float.h>
|
1997-04-04 08:53:08 +00:00
|
|
|
#endif
|
1999-07-16 05:00:38 +00:00
|
|
|
#include "miscadmin.h"
|
1999-07-16 03:14:30 +00:00
|
|
|
#include "utils/builtins.h"
|
1997-03-14 23:21:12 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
static int
|
|
|
|
date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn);
|
1997-03-14 23:21:12 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
/*****************************************************************************
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
* Date ADT
|
1996-07-09 06:22:35 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
|
|
|
|
/* date_in()
|
|
|
|
* Given date text string, convert to internal date format.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
date_in(char *str)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT date;
|
|
|
|
double fsec;
|
1997-09-08 02:41:22 +00:00
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int tzp;
|
1997-09-08 02:41:22 +00:00
|
|
|
int dtype;
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int nf;
|
1997-09-08 02:41:22 +00:00
|
|
|
char *field[MAXDATEFIELDS];
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int ftype[MAXDATEFIELDS];
|
1997-09-08 02:41:22 +00:00
|
|
|
char lowstr[MAXDATELEN + 1];
|
1997-03-14 23:21:12 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
if (!PointerIsValid(str))
|
2000-01-15 02:59:43 +00:00
|
|
|
elog(ERROR, "Bad (null) date external representation");
|
1997-03-14 23:21:12 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
|
|
|
|
elog(ERROR, "Bad date external representation '%s'", str);
|
1997-03-14 23:21:12 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
switch (dtype)
|
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
case DTK_DATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTK_CURRENT:
|
|
|
|
GetCurrentTime(tm);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DTK_EPOCH:
|
|
|
|
tm->tm_year = 1970;
|
|
|
|
tm->tm_mon = 1;
|
|
|
|
tm->tm_mday = 1;
|
|
|
|
break;
|
1997-03-14 23:21:12 +00:00
|
|
|
|
1997-09-08 02:41:22 +00:00
|
|
|
default:
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
elog(ERROR, "Unrecognized date external representation '%s'", str);
|
1997-09-07 05:04:48 +00:00
|
|
|
}
|
1997-03-14 23:21:12 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
date = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1));
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return date;
|
|
|
|
} /* date_in() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* date_out()
|
|
|
|
* Given internal format date, convert to text string.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
char *
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
date_out(DateADT date)
|
1997-07-29 15:54:49 +00:00
|
|
|
{
|
1997-09-08 02:41:22 +00:00
|
|
|
char *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
char buf[MAXDATELEN + 1];
|
1997-07-29 15:54:49 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
j2date((date + date2j(2000, 1, 1)),
|
|
|
|
&(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
1997-07-29 15:54:49 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
EncodeDateOnly(tm, DateStyle, buf);
|
1997-07-29 15:54:49 +00:00
|
|
|
|
1998-01-07 18:47:07 +00:00
|
|
|
result = palloc(strlen(buf) + 1);
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
strcpy(result, buf);
|
1997-07-29 15:54:49 +00:00
|
|
|
|
1998-09-01 03:29:17 +00:00
|
|
|
return result;
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
} /* date_out() */
|
1997-07-29 15:54:49 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_eq(DateADT dateVal1, DateADT dateVal2)
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal1 == dateVal2;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_ne(DateADT dateVal1, DateADT dateVal2)
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal1 != dateVal2;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_lt(DateADT dateVal1, DateADT dateVal2)
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal1 < dateVal2;
|
|
|
|
} /* date_lt() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_le(DateADT dateVal1, DateADT dateVal2)
|
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 18:36:24 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal1 <= dateVal2;
|
|
|
|
} /* date_le() */
|
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 18:36:24 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_gt(DateADT dateVal1, DateADT dateVal2)
|
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 18:36:24 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal1 > dateVal2;
|
|
|
|
} /* date_gt() */
|
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 18:36:24 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
bool
|
|
|
|
date_ge(DateADT dateVal1, DateADT dateVal2)
|
|
|
|
{
|
|
|
|
return dateVal1 >= dateVal2;
|
|
|
|
} /* date_ge() */
|
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 18:36:24 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int
|
|
|
|
date_cmp(DateADT dateVal1, DateADT dateVal2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (dateVal1 < dateVal2)
|
|
|
|
return -1;
|
|
|
|
else if (dateVal1 > dateVal2)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
} /* date_cmp() */
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
date_larger(DateADT dateVal1, DateADT dateVal2)
|
|
|
|
{
|
|
|
|
return date_gt(dateVal1, dateVal2) ? dateVal1 : dateVal2;
|
|
|
|
} /* date_larger() */
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
date_smaller(DateADT dateVal1, DateADT dateVal2)
|
|
|
|
{
|
|
|
|
return date_lt(dateVal1, dateVal2) ? dateVal1 : dateVal2;
|
|
|
|
} /* date_smaller() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* Compute difference between two dates in days.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int4
|
|
|
|
date_mi(DateADT dateVal1, DateADT dateVal2)
|
|
|
|
{
|
|
|
|
return dateVal1 - dateVal2;
|
|
|
|
} /* date_mi() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* Add a number of days to a date, giving a new date.
|
|
|
|
* Must handle both positive and negative numbers of days.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
date_pli(DateADT dateVal, int4 days)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return dateVal + days;
|
|
|
|
} /* date_pli() */
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* Subtract a number of days from a date, giving a new date.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
date_mii(DateADT dateVal, int4 days)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return date_pli(dateVal, -days);
|
|
|
|
} /* date_mii() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* date_timestamp()
|
|
|
|
* Convert date to timestamp data type.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
Timestamp *
|
|
|
|
date_timestamp(DateADT dateVal)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
Timestamp *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
|
|
|
double fsec = 0;
|
|
|
|
char *tzn;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
result = palloc(sizeof(*result));
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (date2tm(dateVal, &tz, tm, &fsec, &tzn) != 0)
|
|
|
|
elog(ERROR, "Unable to convert date to timestamp");
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (tm2timestamp(tm, fsec, &tz, result) != 0)
|
|
|
|
elog(ERROR, "Timestamp out of range");
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* date_timestamp() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* timestamp_date()
|
|
|
|
* Convert timestamp to date data type.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
timestamp_date(Timestamp *timestamp)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
|
|
|
double fsec;
|
|
|
|
char *tzn;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(timestamp))
|
|
|
|
elog(ERROR, "Unable to convert null timestamp to date");
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (TIMESTAMP_NOT_FINITE(*timestamp))
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (TIMESTAMP_IS_EPOCH(*timestamp))
|
|
|
|
{
|
|
|
|
timestamp2tm(SetTimestamp(*timestamp), NULL, tm, &fsec, NULL);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
}
|
|
|
|
else if (TIMESTAMP_IS_CURRENT(*timestamp))
|
|
|
|
{
|
|
|
|
timestamp2tm(SetTimestamp(*timestamp), &tz, tm, &fsec, &tzn);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (timestamp2tm(*timestamp, &tz, tm, &fsec, &tzn) != 0)
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
|
|
|
}
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
result = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1));
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* timestamp_date() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* abstime_date()
|
|
|
|
* Convert abstime to date data type.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT
|
|
|
|
abstime_date(AbsoluteTime abstime)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
DateADT result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
switch (abstime)
|
|
|
|
{
|
|
|
|
case INVALID_ABSTIME:
|
|
|
|
case NOSTART_ABSTIME:
|
|
|
|
case NOEND_ABSTIME:
|
|
|
|
elog(ERROR, "Unable to convert reserved abstime value to date");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pretend to drop through to make compiler think that result
|
|
|
|
* will be set
|
|
|
|
*/
|
|
|
|
|
|
|
|
case EPOCH_ABSTIME:
|
|
|
|
result = date2j(1970, 1, 1) - date2j(2000, 1, 1);
|
|
|
|
break;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
case CURRENT_ABSTIME:
|
|
|
|
GetCurrentTime(tm);
|
|
|
|
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
|
|
|
|
break;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
default:
|
|
|
|
abstime2tm(abstime, &tz, tm, NULL);
|
|
|
|
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1);
|
|
|
|
break;
|
|
|
|
}
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* abstime_date() */
|
1997-09-20 16:17:45 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* date2tm()
|
|
|
|
* Convert date to time structure.
|
|
|
|
* Note that date is an implicit local time, but the system calls assume
|
|
|
|
* that everything is GMT. So, convert to GMT, rotate to local time,
|
|
|
|
* and then convert again to try to get the time zones correct.
|
1997-09-20 16:17:45 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
static int
|
|
|
|
date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn)
|
1997-09-20 16:17:45 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
struct tm *tx;
|
|
|
|
time_t utime;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
*fsec = 0;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
j2date((dateVal + date2j(2000, 1, 1)), &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
|
|
|
|
tm->tm_hour = 0;
|
|
|
|
tm->tm_min = 0;
|
|
|
|
tm->tm_sec = 0;
|
|
|
|
tm->tm_isdst = -1;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (IS_VALID_UTIME(tm->tm_year, tm->tm_mon, tm->tm_mday))
|
|
|
|
{
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* convert to system time */
|
|
|
|
utime = ((dateVal + (date2j(2000, 1, 1) - date2j(1970, 1, 1))) * 86400);
|
|
|
|
/* rotate to noon to get the right day in time zone */
|
|
|
|
utime += (12 * 60 * 60);
|
|
|
|
|
|
|
|
#ifdef USE_POSIX_TIME
|
|
|
|
tx = localtime(&utime);
|
|
|
|
|
|
|
|
tm->tm_year = tx->tm_year + 1900;
|
|
|
|
tm->tm_mon = tx->tm_mon + 1;
|
|
|
|
tm->tm_mday = tx->tm_mday;
|
|
|
|
tm->tm_isdst = tx->tm_isdst;
|
|
|
|
|
|
|
|
#if defined(HAVE_TM_ZONE)
|
|
|
|
tm->tm_gmtoff = tx->tm_gmtoff;
|
|
|
|
tm->tm_zone = tx->tm_zone;
|
|
|
|
|
|
|
|
/* tm_gmtoff is Sun/DEC-ism */
|
|
|
|
*tzp = -(tm->tm_gmtoff);
|
|
|
|
if (tzn != NULL)
|
|
|
|
*tzn = (char *) tm->tm_zone;
|
|
|
|
#elif defined(HAVE_INT_TIMEZONE)
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
*tzp = (tm->tm_isdst ? (_timezone - 3600) : _timezone);
|
|
|
|
#else
|
|
|
|
*tzp = (tm->tm_isdst ? (timezone - 3600) : timezone);
|
|
|
|
#endif
|
|
|
|
if (tzn != NULL)
|
|
|
|
*tzn = tzname[(tm->tm_isdst > 0)];
|
|
|
|
#else
|
|
|
|
#error USE_POSIX_TIME is defined but neither HAVE_TM_ZONE or HAVE_INT_TIMEZONE are defined
|
|
|
|
#endif
|
|
|
|
#else /* !USE_POSIX_TIME */
|
|
|
|
*tzp = CTimeZone; /* V7 conventions; don't know timezone? */
|
|
|
|
if (tzn != NULL)
|
|
|
|
*tzn = CTZName;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* otherwise, outside of timezone range so convert to GMT... */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*tzp = 0;
|
|
|
|
tm->tm_isdst = 0;
|
|
|
|
if (tzn != NULL)
|
|
|
|
*tzn = NULL;
|
|
|
|
}
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return 0;
|
|
|
|
} /* date2tm() */
|
1997-09-20 16:17:45 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Time ADT
|
|
|
|
*****************************************************************************/
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
|
|
|
|
TimeADT *
|
|
|
|
time_in(char *str)
|
1997-09-20 16:17:45 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
TimeADT *time;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
double fsec;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int nf;
|
|
|
|
char lowstr[MAXDATELEN + 1];
|
|
|
|
char *field[MAXDATEFIELDS];
|
|
|
|
int dtype;
|
|
|
|
int ftype[MAXDATEFIELDS];
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(str))
|
|
|
|
elog(ERROR, "Bad (null) time external representation");
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
2000-03-14 23:06:59 +00:00
|
|
|
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, NULL) != 0))
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
elog(ERROR, "Bad time external representation '%s'", str);
|
1997-09-20 16:17:45 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
time = palloc(sizeof(*time));
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
*time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return time;
|
|
|
|
} /* time_in() */
|
1997-09-20 16:17:45 +00:00
|
|
|
|
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
char *
|
|
|
|
time_out(TimeADT *time)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
double fsec;
|
|
|
|
char buf[MAXDATELEN + 1];
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time))
|
|
|
|
return NULL;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
tm->tm_hour = (*time / (60 * 60));
|
|
|
|
tm->tm_min = (((int) (*time / 60)) % 60);
|
|
|
|
tm->tm_sec = (((int) *time) % 60);
|
1997-09-20 16:17:45 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
fsec = 0;
|
1997-09-20 16:17:45 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
EncodeTimeOnly(tm, fsec, NULL, DateStyle, buf);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
result = palloc(strlen(buf) + 1);
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
strcpy(result, buf);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* time_out() */
|
1997-09-07 05:04:48 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_eq(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return *time1 == *time2;
|
|
|
|
} /* time_eq() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_ne(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return *time1 != *time2;
|
|
|
|
} /* time_eq() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_lt(TimeADT *time1, TimeADT *time2)
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
return (*time1 < *time2);
|
|
|
|
} /* time_lt() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_le(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
return (*time1 <= *time2);
|
|
|
|
} /* time_le() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_gt(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
return (*time1 > *time2);
|
|
|
|
} /* time_gt() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
bool
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
time_ge(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
1996-07-09 06:22:35 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
return (*time1 >= *time2);
|
|
|
|
} /* time_ge() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int
|
|
|
|
time_cmp(TimeADT *time1, TimeADT *time2)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return (*time1 < *time2) ? -1 : (((*time1 > *time2) ? 1 : 0));
|
|
|
|
} /* time_cmp() */
|
1996-07-09 06:22:35 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
TimeADT *
|
|
|
|
time_larger(TimeADT *time1, TimeADT *time2)
|
|
|
|
{
|
|
|
|
return time_gt(time1, time2)? time1: time2;
|
|
|
|
} /* time_larger() */
|
|
|
|
|
|
|
|
TimeADT *
|
|
|
|
time_smaller(TimeADT *time1, TimeADT *time2)
|
|
|
|
{
|
|
|
|
return time_lt(time1, time2)? time1: time2;
|
|
|
|
} /* time_smaller() */
|
|
|
|
|
|
|
|
/* overlaps_time()
|
|
|
|
* Implements the SQL92 OVERLAPS operator.
|
|
|
|
* Algorithm from Date and Darwen, 1997
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
overlaps_time(TimeADT *ts1, TimeADT *te1, TimeADT *ts2, TimeADT *te2)
|
|
|
|
{
|
|
|
|
/* Make sure we have ordered pairs... */
|
|
|
|
if (time_gt(ts1, te1))
|
|
|
|
{
|
|
|
|
TimeADT *tt = ts1;
|
|
|
|
ts1 = te1;
|
|
|
|
te1 = tt;
|
|
|
|
}
|
|
|
|
if (time_gt(ts2, te2))
|
|
|
|
{
|
|
|
|
TimeADT *tt = ts2;
|
|
|
|
ts2 = te2;
|
|
|
|
te2 = tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((time_gt(ts1, ts2) && (time_lt(ts1, te2) || time_lt(te1, te2)))
|
|
|
|
|| (time_gt(ts2, ts1) && (time_lt(ts2, te1) || time_lt(te2, te1)))
|
|
|
|
|| time_eq(ts1, ts2));
|
|
|
|
}
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* timestamp_time()
|
|
|
|
* Convert timestamp to time data type.
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
TimeADT *
|
|
|
|
timestamp_time(Timestamp *timestamp)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
TimeADT *result;
|
1997-09-08 02:41:22 +00:00
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
int tz;
|
1997-09-08 02:41:22 +00:00
|
|
|
double fsec;
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
char *tzn;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(timestamp))
|
|
|
|
elog(ERROR, "Unable to convert null timestamp to date");
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (TIMESTAMP_NOT_FINITE(*timestamp))
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (TIMESTAMP_IS_EPOCH(*timestamp))
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
timestamp2tm(SetTimestamp(*timestamp), NULL, tm, &fsec, NULL);
|
1998-09-01 04:40:42 +00:00
|
|
|
}
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
else if (TIMESTAMP_IS_CURRENT(*timestamp))
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
timestamp2tm(SetTimestamp(*timestamp), &tz, tm, &fsec, &tzn);
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
else
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (timestamp2tm(*timestamp, &tz, tm, &fsec, &tzn) != 0)
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
1997-09-07 05:04:48 +00:00
|
|
|
|
2000-03-14 23:06:59 +00:00
|
|
|
result = palloc(sizeof(*result));
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
*result = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* timestamp_time() */
|
1997-09-07 05:04:48 +00:00
|
|
|
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
/* datetime_timestamp()
|
|
|
|
* Convert date and time to timestamp data type.
|
1997-09-07 05:04:48 +00:00
|
|
|
*/
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
Timestamp *
|
|
|
|
datetime_timestamp(DateADT date, TimeADT *time)
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
Timestamp *result;
|
1997-09-07 05:04:48 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
if (!PointerIsValid(time))
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
2000-03-14 23:06:59 +00:00
|
|
|
result = palloc(sizeof(*result));
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
TIMESTAMP_INVALID(*result);
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
else
|
1997-09-07 05:04:48 +00:00
|
|
|
{
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
result = date_timestamp(date);
|
|
|
|
*result += *time;
|
1997-09-07 05:04:48 +00:00
|
|
|
}
|
1996-07-09 06:22:35 +00:00
|
|
|
|
All regression tests pass except for rules.sql (unrelated).
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
2000-02-16 18:17:02 +00:00
|
|
|
return result;
|
|
|
|
} /* datetime_timestamp() */
|
2000-03-14 23:06:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* time_interval()
|
|
|
|
* Convert time to interval data type.
|
|
|
|
*/
|
|
|
|
Interval *
|
|
|
|
time_interval(TimeADT *time)
|
|
|
|
{
|
|
|
|
Interval *result;
|
|
|
|
|
|
|
|
if (!PointerIsValid(time))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = palloc(sizeof(*result));
|
|
|
|
result->time = *time;
|
|
|
|
result->month = 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* time_interval() */
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Time With Time Zone ADT
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
TimeTzADT *
|
|
|
|
timetz_in(char *str)
|
|
|
|
{
|
|
|
|
TimeTzADT *time;
|
|
|
|
|
|
|
|
double fsec;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
|
|
|
|
|
|
|
int nf;
|
|
|
|
char lowstr[MAXDATELEN + 1];
|
|
|
|
char *field[MAXDATEFIELDS];
|
|
|
|
int dtype;
|
|
|
|
int ftype[MAXDATEFIELDS];
|
|
|
|
|
|
|
|
if (!PointerIsValid(str))
|
|
|
|
elog(ERROR, "Bad (null) time external representation");
|
|
|
|
|
|
|
|
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|
|
|
|
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz) != 0))
|
|
|
|
elog(ERROR, "Bad time external representation '%s'", str);
|
|
|
|
|
|
|
|
time = palloc(sizeof(*time));
|
|
|
|
|
|
|
|
time->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
|
|
|
|
time->zone = tz;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
} /* timetz_in() */
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
timetz_out(TimeTzADT *time)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
|
|
|
|
double fsec;
|
|
|
|
int tz;
|
|
|
|
char buf[MAXDATELEN + 1];
|
|
|
|
|
|
|
|
if (!PointerIsValid(time))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tm->tm_hour = (time->time / (60 * 60));
|
|
|
|
tm->tm_min = (((int) (time->time / 60)) % 60);
|
|
|
|
tm->tm_sec = (((int) time->time) % 60);
|
|
|
|
|
|
|
|
fsec = 0;
|
|
|
|
tz = time->zone;
|
|
|
|
|
|
|
|
EncodeTimeOnly(tm, fsec, &tz, DateStyle, buf);
|
|
|
|
|
|
|
|
result = palloc(strlen(buf) + 1);
|
|
|
|
|
|
|
|
strcpy(result, buf);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* timetz_out() */
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_eq(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) == (time2->time + time2->zone));
|
|
|
|
} /* timetz_eq() */
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_ne(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) != (time2->time + time2->zone));
|
|
|
|
} /* timetz_ne() */
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_lt(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) < (time2->time + time2->zone));
|
|
|
|
} /* timetz_lt() */
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_le(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) <= (time2->time + time2->zone));
|
|
|
|
} /* timetz_le() */
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_gt(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) > (time2->time + time2->zone));
|
|
|
|
} /* timetz_gt() */
|
|
|
|
|
|
|
|
bool
|
|
|
|
timetz_ge(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
if (!PointerIsValid(time1) || !PointerIsValid(time2))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return ((time1->time + time1->zone) >= (time2->time + time2->zone));
|
|
|
|
} /* timetz_ge() */
|
|
|
|
|
|
|
|
int
|
|
|
|
timetz_cmp(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
return (timetz_lt(time1, time2) ? -1 : (timetz_gt(time1, time2)? 1: 0));
|
|
|
|
} /* timetz_cmp() */
|
|
|
|
|
|
|
|
TimeTzADT *
|
|
|
|
timetz_larger(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
return timetz_gt(time1, time2)? time1: time2;
|
|
|
|
} /* timetz_larger() */
|
|
|
|
|
|
|
|
TimeTzADT *
|
|
|
|
timetz_smaller(TimeTzADT *time1, TimeTzADT *time2)
|
|
|
|
{
|
|
|
|
return timetz_lt(time1, time2)? time1: time2;
|
|
|
|
} /* timetz_smaller() */
|
|
|
|
|
|
|
|
/* overlaps_timetz()
|
|
|
|
* Implements the SQL92 OVERLAPS operator.
|
|
|
|
* Algorithm from Date and Darwen, 1997
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
overlaps_timetz(TimeTzADT *ts1, TimeTzADT *te1, TimeTzADT *ts2, TimeTzADT *te2)
|
|
|
|
{
|
|
|
|
/* Make sure we have ordered pairs... */
|
|
|
|
if (timetz_gt(ts1, te1))
|
|
|
|
{
|
|
|
|
TimeTzADT *tt = ts1;
|
|
|
|
ts1 = te1;
|
|
|
|
te1 = tt;
|
|
|
|
}
|
|
|
|
if (timetz_gt(ts2, te2))
|
|
|
|
{
|
|
|
|
TimeTzADT *tt = ts2;
|
|
|
|
ts2 = te2;
|
|
|
|
te2 = tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((timetz_gt(ts1, ts2) && (timetz_lt(ts1, te2) || timetz_lt(te1, te2)))
|
|
|
|
|| (timetz_gt(ts2, ts1) && (timetz_lt(ts2, te1) || timetz_lt(te2, te1)))
|
|
|
|
|| timetz_eq(ts1, ts2));
|
|
|
|
} /* overlaps_timetz() */
|
|
|
|
|
|
|
|
/* timestamp_timetz()
|
|
|
|
* Convert timestamp to timetz data type.
|
|
|
|
*/
|
|
|
|
TimeTzADT *
|
|
|
|
timestamp_timetz(Timestamp *timestamp)
|
|
|
|
{
|
|
|
|
TimeTzADT *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
|
|
|
double fsec;
|
|
|
|
char *tzn;
|
|
|
|
|
|
|
|
if (!PointerIsValid(timestamp))
|
|
|
|
elog(ERROR, "Unable to convert null timestamp to date");
|
|
|
|
|
|
|
|
if (TIMESTAMP_NOT_FINITE(*timestamp))
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
|
|
|
|
|
|
|
if (TIMESTAMP_IS_EPOCH(*timestamp))
|
|
|
|
{
|
|
|
|
timestamp2tm(SetTimestamp(*timestamp), NULL, tm, &fsec, NULL);
|
|
|
|
tz = 0;
|
|
|
|
}
|
|
|
|
else if (TIMESTAMP_IS_CURRENT(*timestamp))
|
|
|
|
{
|
|
|
|
timestamp2tm(SetTimestamp(*timestamp), &tz, tm, &fsec, &tzn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (timestamp2tm(*timestamp, &tz, tm, &fsec, &tzn) != 0)
|
|
|
|
elog(ERROR, "Unable to convert timestamp to date");
|
|
|
|
}
|
|
|
|
|
|
|
|
result = palloc(sizeof(*result));
|
|
|
|
|
|
|
|
result->time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);
|
|
|
|
result->zone = tz;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* timestamp_timetz() */
|
|
|
|
|
|
|
|
|
|
|
|
/* datetimetz_timestamp()
|
|
|
|
* Convert date and timetz to timestamp data type.
|
|
|
|
* Timestamp is stored in GMT, so add the time zone
|
|
|
|
* stored with the timetz to the result.
|
|
|
|
* - thomas 2000-03-10
|
|
|
|
*/
|
|
|
|
Timestamp *
|
|
|
|
datetimetz_timestamp(DateADT date, TimeTzADT *time)
|
|
|
|
{
|
|
|
|
Timestamp *result;
|
|
|
|
struct tm tt,
|
|
|
|
*tm = &tt;
|
|
|
|
int tz;
|
|
|
|
double fsec = 0;
|
|
|
|
char *tzn;
|
|
|
|
|
|
|
|
result = palloc(sizeof(*result));
|
|
|
|
|
|
|
|
if (!PointerIsValid(date) || !PointerIsValid(time))
|
|
|
|
{
|
|
|
|
TIMESTAMP_INVALID(*result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (date2tm(date, &tz, tm, &fsec, &tzn) != 0)
|
|
|
|
elog(ERROR, "Unable to convert date to timestamp");
|
|
|
|
|
|
|
|
if (tm2timestamp(tm, fsec, &time->zone, result) != 0)
|
|
|
|
elog(ERROR, "Timestamp out of range");
|
|
|
|
|
|
|
|
*result += time->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} /* datetimetz_timestamp() */
|
|
|
|
|
|
|
|
|