Algorithm-Cron
view release on metacpan or search on metacpan
Build.PL
Changes
lib/Algorithm/Cron.pm
LICENSE
Makefile.PL
MANIFEST This list of files
META.json
META.yml
README
t/00use.t
t/01expand.t
t/02cron.t
t/03next_time.t
t/90rt84352.t
t/99pod.t
lib/Algorithm/Cron.pm view on Meta::CPAN
setlocale( LC_TIME, "C" );
%MONTHS = map { lc(strftime "%b", 0,0,0, 1, $_, 70), $_ } 0 .. 11;
# 0 = Sun. 4th Jan 1970 was a Sunday
%WDAYS = map { lc(strftime "%a", 0,0,0, 4+$_, 0, 70), $_ } 0 .. 6;
setlocale( LC_TIME, $old_loc );
}
sub _expand_set
{
my ( $spec, $kind ) = @_;
return undef if $spec eq "*";
my @vals;
foreach my $val ( split m/,/, $spec ) {
my $step = 1;
my $end;
lib/Algorithm/Cron.pm view on Meta::CPAN
$params{sec} = 0 unless exists $params{sec};
my $self = bless {
base => $base,
}, $class;
foreach ( @FIELDS_CTOR ) {
next unless exists $params{$_};
$self->{$_} = _expand_set( delete $params{$_}, $_ );
!defined $self->{$_} or scalar @{ $self->{$_} } or
croak "Require at least one value for '$_' field";
}
return $self;
}
=head1 METHODS
=cut
t/01expand.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Algorithm::Cron;
local *expand = \&Algorithm::Cron::_expand_set;
is_deeply( expand( "*", "sec" ), undef, 'expand sec=*' );
is_deeply( expand( "0", "sec" ), [ 0 ], 'expand sec=0' );
is_deeply( expand( "*/10", "sec" ), [ 0, 10, 20, 30, 40, 50 ], 'expand sec=0/10' );
is_deeply( expand( "5-8", "sec" ), [ 5, 6, 7, 8 ], 'expand sec=5-8' );
is_deeply( expand( "3-17/4", "sec" ), [ 3, 7, 11, 15 ], 'expand sec=3-17/4' );
is_deeply( expand( "*/5", "mday" ), [ 1, 6, 11, 16, 21, 26, 31 ], 'expand mday=*/5' );
is_deeply( expand( "jan", "mon" ), [ 0 ], 'expand mon=jan' );
is_deeply( expand( "mar-sep", "mon" ), [ 2 .. 8 ], 'expand mon=mar-sep' );
is_deeply( expand( "5", "mon" ), [ 4 ], 'expand mon=5' );
is_deeply( expand( "*/3", "mon" ), [ 0, 3, 6, 9 ], 'expand mon=*/3' );
is_deeply( expand( "mon", "wday" ), [ 1 ], 'expand wday=mon' );
is_deeply( expand( "mon-fri", "wday" ), [ 1 .. 5 ], 'expand wday=mon-fri' );
is_deeply( expand( "4", "wday" ), [ 4 ], 'expand wday=4' );
is_deeply( expand( "5-7", "wday" ), [ 0, 5, 6 ], 'expand wday=5-7' );
is_deeply( expand( "thu-sun", "wday" ), [ 0, 4, 5, 6 ], 'expand wday=thu-sun' );
done_testing;
( run in 1.807 second using v1.01-cache-2.11-cpan-5b529ec07f3 )