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.


In reply to Re^5: Date::Manip and daylight savings by SBECK
in thread Date::Manip and daylight savings by ChrisDennis

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.