Rand Stats

The uploading author of github:alabamenhu does not match the META author of zef:guifa.




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.

.olson-idStrThe unique Olson ID for the timezone
.tz-abbrStrAn (mostly) unique abbreviation for the timezone
.is-dstBoolWhether the timezone is in daylight savings time

The Olson IDs (or timezone identifiers) are maintained by the IANA and based around city names, in the format of Region/City, and occasionally Region/Subregion/City. They do not tend to align with popular usage.
In the United States, for instance, what is commonly called Eastern Time is listed as America/New_York).

The timezone abbreviation is representative of popular usage, but isn't unique. It's appropriate for a quick timestamp as it adjusts for daylight savings time, but for other display purposes, you may want to look to Intl::Format::DateTime.

The DST attribute returns whether the timezone is in what is commonly referred to as Daylight Saving Time (or Summer Time). In some time zones, False is the only value.

Additional Information

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 are annoying for timekeeping and POSIX explicitly ignores them since future ones are unpredictable because weird physics. I do not have the expertise to ensure 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.

Instead, DateTime.new is wrapped with a new method that returns the same (or functionally the same) DateTime you would have expected and mixes in the parameterized TimezoneAware role. It has a few tricks to make sure it doesn't apply the role multiple times.

Version history