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

Re: A question to iterator in Datetime::Event::Recurrence

by Anonymous Monk
on Apr 11, 2012 at 09:56 UTC ( #964491=note: print w/replies, xml ) Need Help??

in reply to A question to iterator in Datetime::Event::Recurrence

Please give me a hint.

Ditch DateTime::Event::Recurrence :) or explain your requirements better, my impression, you want some math

print " ###### \n"; while( $start < $end ){ print "$start\n"; $start->add( hours => 1 ); }

Replies are listed 'Best First'.
Re^2: A question to iterator in Datetime::Event::Recurrence
by vagabonding electron (Chaplain) on Apr 11, 2012 at 10:14 UTC
    Thank you very much!

    Ditch DateTime::Event::Recurrence :)

    Now after I have tried so much to familiarize to it? :-)

    The task is to calculate the bed occupancies in a unit to every certain hour. The start and the end points are known, the iterator generates the hours and then I use $hash{$dt->datetime()}{$id}[0] = 1 for each hour (to sum it later).
    The print was used just to debug.
    The way around could be to use
    while ( my $dt = $it->next() ) { print $dt->datetime(), "\n" if ($dt->hour > 6 and $dt->hour < 23); }
    but since I am learning I would like to use the mainstream and not the way around.
    Thanks again!
        Aye-aye, sir! :-)
        #!/usr/bin/perl use strict; use warnings; use DateTime; use DateTime::Format::Strptime; use Datetime::Set; # use Data::Dumper; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %T', ); my $datf = qq{2012-01-01 04:00:00}; my $datt = qq{2012-01-02 23:00:00}; my $start = $strp->parse_datetime($datf); my $end = $strp->parse_datetime($datt); while( $start < $end ){ print "$start\n" if $start->hour > 6 and $start->hour < 23; $start->add( hours => 1 ); }
        I had bad luck with an attempt over $set = DateTime::Set->from_recurrence however.
        This one:
        $set = DateTime::Set->from_recurrence( after => $start, before => $end, recurrence => sub { return $_[0]->truncate( to => 'day' )->add( hours => 1 ) }, ); my $iter = $set->iterator; while ( my $dt = $iter->next ) { print $dt->ymd; };
        produced an infinite loop with the error message "iterator can't find a previous value". I intended to add later
        my $set2 = $set->grep( sub { return ( $_->hour > 7 or $_->hour < 23); } ); my $iter = $set2->iterator; while ( my $dt = $iter->next ) { print $dt->ymd; };

        Where is my mistake?
        Many thanks again - also for answering my previous question!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964491]
[oiskuu]: Hm. that depends on kernel compiled with CONFIG_AUDITSYSCAL L
[tye]: apropos my several mentions of audit
[Corion]: At least my (non-SELinux) Debian has that config thing set. I don't have non-Debian machines handy (except Android)
[Corion]: My Android phone also has /proc/self/ loginuid, but that displays -1 (resp. 4GB). That might be because the phone is rooted.
[tye]: -1 means nobody logged in or the process was started before audit got booted
[davido]: ok, on my ubuntu system getlogin grabs from /proc/self/ loginuid (per strace)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-06-23 19:58 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.