Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Check if Date interval contains Hour X

by alexm (Chaplain)
on Jul 23, 2009 at 21:40 UTC ( #782793=note: print w/ replies, xml ) Need Help??


in reply to Re: Check if Date interval contains Hour X
in thread Check if Date interval contains Hour X

Another (maybe simpler) way of truncating:

sub hour_in_range { my ($dt_s, $dt_e, @hours) = @_; for my $hour (@hours) { my $dt = $dt_s->clone() ->truncate( to => 'day' ) ->add( hours => $hour ); $dt->add( days => 1 ) if $dt < $dt_s; return 1 if $dt <= $dt_e; } return 0; }

Replies are listed 'Best First'.
Re^3: Check if Date interval contains Hour X
by ikegami (Pope) on Jul 23, 2009 at 21:50 UTC
    That introduced a bug. hour_in_range no longer performs as documented. Test case:
    2010-10-10 01:59:59|2010-10-10 01:59:59|blablalblabla

      I see. In order to check only the hour (skipping minutes and seconds), $dt_s must be truncated to the hour.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2016-06-26 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (328 votes). Check out past polls.