Search code examples
c++c++20c++-chrono

std::chrono::tzdb: cannot locate zone: America/New_York


A random unit test started failing, and I can't remember touching anything pertinent. Here's a minimal reproducible (on my machine) example:

#include <chrono>
#include <string>
#include <sstream>
#include <iostream>

using clock_type = std::chrono::system_clock;
using duration_t = std::chrono::microseconds;
using timepoint_t = std::chrono::time_point<clock_type, duration_t>;

std::string to_eastern_string(timepoint_t tp)
{
    std::ostringstream oss;
    auto tz = std::chrono::locate_zone("America/New_York");
    oss << std::format("{:%F %T}", tz->to_local(tp));
    return oss.str();
}

timepoint_t parse_eastern_time(std::string dtstr)
{
    std::istringstream iss{std::move(dtstr)};
    std::chrono::local_time<duration_t> tp;
    iss >> std::chrono::parse("%F %T",tp);
    return std::chrono::locate_zone("America/New_York")->to_sys(tp);
}

int main(){

    timepoint_t t = parse_eastern_time("2024-11-19 09:30:00.037001");
    std::cout << to_eastern_string(t);
    return 0;
}

on Godbolt I get

2024-11-19 09:30:00.037001

but when I run it on my machine:

g++ -std=c++20 -o test test.cpp
./test 
terminate called after throwing an instance of 'std::runtime_error'
  what():  std::chrono::tzdb: cannot locate zone: America/New_York
Aborted (core dumped)

What gives? Fwiw I'm running Ubuntu 24.04.1 LTS

Edit: total guess, but would this have to do with me messing with environment variables lately? I've been setting LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 lately.


Solution

  • This is a bug in the latest Ubuntu 24.04.1 LTS or Debian update. I've downloaded tzdata_2024b-0ubuntu0.24.04.debian.tar.xz from here https://packages.ubuntu.com/noble-updates/tzdata and what I see in their patch Move-UNIX-System-V-zones-back-from-backzone-to-backwards.patch, they simply removed the alias:

    @@ -61,9 +59,6 @@ Link  America/Whitehorse  Canada/Yukon
     Link   America/Santiago    Chile/Continental
     Link   Pacific/Easter      Chile/EasterIsland
     Link   America/Havana      Cuba
    -Link   Europe/Athens       EET
    -Link   America/Panama      EST
    -Link   America/New_York    EST5EDT
     Link   Africa/Cairo        Egypt
     Link   Europe/Dublin       Eire
     # Vanguard section, for most .zi parsers.
    @@ -102,9 +97,6 @@ Link America/Jamaica     Jamaica
    

    They seem to force users to use EST5EDT.