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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
my $hour_span = DateTime::Span->from_datetimes( start => $dt, end => $dt );

should be

my $hour_span = DateTime::Span->from_datetimes( start => $dt, before => $dt->clone()->add( hours => 1 ), );

or the more readable

my $hour_span = DateTime::Span->new( start => $dt, hours => 1, );

Update: No, neither fix help. They were suppose to make the following match:

2010-10-10 01:59:59|2010-10-10 01:59:59|blablalblabla

You need

sub hour_in_range { my ($dt_s, $dt_e, @hours) = @_; my $dt_span = DateTime::Span->from_datetimes( start => $dt_s, end => $dt_e ); for my $hour (@hours) { my $dt = $dt_s->clone() ->truncate( to => 'day' ) ->add( hours => $hour ); my $dt_tomorrow = $dt->clone()->add( days => 1 ); my $hour_span = DateTime::Span->new( start => $dt, hours => 1 )->union( DateTime::Span->new( start => $dt_tomorrow, hours => 1 )); return 1 if $dt_span->intersects($hour_span); } return 0; }

And there you go, the four DateTimes per hour I mentioned earlier.


In reply to Re^6: Check if Date interval contains Hour X by ikegami
in thread Check if Date interval contains Hour X by gulden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-03-28 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found