Subject: | Bad date computing. |
I ran this script on 23 May 2011, I think there is a problem on month
crossing.
use Schedule::Cron::Events;
use strict;
use warnings;
use DateTime;
use HTTP::Date;
use Time::HiRes;
# ($year,$month,$day,$hour,$minute,$second,$tz) =
HTTP::Date::parse_date($str);
# my $datetime_event = DadaMobile::Time::parse( (sprintf "%4d-%02d-%02d
%02d:%02d:%02d", $year, $month, $day, $hour, $min, $sec), 'UTC' );
my $crontime = "00 14 * * 1,4";
my $now = DateTime->from_epoch( epoch => Time::HiRes::time(), time_zone
=> 'UTC' );
my $date = [ split /,/, $now->strftime('%S,%M,%H,%d,%m,%Y') ];
$date->[5] -= 1900; # 1900 + date->[5] => current year
my $obj_crontab = Schedule::Cron::Events->new( $crontime, Date => $date );
for (my $i = 0 ; $i<5 ; $i++ ) {
my ( $sec, $min, $hour, $day, $month, $year ) =
$obj_crontab->nextEvent();
my $obj_dt = DateTime->new(
year => $year + 1900 ,
month => $month ,
day => $day ,
hour => $hour ,
minute => $min,
second => $sec,
nanosecond => 0,
time_zone => 'UTC'
);
print "next event => $obj_dt\n";
}
next event => 2011-05-23T14:00:00 MONDAY,
next event => 2011-05-27T14:00:00 THUESDAY,
next event => 2011-05-30T14:00:00 MONDAY,
next event => 2011-06-04T14:00:00 SATURDAY ???
next event => 2011-06-07T14:00:00 THURSDAY ???
The correct results are
next event => 2011-06-02T14:00:00 THUESDAY
next event => 2011-06-06T14:00:00 MONDAY
------------
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
Linux ubuntu 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:46 UTC
2011 x86_64 GNU/Linux
Schedule-Cron-Events-1.8-shl9hp