Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get system's Tz #81

Closed
nooberfsh opened this issue May 24, 2021 · 3 comments
Closed

Is there a way to get system's Tz #81

nooberfsh opened this issue May 24, 2021 · 3 comments

Comments

@nooberfsh
Copy link

No description provided.

@quickdudley
Copy link

I'd be happy to do a PR to add this functionality to chrono-tz; especially since I also need it. However there's no platform-independent way to do this and I won't have access to a Windows environment for a few of days.

On Unix-like the best way is to try each of these and use the first one that gives you a valid timezone identifier

  1. Check the TZ environment variable
  2. If /etc/localtime is a symbolic link then check where it points: the path should be of the form {outer directory}/zoneinfo/{timezone identifier}
  3. Search /usr/share/zoneinfo and /var/db/timezone/zoneinfo for a file which is the same as /etc/localtime

Windows has a C function called GetTimeZoneInformation in timezoneapi.h which is documented at https://docs.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation

@astraw
Copy link

astraw commented Dec 13, 2022

This is the raison d'etre of iana-time-zone. It's output can be parsed to make a chrono_tz::Tz like so:

let tz_str = iana_time_zone::get_timezone()?;
let tz: chrono_tz::Tz = tz_str.parse()?;

@djc
Copy link
Contributor

djc commented Dec 13, 2022

I think that's a pretty good way to do it, so I'll close this for now.

@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants