Commit b5e23db4 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Rework the date/time parsing to tighten up some cases and to enable other

 cases which should have worked but did not.
Now supports julian day (J2452271), ISO time labels (T040506) and various
 combinations of spaces and run-togethers of dates, times, and time zones.
All regression tests pass, and I have more tests to add after the 7.2
 release (don't want to require changes to the ancillary horology result
 files until after then).
parent 3e87bfc1
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.60 2001/11/21 18:29:48 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.61 2001/12/29 18:31:31 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2461,6 +2461,11 @@ timestamp_part(PG_FUNCTION_ARGS) ...@@ -2461,6 +2461,11 @@ timestamp_part(PG_FUNCTION_ARGS)
result = (tm->tm_year / 1000); result = (tm->tm_year / 1000);
break; break;
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec) / 86400e0);
break;
case DTK_TZ: case DTK_TZ:
case DTK_TZ_MINUTE: case DTK_TZ_MINUTE:
case DTK_TZ_HOUR: case DTK_TZ_HOUR:
...@@ -2549,7 +2554,8 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -2549,7 +2554,8 @@ timestamptz_part(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(result); PG_RETURN_FLOAT8(result);
} }
if ((type == UNITS) && (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0)) if ((type == UNITS)
&& (timestamp2tm(timestamp, &tz, tm, &fsec, &tzn) == 0))
{ {
switch (val) switch (val)
{ {
...@@ -2619,6 +2625,11 @@ timestamptz_part(PG_FUNCTION_ARGS) ...@@ -2619,6 +2625,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
result = (tm->tm_year / 1000); result = (tm->tm_year / 1000);
break; break;
case DTK_JULIAN:
result = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday);
result += (((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec) / 86400e0);
break;
default: default:
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits); elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits);
result = 0; result = 0;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: datetime.h,v 1.26 2001/11/05 17:46:36 momjian Exp $ * $Id: datetime.h,v 1.27 2001/12/29 18:31:48 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -108,6 +108,9 @@ ...@@ -108,6 +108,9 @@
#define AGO 17 #define AGO 17
#define ABS_BEFORE 18 #define ABS_BEFORE 18
#define ABS_AFTER 19 #define ABS_AFTER 19
/* generic fields to help with parsing */
#define DATE 20
#define TIME 21
/* reserved for unrecognized string values */ /* reserved for unrecognized string values */
#define UNKNOWN_FIELD 31 #define UNKNOWN_FIELD 31
...@@ -163,9 +166,6 @@ ...@@ -163,9 +166,6 @@
#define DTK_TZ_HOUR 34 #define DTK_TZ_HOUR 34
#define DTK_TZ_MINUTE 35 #define DTK_TZ_MINUTE 35
#define DTK_ISO_DATE 36
#define DTK_ISO_TIME 37
/* /*
* Bit mask definitions for time parsing. * Bit mask definitions for time parsing.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment