Raku Land

DateTime::Timezones

github:alabamenhu

DateTime::Timezones

Phileas Fogg avait, «sans s'en douter», gagné un jour sur son itinéraire, - et cela uniquement parce qu'il avait fait le tour du monde en allant vers l'est, et il eût, au contraire, perdu un jour en allant en sens inverse, soit vers l'ouest.
Le Tour du monde en quatre-vingts jours (Jules Vernes)

An module to extend the built in DateTime with timezone support. To use, simply include it at any point in your code:

use DateTime::Timezones;

my $dt = DateTime.new: now;

This extends DateTime to include the following three new attributes whose names are subject to change.

For the most part, once you enable it, you won't need to do anything different at all, as it is designed to be as discreet as possible. There are, nonetheless, a few things to note:

Leapseconds

Leapseconds are annoying for timekeeping and POSIX explicitly ignores them since future ones are unpredictable because weird physics. I have yet to rigorously test that leapseconds are handled correctly, but welcome any code review and/or pull requests to remedy this (particularly test cases).

How does it work?

While the module initially planned on augmenting DateTime, it turns out that has significant problems for things like precompilation (you can't) and requires enabling MONKEY-TYPING which just feels dirty.

Previously, DateTime.new was wrapped with a new method that returned the same (or functionally the same) DateTime you would have expected and mixes in the parameterized TimezoneAware role. It had a few tricks to make sure it doesn't apply the role multiple times. Now, it uses a new technique pioneered by Elizabeth Mattijsen to avoid some of the wraps, and uses the earlier techniques for protecting any precompiled core DateTime objects.

The data files come from the IANA, and are compiled using their zone information compiler (ZIC) prior to distribution.

Version history