Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlm8P-000654-Pp for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 04:26:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlm7t-0001Jh-3x for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2020 04:26:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlm7s-0001Ja-L4 for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 04:26:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlm7q-0002oY-6B for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2020 04:26:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05I4Q4qM1525465 for ; Thu, 18 Jun 2020 00:26:04 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Re: More tzdb fun: POSIXRULES is being deprecated upstream In-reply-to: <1452646.1592417333@sss.pgh.pa.us> References: <1390.1562258309@sss.pgh.pa.us> <1452646.1592417333@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 17 Jun 2020 14:08:53 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1525413.1592454271.0@sss.pgh.pa.us> Date: Thu, 18 Jun 2020 00:26:04 -0400 Message-ID: <1525464.1592454364@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1525413.1592454271.1@sss.pgh.pa.us> I wrote: > The minimum thing that we have to do, I'd say, is to change the > documentation to explain what happens if there's no posixrules file. Here's a proposed patch to do that. To explain this, we more or less have to fully document the POSIX timezone string format (otherwise nobody's gonna understand what "M3.2.0,M11.1.0" means). That's something we've glossed over for many years, and I still feel like it's not something to explain in-line in section 8.5.3, so I shoved all the gory details into a new section in Appendix B. To be clear, nothing here is new behavior, it was just undocumented before. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="document-posix-tz-better.patch"; charset="us-ascii" Content-ID: <1525413.1592454271.2@sss.pgh.pa.us> Content-Description: document-posix-tz-better.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index 3df189ad85..ca61439501 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -2492,25 +2492,10 @@ TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02' In addition to the timezone names and abbreviations, PostgreSQL will accept POSIX-style tim= e zone - specifications of the form STDoffset or - STDoffsetDST, where - STD is a zone abbreviation, offset is a - numeric offset in hours west from UTC, and DST is an - optional daylight-savings zone abbreviation, assumed to stand for= one - hour ahead of the given offset. For example, if EST5EDT<= /literal> - were not already a recognized zone name, it would be accepted and= would - be functionally equivalent to United States East Coast time. In = this - syntax, a zone abbreviation can be a string of letters, or an - arbitrary string surrounded by angle brackets (<><= /literal>). - When a daylight-savings zone abbreviation is present, - it is assumed to be used - according to the same daylight-savings transition rules used in t= he - IANA time zone database's posixrules entry. - In a standard PostgreSQL installation, - posixrules is the same as US/Easter= n, so - that POSIX-style time zone specifications follow USA daylight-sav= ings - rules. If needed, you can adjust this behavior by replacing the - posixrules file. + specifications, as described in + . This option i= s not + normally preferable to using a named time zone, but it may be + necessary if no suitable IANA time zone entry is available. @@ -2537,19 +2522,6 @@ TIMESTAMP WITH TIME ZONE '2004-10-19 10:23:54+02' above, this is not necessarily the same as local civil time on that = date. = - - One should be wary that the POSIX-style time zone feature can - lead to silently accepting bogus input, since there is no check on t= he - reasonableness of the zone abbreviations. For example, SET - TIMEZONE TO FOOBAR0 will work, leaving the system effectiv= ely using - a rather peculiar abbreviation for UTC. - Another issue to keep in mind is that in POSIX time zone names, - positive offsets are used for locations west of= Greenwich. - Everywhere else, PostgreSQL follows the - ISO-8601 convention that positive timezone offsets are eas= t - of Greenwich. - - In all cases, timezone names and abbreviations are recognized case-insensitively. (This is a change from PostgreSQL<= /productname> diff --git a/doc/src/sgml/datetime.sgml b/doc/src/sgml/datetime.sgml index 7cce826e2d..fb210b377b 100644 --- a/doc/src/sgml/datetime.sgml +++ b/doc/src/sgml/datetime.sgml @@ -555,6 +555,210 @@ = = + + <acronym>POSIX</acronym> Time Zone Specifications + + + time zone + POSIX-style specification + + + + PostgreSQL can accept time zone specifications that + are written according to the POSIX standard's rules + for the TZ environment + variable. POSIX time zone specifications are + inadequate to deal with the complexity of real-world time zone history= , + but there are sometimes reasons to use them. + + + + A POSIX time zone specification has the form + +STD offset DST dstoffset , rule + + (For readability, we show spaces between the fields, but spaces should + not be used in practice.) The fields are: + + + + STD is the zone abbreviation to be used + for standard time. + + + + + offset is the zone's standard-time offse= t + from UTC. + + + + + DST is the zone abbreviation to be used + for daylight-savings time. If this field and the following ones ar= e + omitted, the zone uses a fixed UTC offset with no daylight-savings + rule. + + + + + dstoffset is the daylight-savings offset + from UTC. This field is typically omitted, since it defaults to on= e + hour less than the standard-time offset, + which is usually the right thing. + + + + + rule defines the rule for when daylight + savings is in effect, as described below. + + + + + + + In this syntax, a zone abbreviation can be a string of letters, or an + arbitrary string surrounded by angle brackets + (<>). Note that the zone abbreviations given + here are only used for output, and even then only in some timestamp + output formats. The zone abbreviations recognized in timestamp input + are determined as explained in . + + + + The offset fields specify the hours, and optionally minutes and second= s, + difference from UTC. They have the format + hh:mm:ss + optionally with a leading sign (+ + or -). A positive sign is considered to define + zones west of Greenwich. (Note that this is the + opposite of the ISO-8601 sign convention used elsewhere in + PostgreSQL.) + + + + The daylight-savings transition rule has th= e + format + +dstdate / dsttime , stddate / stdtim= e + + (As before, spaces should not be included in practice.) + The dstdate + and dsttime fields define when daylight-sav= ings + time starts, while stddate + and stdtime define when standard time + starts. (In some cases, notably in zones south of the equator, the + former might be later in the year than the latter.) The date fields + have one of these formats: + + + n + + + A plain integer denotes a day of the year, counting from zero to + 364, or to 365 in leap years. + + + + + Jn + + + In this form, n counts from 1 to 365, + and February 29 is not counted even if it is present. (Thus, a + transition occurring on February 29 could not be specified this wa= y.) + + + + + Mm.n.d + + + This form specifies a transition occurring on a particular day of + the week. d is the weekday number from + 0 to 6 (Sunday is 0). m identifies the + month, from 1 to 12. n specifies + the n'th occurrence of that weekday + within the month (1–4), or 5 meaning the last occurrence of + that weekday in the month (which could be the fourth or the fifth)= . + + + + + + + + + The M format is sufficient to describe many common + daylight-savings transition rules; for + example M3.2.0 means second Sunday in + March. But note that none of these variants can deal with + daylight-savings law changes, so in practice the historical data + stored for named time zones (in the IANA time zone database) is + necessary to interpret past time stamps correctly. + + + + + The time fields in a transition rule have the same format as the offse= t + fields described previously, except that they cannot contain signs. + They define the current local time at which the change to the other + time occurs. If omitted, they default to 02:00:00. + + + + If a daylight-savings abbreviation is given but the + transition rule field is omitted, + PostgreSQL attempts to determine the + transition times by consulting the posixrules fil= e + in the IANA time zone database. This file has the same format as a + full time zone entry, but only its transition times are used, not its + UTC offsets. Typically, this file has the same contents as the + US/Eastern file, so that POSIX-style time zone + specifications follow USA daylight-savings rules. If needed, you can + adjust this behavior by replacing the posixrules + file. + + + + If the posixrules file is not present, + the fallback behavior is to use the + rule M3.2.0,M11.1.0, which corresponds to USA + practice as of 2020 (that is, spring forward on the second Sunday of + March, fall back on the first Sunday of November, both transitions + occurring at 2AM prevailing time). + + + + + The facility to consult a posixrules file has + been deprecated by IANA, and it is likely to go away in the future. + One bug in this feature, which is unlikely to be fixed before it + disappears, is that it fails to apply DST rules to dates after 2038. + + + + + As an example, CET-1CEST,M3.5.0,M10.5.0/3 describes + current (as of 2020) timekeeping practice in Paris. This specificatio= n + says that standard time has the abbreviation CET an= d + is one hour ahead of UTC; daylight savings time has the + abbreviation CEST and is implicitly two hours ahead + of UTC; daylight savings time begins on the last Sunday in March at 2A= M + and ends on the last Sunday in October at 3AM. + + + + One should be wary that it is easy to misspell a POSIX-style time zone + specification, since there is no check on the reasonableness of the + zone abbreviation(s). For example, SET TIMEZONE TO + FOOBAR0 will work, leaving the system effectively using a + rather peculiar abbreviation for UTC. + + + + History of Units = ------- =_aaaaaaaaaa0--