Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bfrNb-0002PV-9v for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 16:31:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bfrNa-0003tB-LG for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Sep 2016 16:31:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bfrMD-0002KX-49 for pgsql-hackers@postgreSQL.org; Fri, 02 Sep 2016 16:30:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bfrMA-00012z-0F for pgsql-hackers@postgreSQL.org; Fri, 02 Sep 2016 16:30:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u82GUGwQ018038 for ; Fri, 2 Sep 2016 12:30:16 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Re: Tracking timezone abbreviation removals in the IANA tz database In-reply-to: <9104.1472824610@sss.pgh.pa.us> References: <6189.1472820913@sss.pgh.pa.us> <9104.1472824610@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 02 Sep 2016 09:56:50 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <18008.1472833776.0@sss.pgh.pa.us> Date: Fri, 02 Sep 2016 12:30:16 -0400 Message-ID: <18037.1472833816@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18008.1472833776.1@sss.pgh.pa.us> I wrote: > So the idea I'm toying with (again, haven't tried to code this) is to say > that *if* we can match the abbreviation to something in the referenced > zone then we'll use that, but otherwise we fall back to treating the > abbreviation as a macro for the zone name. This turned out to require only fairly localized code changes. So I now propose that we leave the tznames files as-is and apply the attached patch (plus documentation changes, which I've not done yet). Any objections? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="allow-timezone-abbrevs-not-matching-iana-data.patch"; charset="us-ascii" Content-ID: <18008.1472833776.2@sss.pgh.pa.us> Content-Description: allow-timezone-abbrevs-not-matching-iana-data.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datet= ime.c index 965c3b4..45ba7cd 100644 *** a/src/backend/utils/adt/datetime.c --- b/src/backend/utils/adt/datetime.c *************** static void AdjustFractDays(double frac, *** 56,63 **** int scale); static int DetermineTimeZoneOffsetInternal(struct pg_tm * tm, pg_tz *tzp, pg_time_t *tp); ! static int DetermineTimeZoneAbbrevOffsetInternal(pg_time_t t, const char = *abbr, ! pg_tz *tzp, int *isdst); static pg_tz *FetchDynamicTimeZone(TimeZoneAbbrevTable *tbl, const datetk= n *tp); =20=20 =20=20 --- 56,64 ---- int scale); static int DetermineTimeZoneOffsetInternal(struct pg_tm * tm, pg_tz *tzp, pg_time_t *tp); ! static bool DetermineTimeZoneAbbrevOffsetInternal(pg_time_t t, ! const char *abbr, pg_tz *tzp, ! int *offset, int *isdst); static pg_tz *FetchDynamicTimeZone(TimeZoneAbbrevTable *tbl, const datetk= n *tp); =20=20 =20=20 *************** overflow: *** 1689,1707 **** * This differs from the behavior of DetermineTimeZoneOffset() in that a * standard-time or daylight-time abbreviation forces use of the correspo= nding * GMT offset even when the zone was then in DS or standard time respecti= vely. */ int DetermineTimeZoneAbbrevOffset(struct pg_tm * tm, const char *abbr, pg_tz = *tzp) { pg_time_t t; =20=20 /* * Compute the UTC time we want to probe at. (In event of overflow, we'= ll * probe at the epoch, which is a bit random but probably doesn't matter= .) */ ! (void) DetermineTimeZoneOffsetInternal(tm, tzp, &t); =20=20 ! return DetermineTimeZoneAbbrevOffsetInternal(t, abbr, tzp, &tm->tm_isdst= ); } =20=20 =20=20 --- 1690,1729 ---- * This differs from the behavior of DetermineTimeZoneOffset() in that a * standard-time or daylight-time abbreviation forces use of the correspo= nding * GMT offset even when the zone was then in DS or standard time respecti= vely. + * (However, that happens only if we can match the given abbreviation to = some + * abbreviation that appears in the IANA timezone data. Otherwise, we fa= ll + * back to doing DetermineTimeZoneOffset().) */ int DetermineTimeZoneAbbrevOffset(struct pg_tm * tm, const char *abbr, pg_tz = *tzp) { pg_time_t t; + int zone_offset; + int abbr_offset; + int abbr_isdst; =20=20 /* * Compute the UTC time we want to probe at. (In event of overflow, we'= ll * probe at the epoch, which is a bit random but probably doesn't matter= .) */ ! zone_offset =3D DetermineTimeZoneOffsetInternal(tm, tzp, &t); =20=20 ! /* ! * Try to match the abbreviation to something in the zone definition. ! */ ! if (DetermineTimeZoneAbbrevOffsetInternal(t, abbr, tzp, ! &abbr_offset, &abbr_isdst)) ! { ! /* Success, so use the abbrev-specific answers. */ ! tm->tm_isdst =3D abbr_isdst; ! return abbr_offset; ! } !=20 ! /* ! * No match, so use the answers we already got from ! * DetermineTimeZoneOffsetInternal. ! */ ! return zone_offset; } =20=20 =20=20 *************** DetermineTimeZoneAbbrevOffsetTS(Timestam *** 1715,1733 **** pg_tz *tzp, int *isdst) { pg_time_t t =3D timestamptz_to_time_t(ts); =20=20 ! return DetermineTimeZoneAbbrevOffsetInternal(t, abbr, tzp, isdst); } =20=20 =20=20 /* DetermineTimeZoneAbbrevOffsetInternal() * * Workhorse for above two functions: work from a pg_time_t probe instant. ! * DST status is returned into *isdst. */ ! static int ! DetermineTimeZoneAbbrevOffsetInternal(pg_time_t t, const char *abbr, ! pg_tz *tzp, int *isdst) { char upabbr[TZ_STRLEN_MAX + 1]; unsigned char *p; --- 1737,1777 ---- pg_tz *tzp, int *isdst) { pg_time_t t =3D timestamptz_to_time_t(ts); + int zone_offset; + int abbr_offset; + int tz; + struct pg_tm tm; + fsec_t fsec; =20=20 ! /* ! * If the abbrev matches anything in the zone data, this is pretty easy. ! */ ! if (DetermineTimeZoneAbbrevOffsetInternal(t, abbr, tzp, ! &abbr_offset, isdst)) ! return abbr_offset; !=20 ! /* ! * Else, break down the timestamp so we can use DetermineTimeZoneOffset. ! */ ! if (timestamp2tm(ts, &tz, &tm, &fsec, NULL, tzp) !=3D 0) ! ereport(ERROR, ! (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), ! errmsg("timestamp out of range"))); !=20 ! zone_offset =3D DetermineTimeZoneOffset(&tm, tzp); ! *isdst =3D tm.tm_isdst; ! return zone_offset; } =20=20 =20=20 /* DetermineTimeZoneAbbrevOffsetInternal() * * Workhorse for above two functions: work from a pg_time_t probe instant. ! * On success, return GMT offset and DST status into *offset and *isdst. */ ! static bool ! DetermineTimeZoneAbbrevOffsetInternal(pg_time_t t, const char *abbr, pg_t= z *tzp, ! int *offset, int *isdst) { char upabbr[TZ_STRLEN_MAX + 1]; unsigned char *p; *************** DetermineTimeZoneAbbrevOffsetInternal(pg *** 1739,1756 **** *p =3D pg_toupper(*p); =20=20 /* Look up the abbrev's meaning at this time in this zone */ ! if (!pg_interpret_timezone_abbrev(upabbr, ! &t, ! &gmtoff, ! isdst, ! tzp)) ! ereport(ERROR, ! (errcode(ERRCODE_CONFIG_FILE_ERROR), ! errmsg("time zone abbreviation \"%s\" is not used in time zone \"%s\= "", ! abbr, pg_get_timezone_name(tzp)))); !=20 ! /* Change sign to agree with DetermineTimeZoneOffset() */ ! return (int) -gmtoff; } =20=20 =20=20 --- 1783,1799 ---- *p =3D pg_toupper(*p); =20=20 /* Look up the abbrev's meaning at this time in this zone */ ! if (pg_interpret_timezone_abbrev(upabbr, ! &t, ! &gmtoff, ! isdst, ! tzp)) ! { ! /* Change sign to agree with DetermineTimeZoneOffset() */ ! *offset =3D (int) -gmtoff; ! return true; ! } ! return false; } =20=20 =20=20 diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/e= xpected/timestamptz.out index 67f26db..2bfc13a 100644 *** a/src/test/regress/expected/timestamptz.out --- b/src/test/regress/expected/timestamptz.out *************** SELECT '2007-12-09 07:30:00 UTC'::timest *** 2603,2605 **** --- 2603,2625 ---- Sun Dec 09 03:00:00 2007 (1 row) =20=20 + -- + -- Test that the pg_timezone_names and pg_timezone_abbrevs views are + -- more-or-less working. We can't test their contents in any great detail + -- without the outputs changing anytime IANA updates the underlying data, + -- but it seems reasonable to expect at least one entry per major meridia= n. + -- (At the time of writing, the actual counts are around 38 because of + -- zones using fractional GMT offsets, so this is a pretty loose test.) + -- + select count(distinct utc_offset) >=3D 24 as ok from pg_timezone_names; + ok=20 + ---- + t + (1 row) +=20 + select count(distinct utc_offset) >=3D 24 as ok from pg_timezone_abbrevs; + ok=20 + ---- + t + (1 row) +=20 diff --git a/src/test/regress/sql/timestamptz.sql b/src/test/regress/sql/ti= mestamptz.sql index c023095..ce9d1c2 100644 *** a/src/test/regress/sql/timestamptz.sql --- b/src/test/regress/sql/timestamptz.sql *************** SELECT '2007-12-09 07:00:00 UTC'::timest *** 468,470 **** --- 468,481 ---- SELECT '2007-12-09 07:00:01 UTC'::timestamptz AT TIME ZONE 'VET'; SELECT '2007-12-09 07:29:59 UTC'::timestamptz AT TIME ZONE 'VET'; SELECT '2007-12-09 07:30:00 UTC'::timestamptz AT TIME ZONE 'VET'; +=20 + -- + -- Test that the pg_timezone_names and pg_timezone_abbrevs views are + -- more-or-less working. We can't test their contents in any great detail + -- without the outputs changing anytime IANA updates the underlying data, + -- but it seems reasonable to expect at least one entry per major meridia= n. + -- (At the time of writing, the actual counts are around 38 because of + -- zones using fractional GMT offsets, so this is a pretty loose test.) + -- + select count(distinct utc_offset) >=3D 24 as ok from pg_timezone_names; + select count(distinct utc_offset) >=3D 24 as ok from pg_timezone_abbrevs; ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--