DateTimeX::Duration::SkipDays - Given a starting date, a number of days and a list of days to be skipped, returns the date X number of days away.
version 0.002
#!/usr/bin/perl use strict; use warnings; use DateTime; use DateTimeX::Duration::SkipDays; my $skip_days = q( Christmas Christmas Eve RRULE:FREQ=WEEKLY;BYDAY=SA,SU ); my $skip_x_days = 30; my $start_date = DateTime->new( 'year' => 2011, 'month' => 12, 'day' => 1 ); my $s = DateTimeX::Duration::SkipDays->new({ 'parse_dates' => $skip_days, 'start_date' => $start_date, }); my ( $span, $skipped ) = $s->add( $skip_x_days ); printf "\nCalculated Start: %s\nCalculated End: %s\n", $span->start->ymd, $span->end->ymd; my $iter = $skipped->iterator; while ( my $dt = $iter->next ) { printf "\nSkipped: %s", $dt->min->ymd; } if ( @{ $s->bad_format } ) { print "\n\nUnrecognized formats:"; print "\n\t$_" for @{ $s->bad_format }; } # should output # Calculated Start: 2011-12-01 # Calculated End: 2012-01-12 # Skipped: 2011-12-03 # Skipped: 2011-12-04 # Skipped: 2011-12-10 # Skipped: 2011-12-11 # Skipped: 2011-12-17 # Skipped: 2011-12-18 # Skipped: 2011-12-24 # Skipped: 2011-12-25 # Skipped: 2011-12-31 # Skipped: 2012-01-01 # Skipped: 2012-01-07 # Skipped: 2012-01-08
With no arguments an empty object is returned.
This method will croak if a non-hash reference is passed to it.
The possible keys for the constructor are any of the available methods below, except for add. The add method must be called explicitly. Unknown keys will be silently ignored.
add
The values have the same requirement as the matching methods.
Returns a DateTimeX::Duration::SkipDays object.
DateTimeX::Duration::SkipDays
start_date is expecting a DateTime object. This will be used as the starting point for calculations.
start_date
Returns true on success.
days_to_skip accepts any object, or array of objects that will be added to the current list of days to be skipped.
days_to_skip
Currently, DateTime, DateTime::Span, DateTime::Set, DateTime::Set::ICal and DateTime::SpanSet are known to work. Anything that can be used with DateTime::Set's union method should work.
Returns true on success
parse_dates is expecting a scalar that has a newline separated list of dates. The text can contain any of the following:
parse_dates
Returns true on success or false on failure.
Any line that is not recognized is silently ignored. Check bad_format for a list of unknown formats.
bad_format
Returns a reference to an array of unrecognized formats.
add expects a single integer greater than or equal to 0 (though 0 would be kind of useless).
This is the number of days into the future you are looking for.
The start_date and days_to_skip values need to have been populated or this method will croak.
In array context a reference to a DateTime::Span object and a DateTime::SpanSet object is returned, otherwise a reference to a hash with those objects as values is returned.
See perlmodinstall for information and options on installing Perl modules.
Alan Young <harleypig@gmail.com>
This software is copyright (c) 2012 by Alan Young.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DateTimeX::Duration::SkipDays, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTimeX::Duration::SkipDays
CPAN shell
perl -MCPAN -e shell install DateTimeX::Duration::SkipDays
For more information on module installation, please visit the detailed CPAN module installation guide.