Created
January 11, 2010 19:18
-
-
Save theory/274497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%args> | |
$asset => $story | |
</%args> | |
<%init>; | |
# Get the month and year. | |
my $month = $asset->get_cover_date("%m"); | |
my $year = $asset->get_cover_date("%Y"); | |
# Construct the date for the first of the month. | |
my $start = "$year-$month-01 00:00:00"; | |
# Increment to the beginning of next month. | |
if (++$month == 13) { | |
# Whoops, it's next year. | |
$month = '01'; | |
$year++; | |
} else { | |
# Make sure the month has a leading 0. | |
$month = "0$month" if length $month == 1; | |
} | |
# Return the dates for the beginning of the month and the beginning of the | |
# next month. | |
return ($start, "$year-$month-01 00:00:00"); | |
</%init> | |
<%doc> | |
=head1 NAME | |
/util/month_span_dates.mc - Returns the dates for the beginning and end of a month | |
=head1 SYNOPSIS | |
my ($start, $end) = $m->comp( '/util/month_span_dates.mc', asset => $asset ); | |
=head1 DESCRIPTION | |
Returns the date for the first day of the cover date month and the first day | |
of the following month to represent the span of the cover date month. The | |
cover date is pulled from the C<asset> parameter. If the C<asset> parameter is | |
not passed, then it defaults to the global C<$story> object. | |
This utility template is useful for getting a list of stories with dates | |
within the span of a single month. | |
=head1 AUTHOR | |
David Wheeler <[email protected]> | |
=cut | |
</%doc> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment