Remove internal uses of CTimeZone/HasCTZSet.

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.
This commit is contained in:
Tom Lane 2013-11-01 12:51:27 -04:00
parent 631dc390f4
commit 1c8a7f617f
3 changed files with 9 additions and 60 deletions

View 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);
@ -125,21 +117,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
tm->tm_zone = tx->tm_zone;
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 */
@ -162,7 +139,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
tm->tm_zone)));
}
}
}
else
tm->tm_isdst = -1;
}

View 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;

View File

@ -2960,8 +2960,8 @@ SELECT '2012-12-12 12:00 America/New_York'::timestamptz;
SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD HH:MI:SS TZ');
to_char
----------------------
2012-12-12 12:00:00
----------------------------
2012-12-12 12:00:00 -01:30
(1 row)
RESET TIME ZONE;