tzdb: cannot locate zone

Trying to run my an old app...
where:
 
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.
Maybe you can use "EST"/"EDT" instead.

Unfortunately..
tzdb: cannot locate zone: EST
tzdb: cannot locate zone: EDT
tzdb: cannot locate zone: /usr/share/zoneinfo/America/New_York
as well((
btw, the "some code"(Ubuntu)" mentioned above is a "EST5EDT"... from the file "New_York".
tzdb: cannot locate zone: EST5EDT
That looks like the timezone is not correctly configured. Did you considered this:

https://wiki.debian.org/TimeZoneChanges
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".
Last edited on
Just found another way... but not what I really want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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;
}



Current time in New York: 11:31:07 -0500
Registered users can post here. Sign in or register to post.