This module is a very basic event module. Given parts of a datetime it can return the following, previous and closest datetime object.
The module was inspired by Ben Bennet who at 8:01 PM -0400 13/7/03, wrote:
I vote that you assume the next valid instance of the time (e.g. if they say 4 o'clock and it is 11 PM now, assume 4AM of the following day).
So this module does just that. Rather than finding the next 'easter' or 'sunset', this module finds the next valid datetime matching the parameters.
$seven_pm = DateTime::Event::DateTime->new(
hour => 19,
truncate => 'hour'
);
$dt = $seven_pm->following( datetime => DateTime-now() )
# Gets the next 7pm after now.The module can also be used non-OO:
$dt = previous(
datetime => DateTime->now(),
hour => 19
);
# Returns 19:59:59.999999999, which is the last valid DateTime with the hour '19'.
Because 'previous' returns results that may be unexpected, the truncate parameter exists.
Of course you could just:
$dt = previous(
datetime => DateTime->now(),
hour => 19
)->truncate( to => 'hour' );But adding the truncate allows us to subclass easily:
package DateTime::Event::DateTime::Christmas
use strict;
use DateTime::Event::DateTime;
use vars qw(@ISA);
@ISA = qw(DateTime::Event::DateTime);
sub new {
return $_[0]->SUPER::new(
day => 25,
month => 12,
truncate => 'day'
);
}So now we can:
$christmas = new DateTime::Event::DateTime::Christmas;
$next_christmas = $christmas->next()Note: All methods revert to DateTime->now() if they're not given a datetime parameter.
This module contains a free set of steak knives: - DateTime::Event::DateTime::Christmas - DateTime::Event::DateTime::NewYearsEve and will include extra steak knives upon release.
Will this be useful to anyone other than me?
Is there a better name?
Cheers! Rick
--
--------------------------------------------------------
There are 10 kinds of people:
those that understand binary, and those that don't.
--------------------------------------------------------
The day Microsoft makes something that doesn't suck
is the day they start selling vacuum cleaners
--------------------------------------------------------
"Write a wise proverb and your name will live forever."
-- Anonymous
--------------------------------------------------------
DateTime-Event-DateTime.tar.gz
Description: Binary data
