BurntSushi / jiff

A date-time library for Rust that encourages you to jump into the pit of success.
The Unlicense
1.74k stars 33 forks source link

tz: attempt to read TZ symlink as IANA time zone identifier #115

Closed BurntSushi closed 2 months ago

BurntSushi commented 2 months ago

Previously, we would only attempt to use symlink metadata when reading from /etc/localtime explicitly. We didn't do this when TZ is set to a path. And in particular, TZ might actually be set to /etc/localtime, in which case, it's likely a symlink. And we can detect the IANA time zone identifier from the symlink in most cases. Just like we would by default if TZ wasn't set.

I originally didn't do this because the code for handling TZ was actually completely platform independent, so it didn't occur to me to do something platform specific on Unix. But it's not too hard to do.

While setting TZ=/etc/localtime is odd, apparently this is given as advice to folks for libc to avoid repeatedly reading /etc/localtime to check for updates. Seems weird to me, but whatever. Jiff should try to detect symlink metadata regardless of libc shenanigans.

Fixes #113