Skip to content

Commit 1c8a7f6

Browse files
committed
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.
1 parent 631dc39 commit 1c8a7f6

File tree

3 files changed

+9
-60
lines changed

3 files changed

+9
-60
lines changed

src/backend/utils/adt/nabstime.c

+1-25
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,7 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
100100
pg_time_t time = (pg_time_t) _time;
101101
struct pg_tm *tx;
102102

103-
/*
104-
* If HasCTZSet is true then we have a brute force time zone specified. Go
105-
* ahead and rotate to the local time zone since we will later bypass any
106-
* calls which adjust the tm fields.
107-
*/
108-
if (HasCTZSet && (tzp != NULL))
109-
time -= CTimeZone;
110-
111-
if (!HasCTZSet && tzp != NULL)
103+
if (tzp != NULL)
112104
tx = pg_localtime(&time, session_timezone);
113105
else
114106
tx = pg_gmtime(&time);
@@ -126,21 +118,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
126118

127119
if (tzp != NULL)
128120
{
129-
/*
130-
* We have a brute force time zone per SQL99? Then use it without
131-
* change since we have already rotated to the time zone.
132-
*/
133-
if (HasCTZSet)
134-
{
135-
*tzp = CTimeZone;
136-
tm->tm_gmtoff = CTimeZone;
137-
tm->tm_isdst = 0;
138-
tm->tm_zone = NULL;
139-
if (tzn != NULL)
140-
*tzn = NULL;
141-
}
142-
else
143-
{
144121
*tzp = -tm->tm_gmtoff; /* tm_gmtoff is Sun/DEC-ism */
145122

146123
/*
@@ -161,7 +138,6 @@ abstime2tm(AbsoluteTime _time, int *tzp, struct pg_tm * tm, char **tzn)
161138
errmsg("invalid time zone name: \"%s\"",
162139
tm->tm_zone)));
163140
}
164-
}
165141
}
166142
else
167143
tm->tm_isdst = -1;

src/backend/utils/adt/timestamp.c

+5-32
Original file line numberDiff line numberDiff line change
@@ -1498,8 +1498,7 @@ dt2time(Timestamp jd, int *hour, int *min, int *sec, fsec_t *fsec)
14981498
* 0 on success
14991499
* -1 on out of range
15001500
*
1501-
* If attimezone is NULL, the global timezone (including possibly brute forced
1502-
* timezone) will be used.
1501+
* If attimezone is NULL, the global timezone setting will be used.
15031502
*/
15041503
int
15051504
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
15081507
Timestamp time;
15091508
pg_time_t utime;
15101509

1511-
/*
1512-
* If HasCTZSet is true then we have a brute force time zone specified. Go
1513-
* ahead and rotate to the local time zone since we will later bypass any
1514-
* calls which adjust the tm fields.
1515-
*/
1516-
if (attimezone == NULL && HasCTZSet && tzp != NULL)
1517-
{
1518-
#ifdef HAVE_INT64_TIMESTAMP
1519-
dt -= CTimeZone * USECS_PER_SEC;
1520-
#else
1521-
dt -= CTimeZone;
1522-
#endif
1523-
}
1510+
/* Use session timezone if caller asks for default */
1511+
if (attimezone == NULL)
1512+
attimezone = session_timezone;
15241513

15251514
#ifdef HAVE_INT64_TIMESTAMP
15261515
time = dt;
@@ -1589,21 +1578,6 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
15891578
return 0;
15901579
}
15911580

1592-
/*
1593-
* We have a brute force time zone per SQL99? Then use it without change
1594-
* since we have already rotated to the time zone.
1595-
*/
1596-
if (attimezone == NULL && HasCTZSet)
1597-
{
1598-
*tzp = CTimeZone;
1599-
tm->tm_isdst = 0;
1600-
tm->tm_gmtoff = CTimeZone;
1601-
tm->tm_zone = NULL;
1602-
if (tzn != NULL)
1603-
*tzn = NULL;
1604-
return 0;
1605-
}
1606-
16071581
/*
16081582
* If the time falls within the range of pg_time_t, use pg_localtime() to
16091583
* rotate to the local time zone.
@@ -1624,8 +1598,7 @@ timestamp2tm(Timestamp dt, int *tzp, struct pg_tm * tm, fsec_t *fsec, const char
16241598
utime = (pg_time_t) dt;
16251599
if ((Timestamp) utime == dt)
16261600
{
1627-
struct pg_tm *tx = pg_localtime(&utime,
1628-
attimezone ? attimezone : session_timezone);
1601+
struct pg_tm *tx = pg_localtime(&utime, attimezone);
16291602

16301603
tm->tm_year = tx->tm_year + 1900;
16311604
tm->tm_mon = tx->tm_mon + 1;

src/test/regress/expected/horology.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -2959,9 +2959,9 @@ SELECT '2012-12-12 12:00 America/New_York'::timestamptz;
29592959
(1 row)
29602960

29612961
SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD HH:MI:SS TZ');
2962-
to_char
2963-
----------------------
2964-
2012-12-12 12:00:00
2962+
to_char
2963+
----------------------------
2964+
2012-12-12 12:00:00 -01:30
29652965
(1 row)
29662966

29672967
RESET TIME ZONE;

0 commit comments

Comments
 (0)