Remove internal uses of CTimeZone/HasCTZSet.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Nov 2013 16:51:27 +0000 (12:51 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 Nov 2013 16:51:27 +0000 (12:51 -0400)
The only remaining places where we actually look at CTimeZone/HasCTZSet
are abstime2tm() and timestamp2tm().  Now that session_timezone is always
valid, we can remove these special cases.  The caller-visible impact of
this is that these functions now always return a valid zone abbreviation
if requested, whereas before they'd return a NULL pointer if a brute-force
timezone was in use.  In the existing code, the only place I can find that
changes behavior is to_char(), whose TZ format code will now print
something useful rather than nothing for such zones.  (In the places where
the returned zone abbreviation is passed to EncodeDateTime, the lack of
visible change is because we've chosen the abbreviation used for these
zones to match what EncodeTimezone would have printed.)

It's likely that there is now a fair amount of removable dead code around
the call sites, namely anything that's meant to cope with getting a NULL
timezone abbreviation, but I've not made an effort to root that out.

This could be back-patched if we decide we'd like to fix to_char()'s
behavior in the back branches, but there doesn't seem to be much
enthusiasm for that at present.

src/backend/utils/adt/nabstime.c
src/backend/utils/adt/timestamp.c
src/test/regress/expected/horology.out

index 32f1726402ecb1040ea433f159f84691fdacc121..919e6dc99f212bb0fc8396d18e04c3d490a6e1b2 100644 (file)
@@ -100,15 +100,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
    pg_time_t   time = (pg_time_t) _time;
    struct pg_tm *tx;
 
-   /*
-    * If HasCTZSet is true then we have a brute force time zone specified. Go
-    * ahead and rotate to the local time zone since we will later bypass any
-    * calls which adjust the tm fields.
-    */
-   if (HasCTZSet && (tzp != NULL))
-       time -= CTimeZone;
-
-   if (!HasCTZSet && tzp != NULL)
+   if (tzp != NULL)
        tx = pg_localtime(&time, session_timezone);
    else
        tx = pg_gmtime(&time);
@@ -126,21 +118,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
 
    if (tzp != NULL)
    {
-       /*
-        * We have a brute force time zone per SQL99? Then use it without
-        * change since we have already rotated to the time zone.
-        */
-       if (HasCTZSet)
-       {
-           *tzp = CTimeZone;
-           tm->tm_gmtoff = CTimeZone;
-           tm->tm_isdst = 0;
-           tm->tm_zone = NULL;
-           if (tzn != NULL)
-               *tzn = NULL;
-       }
-       else
-       {
            *tzp = -tm->tm_gmtoff;      /* tm_gmtoff is Sun/DEC-ism */
 
            /*
@@ -161,7 +138,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
                             errmsg("invalid time zone name: \"%s\"",
                                    tm->tm_zone)));
            }
-       }
    }
    else
        tm->tm_isdst = -1;
index 94b2a3608a61d53990dffb8a361d7ae5e795370d..c3c71b72810dcccb8dc15c04c6e57b812dde3fc8 100644 (file)
@@ -1498,8 +1498,7 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
  *  0 on success
  * -1 on out of range
  *
- * If attimezone is NULL, the global timezone (including possibly brute forced
- * timezone) will be used.
+ * If attimezone is NULL, the global timezone setting will be used.
  */
 int
 timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
@@ -1508,19 +1507,9 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
    Timestamp   time;
    pg_time_t   utime;
 
-   /*
-    * If HasCTZSet is true then we have a brute force time zone specified. Go
-    * ahead and rotate to the local time zone since we will later bypass any
-    * calls which adjust the tm fields.
-    */
-   if (attimezone == NULL && HasCTZSet && tzp != NULL)
-   {
-#ifdef HAVE_INT64_TIMESTAMP
-       dt -= CTimeZone * USECS_PER_SEC;
-#else
-       dt -= CTimeZone;
-#endif
-   }
+   /* Use session timezone if caller asks for default */
+   if (attimezone == NULL)
+       attimezone = session_timezone;
 
 #ifdef HAVE_INT64_TIMESTAMP
    time = dt;
@@ -1589,21 +1578,6 @@ recalc_t:
        return 0;
    }
 
-   /*
-    * We have a brute force time zone per SQL99? Then use it without change
-    * since we have already rotated to the time zone.
-    */
-   if (attimezone == NULL && HasCTZSet)
-   {
-       *tzp = CTimeZone;
-       tm->tm_isdst = 0;
-       tm->tm_gmtoff = CTimeZone;
-       tm->tm_zone = NULL;
-       if (tzn != NULL)
-           *tzn = NULL;
-       return 0;
-   }
-
    /*
     * If the time falls within the range of pg_time_t, use pg_localtime() to
     * rotate to the local time zone.
@@ -1624,8 +1598,7 @@ recalc_t:
    utime = (pg_time_t) dt;
    if ((Timestamp) utime == dt)
    {
-       struct pg_tm *tx = pg_localtime(&utime,
-                                attimezone ? attimezone : session_timezone);
+       struct pg_tm *tx = pg_localtime(&utime, attimezone);
 
        tm->tm_year = tx->tm_year + 1900;
        tm->tm_mon = tx->tm_mon + 1;
index 2666deea88bd9838f48f2037378d31bc1b26f8fe..3ed9c8c1a095e939ef8cdd1c050fac307a96cdc5 100644 (file)
@@ -2959,9 +2959,9 @@ SELECT '2012-12-12 12:00 America/New_York'::timestamptz;
 (1 row)
 
 SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD HH:MI:SS TZ');
-       to_char        
-----------------------
- 2012-12-12 12:00:00 
+          to_char           
+----------------------------
+ 2012-12-12 12:00:00 -01:30
 (1 row)
 
 RESET TIME ZONE;