--- sample program ---

use strict;
use DateTime::Event::Recurrence;

my $blackout_start =
    DateTime::Event::Recurrence->daily(
        hours => 22 
    );
my $blackout_end   = 
    DateTime::Event::Recurrence->daily( 
        hours => 23 
    );

my $blackout = 
    DateTime::SpanSet->from_sets(
        start_set => $blackout_start,
        end_set   => $blackout_end 
    );

test( DateTime->now );
test( DateTime->now->set( hour => 22 ) );
test( DateTime->now->set( hour => 23 ) );

sub test {
    print $_[0]->datetime;
    if ( $blackout->contains( $_[0] ) )
    {
       print " Inside Blackout...no checks !\n";
    }
    else
    {
       print " Outside Blackout...\n";
    }
}

--- Output ---
2004-02-25T20:52:23 Outside Blackout...
2004-02-25T22:52:23 Inside Blackout...no checks !
2004-02-25T23:52:23 Outside Blackout...
---

Flavio S. Glock


> Hi !
> 
> I have to do some checks every minute. For maintenance I have to define a
> blackout-period with
> no checks (example: blackout start 22:00, end: 23:00, interval: daily).
> 
> I have had a look at DateTime::Span, but unfortunately I'm a little bit
> confused...
> 
> I build a "Span":
> 
> $iso8601 = DateTime::Format::ISO8601->new;
> $blackout_dt_start = $iso8601->parse_datetime( "22:00" );
> $blackout_dt_end = $iso8601->parse_datetime( "23:00" );
> $span = DateTime::Span->from_datetimes( start => $blackout_dt_start, end =>
> $blackout_dt_end );
> 
> and made the checks:
> 
> while (1)
> {
>     my $dt_now = DateTime->now;
>     if ( $span->contains( $dt_now))
>     {
>        print " Inside Blackout...no checks !";
>     }
>     else
>     {
>        print " Outside Blackout...";
>        do_check();
>     }
> 
>     sleep (60);
> }
> 
> My question: how to build recurring "span" for every day? I have had a look
> at DateTime::SpanSet but there
> is no method "from_span_and_duration" like the existing method
> "from_set_and_duration"....
> 
> 
> 
> ---
> 
>   Oliver Raupach
>


Reply via email to