std::string time = std::format("{:%H:%M:%OS %z}", std::chrono::zoned_time{"America/New_York", now});
terminate called after throwing an instance of 'std::runtime_error'
what(): tzdb: cannot locate zone: America/New_York
Aborted
It returns a such error with any zone. I have this issue on Debian 12. On Deb 11 it worked fine.
1. All files of TZDB are there and readable - /usr/share/zoneinfo/.
2. I have a last version: "tzdata_2024b-0+deb12u1_all"(bookworm); downgrading to "2024b-0+deb11u1"(bullseye) doesn't help.
3. Neither g++ 13.3.0 nor g++ 14.2.0 can obtain the location.
I have searched around... Suggestions like to change "America/New_York" to "some code"(Ubuntu) or downgrading the tzdata(ArchLinux) didn't work for me.
Maybe someone knows how to locate zone? It looks like Debian, as usually, has its own painful way:))
The problem of "America/New_York" is that there are 2 timezones: "EST" and "EDT". The error probably means that the system is not able to figure out which one to use.
Maybe you can use "EST"/"EDT" instead. That'd mean it is up to you to figure out the right one.
I really don't want to change the local time. I have no reason to change time settings, it works fine and may be reconfigured any time if I need.
I want to let my program to represent the local time(or any time point) in time of a certain location - for ex. NY. As I see there: https://wiki.debian.org/TimeZoneChanges - Time Zone changes doesn't affect time representation by std::chrono::zoned_time. Time point representation is the reason why I'm using "zoned_time".
#include <chrono>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
int main() {
// Set the TZ environment variable
setenv("TZ", "America/New_York", 1);
tzset(); // Update the timezone information
auto now = std::chrono::system_clock::now();
auto local_time = std::chrono::system_clock::to_time_t(now);
std::tm* tm_ptr = std::localtime(&local_time);
// Format the time manually
std::cout << "Current time in New York: "
<< std::put_time(tm_ptr, "%H:%M:%S %z") << std::endl;
return 0;
}
This sounds like a breaking change that Debian devs introduced, no? Is there something in the Debian 12 changelogs that mention zoned_time or time zone changes? Maybe a actual Debian forum might know more.
As I understand this, the problem is that in the file tzdata.zi max is Max and hence can't be parsed. If so, why not just edit this file and replace Max with max?
I just can't find neither "Max" nor "max" there. The mentioned string from the bugzilla looks otherwise - there is only "ma". So, I'm not sure should I touch this because there are many strings containing "ma".
from bugzilla:
R K 2023 Max - O lastTh 24 0 -
..../gcc-13.3.0/libstdc++-v3/src/c++20/tzdata.zi:
R K 2023 ma - O lastTh 24 0 -
Okay, I have edited the tzdata.zi :) "ma" -> "max"
Still not working. Maybe it's needed to reboot the machine or restart something? I'm not sure.))