diff --git a/charting/Months.pm b/charting/Months.pm index 3de08522..98c0712e 100755 --- a/charting/Months.pm +++ b/charting/Months.pm @@ -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;