Algorithm-Cron
view release on metacpan or search on metacpan
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
base => 'local',
min => 0,
hour => 9,
wday => "mon-fri",
);
A `crontab' field containing a single asterisk (`*'), or a missing named
field, indicates that any value here is included in the scheduled times.
To restrict the schedule, a value or set of values can be provided. This
should consist of one or more comma-separated numbers or ranges, where a
range is given as the start and end points, both inclusive.
hour => "3-6"
hour => "3,4,5,6"
Ranges can also be prefixed by a value to give the increment for values
in that range.
min => "*/10"
min => "0,10,20,30,40,50"
@months = $cron->mon
@wdays = $cron->wday
Accessors that return a list of the accepted values for each scheduling
field. These are returned in a plain list of numbers, regardless of the
form they were specified to the constructor.
Also note that the list of valid months will be 0-based (in the range 0
to 11) rather than 1-based, to match the values used by `localtime',
`gmtime', `mktime' and `timegm'.
$time = $cron->next_time( $start_time )
Returns the next scheduled time, as an epoch timestamp, after the given
timestamp. This is a stateless operation; it does not change any state
stored by the `$cron' object.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
lib/Algorithm/Cron.pm view on Meta::CPAN
base => 'local',
min => 0,
hour => 9,
wday => "mon-fri",
);
A C<crontab> field containing a single asterisk (C<*>), or a missing named
field, indicates that any value here is included in the scheduled times. To
restrict the schedule, a value or set of values can be provided. This should
consist of one or more comma-separated numbers or ranges, where a range is
given as the start and end points, both inclusive.
hour => "3-6"
hour => "3,4,5,6"
Ranges can also be prefixed by a value to give the increment for values in
that range.
min => "*/10"
min => "0,10,20,30,40,50"
lib/Algorithm/Cron.pm view on Meta::CPAN
provided it will default to C<0>. If six fields are provided, the first gives
the seconds.
=head2 Time Base
C<Algorithm::Cron> supports using either UTC or the local timezone when
comparing against the given schedule.
=cut
# mday field starts at 1, others start at 0
my %MIN = (
sec => 0,
min => 0,
hour => 0,
mday => 1,
mon => 0
);
# These don't have to be real maxima, as the algorithm will cope. These are
# just the top end of the range expansions
lib/Algorithm/Cron.pm view on Meta::CPAN
$t->[TM_MDAY] = 1;
@$t = $funcs->[NORMALISE]->( @$t );
return 0;
}
return 1;
}
=head2 $time = $cron->next_time( $start_time )
Returns the next scheduled time, as an epoch timestamp, after the given
timestamp. This is a stateless operation; it does not change any state stored
by the C<$cron> object.
=cut
sub next_time
{
my $self = shift;
lib/Algorithm/Cron.pm view on Meta::CPAN
my @t = $funcs->[EXTRACT]->( $time + 1 );
RESTART:
$self->next_time_field( \@t, TM_MON ) or goto RESTART;
if( defined $self->{mday} and defined $self->{wday} ) {
# Now it gets tricky because cron allows a match of -either- mday or wday
# rather than requiring both. So we'll work out which of the two is sooner
my $next_time_by_wday;
my @wday_t = @t;
my $wday_restart = 0;
$self->next_time_field( \@wday_t, TM_WDAY ) or $wday_restart = 1;
$next_time_by_wday = $funcs->[BUILD]->( @wday_t );
my $next_time_by_mday;
my @mday_t = @t;
my $mday_restart = 0;
$self->next_time_field( \@mday_t, TM_MDAY ) or $mday_restart = 1;
$next_time_by_mday = $funcs->[BUILD]->( @mday_t );
if( $next_time_by_wday > $next_time_by_mday ) {
@t = @mday_t;
goto RESTART if $mday_restart;
}
else {
@t = @wday_t;
goto RESTART if $wday_restart;
}
}
elsif( defined $self->{mday} ) {
$self->next_time_field( \@t, TM_MDAY ) or goto RESTART;
}
elsif( defined $self->{wday} ) {
$self->next_time_field( \@t, TM_WDAY ) or goto RESTART;
}
foreach my $idx ( TM_HOUR, TM_MIN, TM_SEC ) {
( run in 0.458 second using v1.01-cache-2.11-cpan-0d8aa00de5b )