Yuri6037 / time-tz

Implementation of tz database (IANA) for time Rust crate.
BSD 3-Clause "New" or "Revised" License
22 stars 7 forks source link

timezone defaults to UTC in docker #17

Closed alekspickle closed 10 months ago

alekspickle commented 10 months ago

So if you build in docker get_timezone will return Etc/UTC by default and would be wrong.

For example I am in berlin tz and some of the machines I tried it are in other tz's. It always returns UTC, which is weird.

MRE:

    let tz = time_tz::system::get_timezone().unwrap_or_else(|_| timezones::db::europe::BERLIN);

if you create a simple binary and wrap it in docker this will not fail, but instead return UTC.

Yuri6037 commented 10 months ago

time_tz::system::get_timezone() uses /etc/localtime can you check to what file /etc/localtime points to in your docker?

Note: if all you're after is to get the current system time in local time and not the actual timezone, you can check out bp3d-os with the time feature.

alekspickle commented 10 months ago

Fair enough, but still it kinda unexpected. The content of all images I checked:

root@0e903dfdb4c9:/app# cat /etc/localtime
TZif2UTCTZif2UTC
UTC0
Yuri6037 commented 10 months ago

Fair enough, but still it kinda unexpected. The content of all images I checked:

root@0e903dfdb4c9:/app# cat /etc/localtime
TZif2UTCTZif2UTC
UTC0

Unfortunately, given this output there's not much I can do. Maybe you could use the built-in TZ environment variable parser and use the TZ parser if there is a TZ variable.

alekspickle commented 10 months ago

It's unfortunate: it basically means this crate is unusable in docker.

I just looked at how chrono solves it and it basically doesn't - it's and inherent problem that is typically solved by passing timezone for container manually IIUC. Which is a great surprize to me but manageable. anyway, kudos for crate! it's still better than chrono world IMO

Edit: I just had an idea, that aside from get_by_name it would be really nice to have and interface to query by a standart abbreviation, like CET