Hello! Searching has proven less fruitful than hoped, and the most successful searches ultimately just point to using DateTime. I like this idea, but the senior Perl devs in our company prefer I stick with Date::Manip.
First, a summary with results. I am in mountain time, constructing a date object, changing it to US/Pacific, then making more changes based on user-supplied datetime parameters. In most cases, things work beautifully, but when going more than 15 days back in time, bizarre behavior is occurring.
[me ~]$ perl datefail.pl --startday='-15 days' --endday='-14 days' Start with Today 20151120T22:51-0700 Fix timezone 20151120T21:51-0800 Set the right day 20151105T21:51-0800 Strip the hours 20151105T00:51-0800 Strip the minutes 20151105T00:00-0800 [me ~]$ perl datefail.pl --startday='-19 days' --endday='-18 days' Start with Today 20151120T22:51-0700 Fix timezone 20151120T21:51-0800 Set the right day 20151101T21:51-0800 Strip the hours 20151101T01:51-0700 Strip the minutes 20151101T01:00-0700
Enjoy this simplified code that illustrates the problem.
#!/usr/bin/perl use strict; use warnings; use Date::Manip; use Getopt::Long qw(GetOptions); my $startDay; my $endDay; GetOptions( 'startday=s' => \$startDay ,'endday=s' => \$endDay ); my ( $startDDelta,$zeroStartH,$zeroStartHDelta,$zeroStartM,$zeroStartM +Delta ); print "Start with Today\n"; my $dateObjStart = new Date::Manip::Date('now'); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Fix timezone\n"; $dateObjStart->convert('US/Pacific'); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Set the right day\n"; $startDDelta = new Date::Manip::Delta($startDay); $dateObjStart = $dateObjStart->calc($startDDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Strip the hours\n"; $zeroStartH = '-'.$dateObjStart->printf('%H').' hours'; $zeroStartHDelta = new Date::Manip::Delta($zeroStartH); $dateObjStart = $dateObjStart->calc($zeroStartHDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n"; print "Strip the minutes\n"; $zeroStartM = '-'.$dateObjStart->printf('%M').' minutes'; $zeroStartMDelta = new Date::Manip::Delta($zeroStartM); $dateObjStart = $dateObjStart->calc($zeroStartMDelta); print $dateObjStart->printf('%Y%m%dT%H:%M%z') . "\n";
Thank you kindly for any suggestions you can offer that don't require me to refactor the code to use another package. (Though if that's the only option, I'll just offer the department their choice between that or, say, ColdFusion. Hah.)
In reply to Date::Manip time zone is resetting in some cases by tcabeen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |