Skip to content

Commit

Permalink
Calculate the array of month names, rather than using a static one th…
Browse files Browse the repository at this point in the history
…at has to be updated every month.
  • Loading branch information
iay committed Feb 14, 2011
1 parent 7f9d7c4 commit 429e1c5
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions charting/Months.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@
# Months.pm
#
use File::stat;
use Date::Manip::Date;
use Date::Manip::Delta;

@months = (
'2006-12',
'2007-01', '2007-02', '2007-03', '2007-04', '2007-05', '2007-06',
'2007-07', '2007-08', '2007-09', '2007-10', '2007-11', '2007-12',
'2008-01', '2008-02', '2008-03', '2008-04', '2008-05', '2008-06',
'2008-07', '2008-08', '2008-09', '2008-10', '2008-11', '2008-12',
'2009-01', '2009-02', '2009-03', '2009-04', '2009-05', '2009-06',
'2009-07', '2009-08', '2009-09', '2009-10', '2009-11', '2009-12',
'2010-01', '2010-02', '2010-03', '2010-04', '2010-05', '2010-06',
'2010-07', '2010-08', '2010-09', '2010-10', '2010-11', '2010-12',
'2011-01',
);
@months = ( );

$date = new Date::Manip::Date;
$date->parse_date('2006-12-01') && die('could not parse base date');

$now = new Date::Manip::Date;
$now->parse('today') && die('could not parse today');

$oneMonth = new Date::Manip::Delta;
$oneMonth->parse("1 month") && die('could not parse delta');

#
# Enumerate all month beginnings that have already happened, then stop.
#
while ($date->cmp($now) < 0) {
local $dateStr = $date->printf('%Y-%m');
# print "date string $dateStr\n";
push @months, $dateStr;

# move on one month
$date = $date->calc($oneMonth);
}

1;

0 comments on commit 429e1c5

Please sign in to comment.