I've found lots of discussion about this in the net, but nothing that solves my problem.

Here's the bare-bones code, taken from a program that steps backwards in time a period at a time, where 'period' can be an hour, day, week, month, or year.

#!/usr/bin/perl use 5.10.1; use strict; use warnings; use Date::Manip; print "Date::Manip version " . Date::Manip->VERSION . "\n"; print "\nHours: \n"; # Note that daylight saving ended here in the early # hours of 30 October 2011. my @dates = ('2011103003:00:00', '2011103002:00:00', '2011103001:00:00', '2011103000:00:00'); foreach my $date1 (@dates) { my $date2 = DateCalc($date1, '-0:0:-0:0:1:0:0', 1); print "date: $date1 date-1h: $date2\n"; $date2 = DateCalc($date1, '-0:0:-0:0:2:0:0', 1); print "date: $date1 date-2h: $date2\n"; } print "\nDays: \n"; my @dates2 = ('2011110100:00:00', '2011103100:00:00', '2011103000:00:00'); print "mode=0\n"; my $err = 0; foreach my $date1 (@dates2) { my $date2 = DateCalc($date1, '-0:0:-0:1:0:0:0', \$err, 0); print "date: $date1 date-1d: $date2 err=$err\n"; } print "mode=1\n"; foreach my $date1 (@dates2) { my $date2 = DateCalc($date1, '-0:0:-0:1:0:0:0', \$err, 1); print "date: $date1 date-1d: $date2 err=$err\n"; }
which produces the following output:
Date::Manip version 6.11 Hours: date: 2011103003:00:00 date-1h: 2011103002:00:00 date: 2011103003:00:00 date-2h: 2011103001:00:00 date: 2011103002:00:00 date-1h: 2011103001:00:00 date: 2011103002:00:00 date-2h: 2011103001:00:00 date: 2011103001:00:00 date-1h: 2011103001:00:00 date: 2011103001:00:00 date-2h: 2011103000:00:00 date: 2011103000:00:00 date-1h: 2011102923:00:00 date: 2011103000:00:00 date-2h: 2011102922:00:00 Days: mode=0 date: 2011110100:00:00 date-1d: 2011103100:00:00 err=0 date: 2011103100:00:00 date-1d: 2011103001:00:00 err=0 date: 2011103000:00:00 date-1d: 2011102900:00:00 err=0 mode=1 date: 2011110100:00:00 date-1d: 2011103100:00:00 err=0 date: 2011103100:00:00 date-1d: 2011103001:00:00 err=0 date: 2011103000:00:00 date-1d: 2011102900:00:00 err=0

There are two issues here.

When going back an hour at time from 1am on 30 October, it gets back to...1am on 30 October, making the program loop. I can see why this happens, and I can work around it quite easily, but it's a trap for young users of Date::Manip.

Secondly, when jumping back a day past the end of daylight savings, it only goes back 24 hours, despite the day being 25 hours long, whether or not I use 'approximate' mode.

Am I doing something wrong? Is there a way round this issue?

Or should I switch to using something like Date::Calc instead of Date::Manip?

cheers

Chris


In reply to 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.