https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123510

            Bug ID: 123510
           Summary: chrono::tzdb parser should be case insensitive
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

The zic man page says:

Names must be in English and are case insensitive.  They appear in several
contexts, and include month and weekday names and keywords such as  maximum,
only, Rolling, and Zone.  A name can be abbreviated by omitting all but an
initial prefix; any abbreviation must be unambiguous in context.


The tzdb code is case sensitive, so month names like "may" fail.


// { dg-do run { target c++20 } }
// { dg-require-effective-target tzdb }
// { dg-require-effective-target cxx11_abi }

#include <chrono>
#include <fstream>
#include <cstdio>
#include <testsuite_hooks.h>

static bool override_used = false;

namespace __gnu_cxx
{
  const char* zoneinfo_dir_override() {
    override_used = true;
    return "./";
  }
}

// Uses mixed case and various abbreviations of "Rule", "only", "Oct" etc.
std::string tzdata_zi = R"(
 # version test1
 # Rule  NAME  FROM  TO    TYPE  IN   ON       AT    SAVE  LETTER/S
 Rule    Swiss 1941  1942  -     mAY  mo>=1    1:00  1:00  S
 rule    Swiss 1941  1942  -     Oc   MON>=1   2:00  0     -
 RULE    EU    1977  1980  -     Ap   sund>=1  1:00u 1:00  S
 rule    EU    1977  oNLY  -     sep  lastsu  1:00u 0     -
 r       EU    1978  O     -     oct   1       1:00u 0     -
 ru      EU    1979  1995  -     Sep  LASTSUNDAY  1:00u 0     -
 RUL     EU    1981  MAX   -     maR  lastSun  1:00u 1:00  S
 RuLe    EU    1996  ma    -     oc   LastSun  1:00u 0     -

 # Zone  NAME           STDOFF      RULES  FORMAT  [UNTIL]
 zone    Europe/Zurich  0:34:08     -      LMT     1853 Jul 16
                        0:29:45.50  -      BMT     1894 Jun
                        1:00        Swiss  CE%sT   1981
                        1:00        EU     CE%sT

 link    Europe/Zurich  Europe/Vaduz

)";

using namespace std::chrono;

void
test_load()
{
  const tzdb& db = get_tzdb();
  VERIFY( db.version == "test1" );
  auto z = db.locate_zone("Europe/Vaduz");
  VERIFY( z != nullptr );
  VERIFY( z == db.locate_zone("Europe/Zurich") );
}

int main()
{
  std::ofstream("leapseconds") << '\n';
  std::ofstream("tzdata.zi") << tzdata_zi;

  (void) get_tzdb();
  if (override_used)
  {
    test_load();
  }
  else
    std::puts("__gnu_cxx::zoneinfo_dir_override() doesn't work on this
target");
}

Reply via email to