Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Time::Period overlaps?

by ikegami (Patriarch)
on Mar 15, 2006 at 01:20 UTC ( #536750=note: print w/replies, xml ) Need Help??


in reply to Time::Period overlaps?

If you already have the periods in Time::Period's format, it should be trivial to write a version of Time::Period's functions which returns DateTime::SpanSets instead of booleans. For example, below are the guts of the wd and hr.

sub wd { my ($min, $max) = @_ return DateTime::SpanSet->from_set_and_duration( set => DateTime::Set->from_recurrence( recurrence => sub { my ($dt) = @_; return $dt->truncate(to => 'day') ->add(days => ($min-$dt->wday()+7-1) % 7 + 1); }, ), days => $max-$min+1, ); } sub hr { my ($min, $max) = @_ return DateTime::SpanSet->from_set_and_duration( set => DateTime::Set->from_recurrence( recurrence => sub { my ($dt) = @_; $dt = $dt->add(days => 1) if $dt->hour() >= $min; return $dt->truncate(to => 'day')->set(hour => $min); }, ), hours => $max-$min+1, ) } # M-F, 9am to 5pm # wd {mo-fr} hr {9-16} my $sla_period = wd(1,5)->intersection(hr(9, 16));

Still untested.

Replies are listed 'Best First'.
Re^2: Time::Period overlaps?
by merzy (Scribe) on Mar 15, 2006 at 21:14 UTC
    This looks like it would do the trick, ikegami. Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-05-24 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?