houseabsolute / DateTime-TimeZone

Time zone object base class and factory
https://metacpan.org/release/DateTime-TimeZone/
Other
9 stars 25 forks source link

Support Linux system default zoneinfo #33

Open ghost opened 5 years ago

ghost commented 5 years ago

Now this library bundles a converted Olson data with itself, and there is no way to use Linux system default zoneinfo. It becomes a problem if user does not keep their version of the library up-to-date. Python's pytz uses TZ format zoneinfo data and allows an env var for user to use system default zoneinfo.

autarch commented 5 years ago

I'm not sure exactly what you're asking for. You can ask for the system's definition of its time zone by specifying the time zone name as local. This won't actually load the system's zone definition file, but it will attempt to match whatever the local system does.

I would like to have this distro be able to use the tz definition files directly, but that work's been stalled for a while.

ghost commented 5 years ago

I would like to have this distro be able to use the tz definition files directly, but that work's been stalled for a while.

This is exactly what I need. At my workplace we would like to directly use the tz files from /usr/share/zoneinfo. DateTime::TimeZone is so well known and so widely used in the Perl community, we would like to avoid creating our own new library and tell our developers to switch. So it's best to have the support from within DateTime::TimeZone. Python's pytz, which is the equivalent of DateTime::TimeZone, ships a zoneinfo dir with itself, and it allows overrding the path via an env var.

autarch commented 5 years ago

I see. No one is working on this feature right now, unfortunately. Years back a Perl person who goes by Zefram had a nearly done prototype of this. Unfortunately, he didn't quite finish this. He shared work in progress but it never ended up in a durable location so I can't get this and finish it.

However, he does have a distro on CPAN that is probably good enough for your needs at https://metacpan.org/release/DateTime-TimeZone-Tzfile

ghost commented 5 years ago

Some more findings today:

Besides pytz I mentioned yesterday, Python's another library called dateutil (python-dateutil), intrinsically uses /usr/share/zoneinfo on Linux, and only uses its bundled TZ files as a fallback. So both of the two major Python timezone libraries supports TZ files and can easily use /usr/share/zoneinfo. I guess the performance impact of parsing TZ files is actually not much.

On the contrary, the Perl timezone libraries cannot easily use /usr/share/zoneinfo. Both the two dominant ones, DateTime::TimeZone and Date::Manip convert TZ files to Perl modules, and do not support parsing/using TZ files. Zefram's DateTime::TimeZone::Olson uses TZ files, but it also ships Olson via his another library Time::OlsonTZ::Data which is not designed to allow an easy switch to /usr/share/zoneinfo. Also DateTime::TimeZone::Olson is so less known in the Perl community...