Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: DateTime and hour 0

by RazorbladeBidet (Friar)
on Apr 18, 2005 at 13:19 UTC ( #448840=note: print w/replies, xml ) Need Help??


in reply to DateTime and hour 0

You entered hour "24" when there is only an hour up to "23"... try $hour % 24 (that is, hour modulus 24)
--------------
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."

Replies are listed 'Best First'.
Re^2: DateTime and hour 0
by tcf03 (Deacon) on Apr 18, 2005 at 13:54 UTC
    I didn't set it to 24 I tried 0 and 00, thats why the error seems odd to me. here is the beginning of the sub where this is located
    sub minutes_before { my $minutes_b4=shift; my $month=shift; my $day=shift; my $hour=shift; my $minute=shift; my $MONTHNUM=&month_to_num($month); ( $day < 10 ) ? $FDAY="0$day" : $FDAY=$day; # Lets find n minutes before! $datetime=DateTime->new( year => 2005, month => $MONTHNUM, day => $FDAY, hour => $hour, minute => $minute, second => 00 ); my $formatter=DateTime::Format::Epoch->new( epoch => $datetime, unit => 'seconds', type => 'int', # or 'float', or 'b +igint' skip_leap_seconds => 1, start_at => 0, local_epoch => undef ); my $seconds=$formatter->format_datetime($datetime); my $conv_seconds=$minutes_b4 * 60; $seconds=$seconds-$conv_seconds; # And we are left with n seconds before our search time my $MinBefore=$formatter->parse_datetime( $seconds ); # Now we'll reformat $MinBefore to fit the log file my ($DATE2, $TIME2)=split(/T/, $MinBefore); ($YEAR2, $MONTH2, $DAY2)=split(/-/, $DATE2); $MONTHNAME2=&num_to_month($MONTH2); ($HOUR2, $MINUTE2, $SECOND2)=split(/:/, $TIME2); # End of reformatting $MinBefore $DAY2=~s/^0+//; $ready=1; return @MINBEFORE=($MONTHNAME2, $DAY2, $HOUR2, $MINUTE2); }
    and here is where $hour gets set:
    if ( defined (param('MONTH')) and defined (param('DAY')) and defined (param('HOUR')) and defined (param('MINUTE')) ) { $MONTH=param('MONTH'); $DAY=param('DAY'); $HOUR=param('HOUR'); $MINUTE=param('MINUTE');
    snip...
    @M1=&minutes_before(1, $MONTH, $DAY, $HOUR, $MINUTE);
    The code works as its supposed to execept when I enter 0 or 00.
    Thanks
    Ted
    update
    $hour % 24 didn't work either.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://448840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2020-10-26 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (252 votes). Check out past polls.

    Notices?