admin管理员组文章数量:1313084
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.
1 Answer
Reset to default 7This 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
版权声明:本文标题:c++ - std::chrono::tzdb: cannot locate zone: AmericaNew_York - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741949234a2406608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/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 oneAmerica/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:20America/New_York
is an alias ofEST5EDT
. OP, you can try to replaceAmerica/New_York
withEST5EDT
orUS/Eastern
. – 3CxEZiVlQ Commented Jan 30 at 17:24EST5EDT
is a zone entry in itself - but it doesn't help to set that unfortunately. – Ted Lyngmo Commented Jan 30 at 17:29