Im using DateTime in a script and I keep getting the following error when entering 0 or 00 for my hour.
The 'hour' parameter ("24") to DateTime::new did not pass the 'is betw +een 0 and 23' callback at /usr/lib/perl5/site_perl/5.8.5/DateTime/Format/Epoch.pm line 179
and here is how DateTime is using $hour:
$datetime=DateTime->new( year => 2005, month => $MONTHNUM, day => $FDAY, hour => $hour, minute => $minute, second => 00 );
any Ideas about the error?
Ted

UPDATE another oddity is that 00 does work (in the hour field) as long as $minute >= 10. if I set minute to anything less that 10. Im looking through Epoch.pm from DateTime::Format::Epoch, but its a bit above my skill level.
UPDATE2
fglock nailed it when he suggested changing the algorithm. Here is the new code that works. Thanks for all you're suggestions.
sub minutes_before { my $minutes_b4=shift; my $month=shift; my $day=shift; my $hour=shift; my $minute=shift; # Lets find n minutes before! my $datetime=DateTime->new( year => 2005, month => month_to_num($month), day => $day, hour => $hour, minute => $minute ); $datetime->subtract( minutes => $minutes_b4 ); # This is clumsy, ill use it now # and fix it later if ( $datetime->day < 10 ) { $day="0".$datetime->day; } else { $day=$datetime->day; } if ( $datetime->hour < 10 ) { $hour="0".$datetime->hour; } else { $hour=$datetime->hour; } if ( $datetime->minute < 10 ) { $minute="0".$datetime->minute; } else { $minute=$datetime->minute; } # End of genereal clumsiness... $ready=1; return @MINBEFORE = ( num_to_month($datetime->month), $day, $hour, $minute ); }
There is still the messiness of zero padding, but ill figure that out in time - if anyone has suggestions that would be cool.

In reply to DateTime and hour 0 by tcf03

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.