Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #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

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2018-09-20 04:40 GMT
    Find Nodes?
      Voting Booth?
      Eventually, "covfefe" will come to mean:

      Results (171 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!