Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2c8ef93

Browse files
committed
Future-proof regression tests against possibly-missing posixrules file.
The IANA time zone folk have deprecated use of a "posixrules" file in the tz database. While for now it's our choice whether to keep supplying one in our own builds, installations built with --with-system-tzdata will soon be needing to cope with that file not being present, at least on some platforms. This causes a problem for the horology test, which expected the nonstandard POSIX zone spec "CST7CDT" to apply pre-2007 US daylight savings rules. That does happen if the posixrules file supplies such information, but otherwise the test produces undesired results. To fix, add an explicit transition date rule that matches 2005 practice. (We could alternatively have switched the test to use some real time zone, but it seems useful to have coverage of this type of zone spec.) While at it, update a documentation example that also relied on "CST7CDT"; use a real-world zone name instead. Also, document why the zone names EST5EDT, CST6CDT, MST7MDT, PST8PDT aren't subject to similar failures when "posixrules" is missing. Back-patch to all supported branches, since the hazard is the same for all. Discussion: https://postgr.es/m/1665379.1592581287@sss.pgh.pa.us
1 parent 816cbb5 commit 2c8ef93

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

doc/src/sgml/datetime.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,18 @@
757757
CET and ends on the last Sunday in October at 3AM CEST.
758758
</para>
759759

760+
<para>
761+
The four timezone names <literal>EST5EDT</literal>,
762+
<literal>CST6CDT</literal>, <literal>MST7MDT</literal>,
763+
and <literal>PST8PDT</literal> look like they are POSIX zone
764+
specifications. However, they actually are treated as named time zones
765+
because (for historical reasons) there are files by those names in the
766+
IANA time zone database. The practical implication of this is that
767+
these zone names will produce valid historical USA daylight-savings
768+
transitions, even when a plain POSIX specification would not due to
769+
lack of a suitable <filename>posixrules</filename> file.
770+
</para>
771+
760772
<para>
761773
One should be wary that it is easy to misspell a POSIX-style time zone
762774
specification, since there is no check on the reasonableness of the

doc/src/sgml/func.sgml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9131,18 +9131,22 @@ SELECT (DATE '2001-10-30', DATE '2001-10-30') OVERLAPS
91319131
When adding an <type>interval</type> value to (or subtracting an
91329132
<type>interval</type> value from) a <type>timestamp with time zone</type>
91339133
value, the days component advances or decrements the date of the
9134-
<type>timestamp with time zone</type> by the indicated number of days.
9134+
<type>timestamp with time zone</type> by the indicated number of days,
9135+
keeping the time of day the same.
91359136
Across daylight saving time changes (when the session time zone is set to a
91369137
time zone that recognizes DST), this means <literal>interval '1 day'</literal>
91379138
does not necessarily equal <literal>interval '24 hours'</literal>.
9138-
For example, with the session time zone set to <literal>CST7CDT</literal>,
9139-
<literal>timestamp with time zone '2005-04-02 12:00-07' + interval '1 day'</literal>
9140-
will produce <literal>timestamp with time zone '2005-04-03 12:00-06'</literal>,
9141-
while adding <literal>interval '24 hours'</literal> to the same initial
9142-
<type>timestamp with time zone</type> produces
9143-
<literal>timestamp with time zone '2005-04-03 13:00-06'</literal>, as there is
9144-
a change in daylight saving time at <literal>2005-04-03 02:00</literal> in time zone
9145-
<literal>CST7CDT</literal>.
9139+
For example, with the session time zone set
9140+
to <literal>America/Denver</literal>:
9141+
<screen>
9142+
SELECT timestamp with time zone '2005-04-02 12:00:00-07' + interval '1 day';
9143+
<lineannotation>Result: </lineannotation><computeroutput>2005-04-03 12:00:00-06</computeroutput>
9144+
SELECT timestamp with time zone '2005-04-02 12:00:00-07' + interval '24 hours';
9145+
<lineannotation>Result: </lineannotation><computeroutput>2005-04-03 13:00:00-06</computeroutput>
9146+
</screen>
9147+
This happens because an hour was skipped due to a change in daylight saving
9148+
time at <literal>2005-04-03 02:00:00</literal> in time zone
9149+
<literal>America/Denver</literal>.
91469150
</para>
91479151

91489152
<para>

src/test/regress/expected/horology.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ SELECT (timestamp with time zone 'tomorrow' > 'now') as "True";
652652
(1 row)
653653

654654
-- timestamp with time zone, interval arithmetic around DST change
655-
SET TIME ZONE 'CST7CDT';
655+
-- (just for fun, let's use an intentionally nonstandard POSIX zone spec)
656+
SET TIME ZONE 'CST7CDT,M4.1.0,M10.5.0';
656657
SELECT timestamp with time zone '2005-04-02 12:00-07' + interval '1 day' as "Apr 3, 12:00";
657658
Apr 3, 12:00
658659
------------------------------

src/test/regress/sql/horology.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ SELECT (timestamp with time zone 'tomorrow' = (timestamp with time zone 'yesterd
122122
SELECT (timestamp with time zone 'tomorrow' > 'now') as "True";
123123

124124
-- timestamp with time zone, interval arithmetic around DST change
125-
SET TIME ZONE 'CST7CDT';
125+
-- (just for fun, let's use an intentionally nonstandard POSIX zone spec)
126+
SET TIME ZONE 'CST7CDT,M4.1.0,M10.5.0';
126127
SELECT timestamp with time zone '2005-04-02 12:00-07' + interval '1 day' as "Apr 3, 12:00";
127128
SELECT timestamp with time zone '2005-04-02 12:00-07' + interval '24 hours' as "Apr 3, 13:00";
128129
SELECT timestamp with time zone '2005-04-03 12:00-06' - interval '1 day' as "Apr 2, 12:00";

0 commit comments

Comments
 (0)