in reply to Re^4: Date::Manip and daylight savings
in thread Date::Manip and daylight savings

If you'll switch to using the Object Oriented interface of Date::Manip, there won't be any problem. The functional interface is limited by being backward compatible with the old version of Date::Manip (which didn't work well with timezones). Look at the man page for Date::Manip for information on how to use it. Then, you would write:

#!/usr/bin/perl use 5.10.1; use strict; use warnings; use Date::Manip::Date; my $date1 = new Date::Manip::Date; my @dates = ('2011103003:00:00', '2011103002:00:00', '2011103001:00:00', '2011103000:00:00'); my $delta1 = $date1->new_delta(); $delta1->parse('-0:0:-0:0:1:0:0'); foreach my $date (@dates) { $date1->parse($date); my $date2 = $date1->calc($delta1); print "date: ",$date1->printf('%g')," ", "date2: ",$date2->printf('%g'),"\n"; }

If you want different information, use different printf formats.

The 'one day ago' question cannot be defined to be 'the same time yesterday' because that's not guaranteed to exist. The definition that I'm leaning to (when/if I implement it) is:

The same time yesterday with the same offest as today. If that doesn't exist, then the same time yesterday in the other offset. If that doesn't exist, then 24 hours in the past.

A definition like that is the only way to handle all of the daylight saving time changes, and I'm strongly considering implementing it (in approximate mode only). It probably gives the results that people expect most of the time (though that one time when the third case kicks in is going to confuse people... but daylight saving time is by definition confusing :-).

I won't use the 23/24/25 hour definition because that's even less well defined unless you're strictly talking about midnight to midnight calculations. If you do a 1:30 AM to 1:30 AM day, the rules would be non-intuitive (though you could certainly express the calculation in those terms).

One way to get what you want is to do the calculation and then explicitly set the time... but be careful. You can't set the time if to an invalid time in your timezone.

Replies are listed 'Best First'.
Re^6: Date::Manip and daylight savings
by ChrisDennis (Sexton) on Nov 07, 2011 at 18:34 UTC

    Thanks for that sample code -- I can see that I'll have to grapple with the OO interface, and code some special cases for when the target time doesn't exist.

    You're right about my definition of a day -- I'd forgotten about the missing hour in the spring.

    cheers

    Chris