admin管理员组

文章数量:1313274

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.

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.

Share Improve this question edited Jan 30 at 17:07 Drew Dormann 64k14 gold badges128 silver badges197 bronze badges asked Jan 30 at 16:59 TaylorTaylor 2,0855 gold badges28 silver badges61 bronze badges 8
  • IANA Time Zone Database has changed on 2025-01-15, this may be a reason. – 3CxEZiVlQ Commented Jan 30 at 17:19
  • Your program runs clean on Fedora 41 but I can reproduce the issue on Ubuntu 24.04 (WSL). There are a lot of differences in /usr/share/zoneinfo/tzdata.zi on those two machines. The Ubuntu version has 4622 lines and the Fedora version only has 4281 - but, it has one America/New_Your record more: L America/New_York EST5EDT. Both files have a heading saying # version 2024b though. – Ted Lyngmo Commented Jan 30 at 17:20
  • @TedLyngmo America/New_York is an alias of EST5EDT. OP, you can try to replace America/New_York with EST5EDT or US/Eastern. – 3CxEZiVlQ Commented Jan 30 at 17:24
  • IMO this is a bug in the last Ubuntu update. Please report it them. – 3CxEZiVlQ Commented Jan 30 at 17:28
  • @3CxEZiVlQ Yes, it's marked as a link to it in Fedora and in Ubuntu, EST5EDT is a zone entry in itself - but it doesn't help to set that unfortunately. – Ted Lyngmo Commented Jan 30 at 17:29
 |  Show 3 more comments

1 Answer 1

Reset to default 7

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/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.

本文标签: cstdchronotzdb cannot locate zone AmericaNewYorkStack Overflow