mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
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:
@ -100,15 +100,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
|
|||||||
pg_time_t time = (pg_time_t) _time;
|
pg_time_t time = (pg_time_t) _time;
|
||||||
struct pg_tm *tx;
|
struct pg_tm *tx;
|
||||||
|
|
||||||
/*
|
if (tzp != NULL)
|
||||||
* 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)
|
|
||||||
tx = pg_localtime(&time, session_timezone);
|
tx = pg_localtime(&time, session_timezone);
|
||||||
else
|
else
|
||||||
tx = pg_gmtime(&time);
|
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;
|
tm->tm_zone = tx->tm_zone;
|
||||||
|
|
||||||
if (tzp != NULL)
|
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 */
|
*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)));
|
tm->tm_zone)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
tm->tm_isdst = -1;
|
tm->tm_isdst = -1;
|
||||||
}
|
}
|
||||||
|
@ -1498,8 +1498,7 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
|
|||||||
* 0 on success
|
* 0 on success
|
||||||
* -1 on out of range
|
* -1 on out of range
|
||||||
*
|
*
|
||||||
* If attimezone is NULL, the global timezone (including possibly brute forced
|
* If attimezone is NULL, the global timezone setting will be used.
|
||||||
* timezone) will be used.
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char **tzn, pg_tz *attimezone)
|
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;
|
Timestamp time;
|
||||||
pg_time_t utime;
|
pg_time_t utime;
|
||||||
|
|
||||||
/*
|
/* Use session timezone if caller asks for default */
|
||||||
* If HasCTZSet is true then we have a brute force time zone specified. Go
|
if (attimezone == NULL)
|
||||||
* ahead and rotate to the local time zone since we will later bypass any
|
attimezone = session_timezone;
|
||||||
* 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
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
time = dt;
|
time = dt;
|
||||||
@ -1589,21 +1578,6 @@ recalc_t:
|
|||||||
return 0;
|
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
|
* If the time falls within the range of pg_time_t, use pg_localtime() to
|
||||||
* rotate to the local time zone.
|
* rotate to the local time zone.
|
||||||
@ -1624,8 +1598,7 @@ recalc_t:
|
|||||||
utime = (pg_time_t) dt;
|
utime = (pg_time_t) dt;
|
||||||
if ((Timestamp) utime == dt)
|
if ((Timestamp) utime == dt)
|
||||||
{
|
{
|
||||||
struct pg_tm *tx = pg_localtime(&utime,
|
struct pg_tm *tx = pg_localtime(&utime, attimezone);
|
||||||
attimezone ? attimezone : session_timezone);
|
|
||||||
|
|
||||||
tm->tm_year = tx->tm_year + 1900;
|
tm->tm_year = tx->tm_year + 1900;
|
||||||
tm->tm_mon = tx->tm_mon + 1;
|
tm->tm_mon = tx->tm_mon + 1;
|
||||||
|
@ -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');
|
SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD HH:MI:SS TZ');
|
||||||
to_char
|
to_char
|
||||||
----------------------
|
----------------------------
|
||||||
2012-12-12 12:00:00
|
2012-12-12 12:00:00 -01:30
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
RESET TIME ZONE;
|
RESET TIME ZONE;
|
||||||
|
Reference in New Issue
Block a user