public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add workaround for old tzdata.zi files
Date: Thu, 26 Jan 2023 13:50:46 +0000	[thread overview]
Message-ID: <20230126135046.1441243-1-jwakely@redhat.com> (raw)

Tested x86_64-linux (Fedora 36 and RHEL 6.10). Pushed to trunk.

-- >8 --

The tzdata.zi file in the RHEL 6 tzdata-2018e-3.el6 package (with
version "unknown") does not conform to the current rules described in
the zic(8) man page. Specifically, a Rule name must not start with the
character '+' in the current rules, but the older tzdata.zi file
used "+" as the name of rules for the "Europe/Sofia" zone.

Add a special case to the logic that detects whether a RULES field
refers to a named rule or is an offset from standard time. For a string
matching exactly "+" treat it as a named Rule, but for any other string
starting with '+' treat it as an offset.

libstdc++-v3/ChangeLog:

	* src/c++20/tzdb.cc (operator>>(istream&, ZoneInfo&)): Allow
	rules named "+" for compatibility with older tzdata.zi files.
---
 libstdc++-v3/src/c++20/tzdb.cc | 49 +++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index c945f002ad7..c956e861891 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1967,6 +1967,22 @@ namespace std::chrono
       return in;
     }
 
+    // Test whether the RULES field of a Zone line is a valid Rule name.
+    inline bool
+    is_rule_name(string_view rules) noexcept
+    {
+      // The NAME field of a Rule line must start with a character that is
+      // neither an ASCII digit nor '-' nor '+'.
+      if (('0' <= rules[0] && rules[0] <= '9') || rules[0] == '-')
+	return false;
+      // However, some older tzdata.zi files (e.g. in tzdata-2018e-3.el6 RPM)
+      // used "+" as a Rule name, so we need to handle that special case.
+      if (rules[0] == '+')
+	return rules.size() == 1; // "+" is a rule name, "+1" is not.
+      // Everything else is the name of a Rule.
+      return true;
+    }
+
     istream& operator>>(istream& in, ZoneInfo& inf)
     {
       // STDOFF  RULES  FORMAT  [UNTIL]
@@ -1976,25 +1992,28 @@ namespace std::chrono
 
       in >> off >> quoted{rules} >> fmt;
       inf.m_offset = off.time;
-      if (rules == "-")
+      if (is_rule_name(rules))
 	{
-	  // Standard time always applies, no DST.
-	  inf.set_abbrev(fmt);
-	}
-      else if (string_view("0123456789-+").find(rules[0]) != string_view::npos)
-	{
-	  // rules specifies the difference from standard time.
-	  at_time rules_time;
-	  istringstream in2(std::move(rules));
-	  in2 >> rules_time;
-	  inf.m_save = duration_cast<minutes>(rules_time.time);
-	  select_std_or_dst_abbrev(fmt, inf.m_save);
-	  inf.set_abbrev(fmt);
+	  // `rules` refers to a named Rule which describes transitions.
+	  inf.set_rules_and_format(rules, fmt);
 	}
       else
 	{
-	  // rules refers to a named Rule which describes transitions.
-	  inf.set_rules_and_format(rules, fmt);
+	  if (rules == "-")
+	    {
+	      // Standard time always applies, no DST.
+	    }
+	  else
+	    {
+	      // `rules` specifies the difference from standard time,
+	      // e.g., "-2:30"
+	      at_time rules_time;
+	      istringstream in2(std::move(rules));
+	      in2 >> rules_time;
+	      inf.m_save = duration_cast<minutes>(rules_time.time);
+	      select_std_or_dst_abbrev(fmt, inf.m_save);
+	    }
+	  inf.set_abbrev(fmt);
 	}
 
       // YEAR [MONTH [DAY [TIME]]]
-- 
2.39.1


                 reply	other threads:[~2023-01-26 13:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230126135046.1441243-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).