in reply to Re^4: Date::Manip and daylight savings
in thread Date::Manip and daylight savings
From DateTime docs.
When math crosses a daylight saving boundary, a single day may have more or less than 24 hours.
For example, if you do this:
my $dt = DateTime->new( year => 2003, month => 4, day => 5, hour => 2, time_zone => 'America/Chicago', ); $dt->add( days => 1 );then you will produce an invalid local time, and therefore an exception will be thrown.
However, this works:
and produces a datetime with the local time of "03:00".my $dt = DateTime->new( year => 2003, month => 4, day => 5, hour => 2, time_zone => 'America/Chicago', ); $dt->add( hours => 24 );If all this makes your head hurt, there is a simple alternative. Just convert your datetime object to the "UTC" time zone before doing date math on it, and switch it back to the local time zone afterwards. This avoids the possibility of having date math throw an exception, and makes sure that 1 day equals 24 hours. Of course, this may not always be desirable, so caveat user!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Date::Manip and daylight savings
by ikegami (Patriarch) on Nov 07, 2011 at 22:08 UTC | |
by SBECK (Chaplain) on Nov 08, 2011 at 12:45 UTC | |
by ikegami (Patriarch) on Nov 08, 2011 at 18:04 UTC | |
by SBECK (Chaplain) on Nov 08, 2011 at 18:44 UTC | |
by ikegami (Patriarch) on Nov 08, 2011 at 19:49 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2011 at 18:30 UTC | |
by Anonymous Monk on Nov 08, 2011 at 18:48 UTC | |
by ikegami (Patriarch) on Nov 08, 2011 at 19:48 UTC |