mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
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).
This commit is contained in:
parent
3e87bfc1f1
commit
b5e23db438
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* 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)
|
||||
result = (tm->tm_year / 1000);
|
||||
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_MINUTE:
|
||||
case DTK_TZ_HOUR:
|
||||
@ -2549,7 +2554,8 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
||||
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)
|
||||
{
|
||||
@ -2619,6 +2625,11 @@ timestamptz_part(PG_FUNCTION_ARGS)
|
||||
result = (tm->tm_year / 1000);
|
||||
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:
|
||||
elog(ERROR, "TIMESTAMP WITH TIME ZONE units '%s' not supported", lowunits);
|
||||
result = 0;
|
||||
|
@ -9,7 +9,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* 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 @@
|
||||
#define AGO 17
|
||||
#define ABS_BEFORE 18
|
||||
#define ABS_AFTER 19
|
||||
/* generic fields to help with parsing */
|
||||
#define DATE 20
|
||||
#define TIME 21
|
||||
/* reserved for unrecognized string values */
|
||||
#define UNKNOWN_FIELD 31
|
||||
|
||||
@ -163,9 +166,6 @@
|
||||
#define DTK_TZ_HOUR 34
|
||||
#define DTK_TZ_MINUTE 35
|
||||
|
||||
#define DTK_ISO_DATE 36
|
||||
#define DTK_ISO_TIME 37
|
||||
|
||||
|
||||
/*
|
||||
* Bit mask definitions for time parsing.
|
||||
|
Loading…
Reference in New Issue
Block a user