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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.