]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix DecodeDateTime to allow timezone to appear before year. This had
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Jun 2007 15:58:39 +0000 (15:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Jun 2007 15:58:39 +0000 (15:58 +0000)
historically worked in some but not all cases, but as of 8.2 it failed for all
timezone formats.  Fix, and add regression test cases to catch future
regressions in this area.  Per gripe from Adam Witney.

src/backend/utils/adt/datetime.c
src/test/regress/expected/timestamptz.out
src/test/regress/sql/timestamptz.sql

index 5a1613ef7d0c88ef41a4032831a266a809fb3658..c9ec9aff19d16386de052386f70ffeccc8218952 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.174.2.1 2007/05/29 04:59:13 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.174.2.2 2007/06/12 15:58:39 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -719,11 +719,17 @@ DecodeDateTime(char **field, int *ftype, int nf,
                                }
                                /***
                                 * Already have a date? Then this might be a time zone name
-                                * with embedded punctuation (e.g. "America/New_York") or
-                                * run-together time with trailing time zone (e.g. hhmmss-zz).
+                                * with embedded punctuation (e.g. "America/New_York") or a
+                                * run-together time with trailing time zone (e.g. hhmmss-zz).
                                 * - thomas 2001-12-25
+                                *
+                                * We consider it a time zone if we already have month & day.
+                                * This is to allow the form "mmm dd hhmmss tz year", which
+                                * we've historically accepted.
                                 ***/
-                               else if ((fmask & DTK_DATE_M) == DTK_DATE_M || ptype != 0)
+                               else if (ptype != 0 ||
+                                                ((fmask & (DTK_M(MONTH) | DTK_M(DAY))) ==
+                                                 (DTK_M(MONTH) | DTK_M(DAY))))
                                {
                                        /* No time zone accepted? Then quit... */
                                        if (tzp == NULL)
index be3d7bed5d1edc949765eb0c95ab5676eb6f9f2d..c2732e310d478cdf1329a1fe965e8c293317e951 100644 (file)
@@ -153,6 +153,38 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097');
 ERROR:  time zone displacement out of range: "Feb 16 17:32:01 -0097"
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC');
 ERROR:  timestamp out of range: "Feb 16 17:32:01 5097 BC"
+-- Alternate field order that we've historically supported (sort of)
+-- with regular and POSIXy timezone specs
+SELECT 'Wed Jul 11 10:51:14 America/New_York 2001'::timestamptz;
+         timestamptz          
+------------------------------
+ Wed Jul 11 07:51:14 2001 PDT
+(1 row)
+
+SELECT 'Wed Jul 11 10:51:14 GMT-4 2001'::timestamptz;
+         timestamptz          
+------------------------------
+ Tue Jul 10 23:51:14 2001 PDT
+(1 row)
+
+SELECT 'Wed Jul 11 10:51:14 GMT+4 2001'::timestamptz;
+         timestamptz          
+------------------------------
+ Wed Jul 11 07:51:14 2001 PDT
+(1 row)
+
+SELECT 'Wed Jul 11 10:51:14 PST-03:00 2001'::timestamptz;
+         timestamptz          
+------------------------------
+ Wed Jul 11 00:51:14 2001 PDT
+(1 row)
+
+SELECT 'Wed Jul 11 10:51:14 PST+03:00 2001'::timestamptz;
+         timestamptz          
+------------------------------
+ Wed Jul 11 06:51:14 2001 PDT
+(1 row)
+
 SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL; 
  64 |               d1                
 ----+---------------------------------
index fc597a6b2cf477da44d86c11282dd7833e378937..af6752addbc7215c38a1e9caad4b66962274d773 100644 (file)
@@ -127,6 +127,14 @@ INSERT INTO TIMESTAMPTZ_TBL VALUES ('Jan 01 17:32:01 2001');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 -0097');
 INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 16 17:32:01 5097 BC');
 
+-- Alternate field order that we've historically supported (sort of)
+-- with regular and POSIXy timezone specs
+SELECT 'Wed Jul 11 10:51:14 America/New_York 2001'::timestamptz;
+SELECT 'Wed Jul 11 10:51:14 GMT-4 2001'::timestamptz;
+SELECT 'Wed Jul 11 10:51:14 GMT+4 2001'::timestamptz;
+SELECT 'Wed Jul 11 10:51:14 PST-03:00 2001'::timestamptz;
+SELECT 'Wed Jul 11 10:51:14 PST+03:00 2001'::timestamptz;
+
 SELECT '' AS "64", d1 FROM TIMESTAMPTZ_TBL; 
 
 -- Demonstrate functions and operators