[Zope-CVS] CVS: Packages/TestScripts - summarizer.py:1.4
Steve Alexander
steve at cat-box.net
Sun Jan 4 12:32:34 EST 2004
Update of /cvs-repository/Packages/TestScripts
In directory cvs.zope.org:/tmp/cvs-serv22156
Modified Files:
summarizer.py
Log Message:
Fixed bug in calculating the year and month of the previous month.
=== Packages/TestScripts/summarizer.py 1.3 => 1.4 ===
--- Packages/TestScripts/summarizer.py:1.3 Mon Dec 22 12:07:39 2003
+++ Packages/TestScripts/summarizer.py Sun Jan 4 12:32:33 2004
@@ -167,6 +167,18 @@
subject, fromaddr = subjects[0]
return Message(url, datetext, subject, fromaddr)
+def monthMinusOne(year, month):
+ """Takes a year and a 1-based month.
+
+ Returns as a two-tuple (year, month) the year and 1-based month of
+ the previous month.
+ """
+ if not (1 <= month <= 12):
+ raise ValueError, month
+ months = year * 12 + month - 1
+ y, m = divmod(months - 1, 12)
+ return y, m + 1
+
def main():
"""Do the work!
@@ -177,7 +189,7 @@
now = datetime.datetime.utcnow()
this_month_urls = get_archive(now.year, now.month)
- last_month_year, last_month = divmod((now.year * 12 + now.month) - 1, 12)
+ last_month_year, last_month = monthMinusOne(now.year, now.month)
last_month_urls = get_archive(last_month_year, last_month)
# urls is a list of urls for this month an last month, most recent first.
More information about the Zope-CVS
mailing list