Miscellaneous

Dave Rolsky edited this page Jan 30, 2017 · 1 revision

How do I do business week calculations?

TODO

e.g. 3 business days from now...

How do I localize dates?

DateTime.pm is designed to integrate with the DateTime::Locale modules in order to allow you to localize output. In addition, the DateTime::Format::Strptime uses the locale modules to localize parsing.

# fr_FR = French (France)
my $dt = DateTime->new( year => 2000, month => 3, locale => 'fr_FR' );

print $dt->month_name;

What are GMT, TAI, UTC, and UT1?

Provided by Flavio Glock (fglock at pucrs dot br), from discussions with Peter J. Acklam, Flavio Glock, John Peacock, Eugene Van Der Pijll and others

Before 1972, the "international time" reference was GMT. In GMT, all days have the same number of seconds. A day starts at "midnight" and has 86400 seconds. However, the length of a second would vary since it was based on astronomical observations.

TAI is another time measuring system, in which seconds depend on "atomic time" only, instead of the Sun-Earth position. TAI days have 86400 seconds, and its origin is in 1958 January 1.

Parallel with those, there exists UT1, which is the "astronomical time". UT1 depends only on Sun-Earth position. UT1 - TAI has grown over time, as the Earth's rotation has slowed over time and the length of a day has increased. The difference between the two is a floating point number.

In 1972 UTC was introduced, in order to approximate "international time" to "astronomical time". Now, whenever the difference between UTC and UT1 is big enough, a leap second is introduced. UTC is synchronized to TAI, which means that UTC - TAI is an integral number of seconds. UTC - UT1 is a fraction of a second.

The DateTime module keeps time in UTC, except when using the floating time zone.

How does DST affect day length?

DST stands for Daylight Saving Time. This is also referred to as summer time in Europe, and possibly other names elsewhere. In places that use DST, the clock will jump forward an hour at one point during the year, and then at some other point it jumps backward an hour.

In the US, the clock jumps forward at 2 AM on the first Sunday in April, and moves back (to Standard Time) at 2 AM on the last Sunday in October.

For example, on April 6 of 2003, the clock went from 1:59 AM to 3:00 AM. This means that this day was only 23 hours long, as measured by a wall clock in the US. On October 26, the clock went from 1:59 AM back to 1:00 AM. This means this was 25 hours long, again measured by the wall clock.

This can cause some strange results when doing date math (see the DateTime.pm docs for details). It also means that certain DateTime.pm objects just cannot exist. You cannot create an object to represent 2:30 AM (local time) on April 6, 2003 in a US time zone.