NAME
DateTime::Span::Common - create common DateTime::Span instances
VERSION
Version 0.01
SYNOPSIS
use DateTime::Span::Common;
my $x = DateTime::Span::Common->new;
my $dts = $x->today;
$dts = $x->yesterday;
$dts = $x->this_week;
$dts = $x->last_week;
$dts = $x->this_month;
$dts = $x->last_month;
$dts = $x->year_to_date;
$dts = $x->last_year;
my $sth = $dbh->prepare('SELECT * FROM table WHERE order_date BETWEEN ? AND ?');
$sth->execute($dts->datetimes);
DESCRIPTION
DateTime::Span::Common is a module which provides a DateTime::Span object for a number of common date spans. It also provides a few convenience methods which I found useful in developing this module.
METHODS
new
When constructing a DateTime::Span::Common object, you may change the day on which the week is presumed to start from Sunday to any other day in the week:
my $dtsc = DateTime::Span::Common->new(week_start_day => 'Monday');
today
Returns a DateTime::Span object covering the current day.
yesterday
Returns a DateTime::Span object covering yesterday.
this_week
Returns a DateTime::Span object covering this week, respective of $self->week_start_day
.
last_week
Returns a DateTime::Span object covering last week, respective of $self->week_start_day
.
this_month
Returns a DateTime::Span object covering this month to date.
this_year
Returns a DateTime::Span object covering this year to date.
last_year
Returns a DateTime::Span object covering last year to date.
Internal Methods
set_eod
This method is used for end of day calculations. It sets a DateTime object's day, minute, and second fields by default. You can override it for your own purposes in your subclass as necessary.
DateTime::Span::datetimes
The public methods of this module return a Datetime::Span instance. Oftentimes you will want the start and end of the span in an array. This method gives it to you:
my $datetime_span = DateTime::Span::Common->new->this_year;
my $sth = $dbh->prepare('SELECT * FROM table WHERE order_date BETWEEN ? AND ?');
$sth->execute($datetime_span->datetimes);
DateTime::Span::from_array
This method creates a DateTime::Span instance from an array:
my @data = some_api_result();
my $dts = DateTime::Span->from_array(@data);
AUTHOR
Terrence Brannon, <metaperl at gmail.com>
BUGS
Please report any bugs or feature requests to bug-datetime-span-common at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime-Span-Common. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DateTime::Span::Common
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DateTime-Span-Common
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Terrence Brannon, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.