From: Sidnei da S. <dre...@us...> - 2004-09-16 13:46:18
|
Update of /cvsroot/collective/Calendaring/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2201/model Modified Files: __init__.py _cal.py day.py hour.py month.py week.py Log Message: Replace some nastyness by use of Gustavo Niemeyer's DateUtil module. Index: month.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/month.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- month.py 19 Jun 2004 14:53:33 -0000 1.1.1.1 +++ month.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -18,8 +18,9 @@ """ $Id$ """ -from datetime import timedelta -from Products.Calendaring.model import ModelView, registerView, SECOND + +from dateutil.relativedelta import relativedelta +from Products.Calendaring.model import ModelView, registerView, MONTH class OneMonthView(ModelView): @@ -36,6 +37,6 @@ _sub = 'month_view' name = 'three_months_view' _args = 2 - _leap = timedelta(56) + _leap = MONTH registerView(ThreeMonthsView) Index: hour.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/hour.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- hour.py 19 Jun 2004 14:53:33 -0000 1.1.1.1 +++ hour.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -18,7 +18,8 @@ """ $Id$ """ -from datetime import timedelta + +from dateutil.relativedelta import relativedelta from Products.Calendaring.model import ModelView, registerView, SECOND from Products.Calendaring.common import dt2DT from Products.CMFCore.utils import getToolByName @@ -30,7 +31,7 @@ _sub = 'hour_view' name = 'hour_view' _args = 4 - _leap = timedelta(minutes=59) + _leap = relativedelta(minutes=59) _skip = False registerView(OneHourView) Index: _cal.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/_cal.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- _cal.py 19 Jun 2004 14:53:33 -0000 1.1.1.1 +++ _cal.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -19,34 +19,36 @@ $Id$ """ import calendar +from dateutil.relativedelta import relativedelta from datetime import timedelta, datetime, date -WEEK = timedelta(days=7) -DAY = timedelta(days=1) -HOUR = timedelta(hours=1) -MONTH = timedelta(days=28) -YEAR = timedelta(days=365) -SECOND = timedelta(seconds=1) +WEEK = relativedelta(days=7) +WEEKDAY = relativedelta(days=5) +DAY = relativedelta(days=1) +HOUR = relativedelta(hours=1) +MONTH = relativedelta(months=1) +YEAR = relativedelta(years=1) +SECOND = relativedelta(seconds=1) def yearRange(dt): start = dt.replace(month=1, day=1, hour=0, minute=0, second=0) - end = dt.replace(month=12, day=31, hour=0, minute=0, second=0) + DAY - delta = end - start + end = start + YEAR + delta = YEAR return start, end, delta def monthRange(dt): start = dt.replace(day=1, hour=0, minute=0, second=0) - delta = timedelta(calendar.monthrange(start.year, start.month)[1]) + delta = MONTH end = start + delta return start, end, delta def threeMonthRange(dt): - previous = dt.replace(day=1) - MONTH + previous = dt - MONTH start = previous.replace(day=1, hour=0, minute=0, second=0) - next = dt.replace(day=28) + MONTH + next = dt + MONTH next = next.replace(day=1, hour=0, minute=0, second=0) end = next + timedelta(calendar.monthrange(next.year, next.month)[1]) - delta = end - start + delta = relativedelta(end, start) return start, end, delta def weekRange(dt): @@ -54,7 +56,7 @@ end = dt + timedelta(7 - dt.weekday()) start = start.replace(hour=0, minute=0, second=0) end = end.replace(hour=0, minute=0, second=0) - delta = end - start + delta = relativedelta(end, start) return start, end, delta def workdaysRange(dt): @@ -62,7 +64,7 @@ end = dt + timedelta(5 - dt.weekday()) start = start.replace(hour=0, minute=0, second=0) end = end.replace(hour=0, minute=0, second=0) - delta = end - start + delta = relativedelta(end, start) return start, end, delta def threeWeekRange(dt): @@ -70,7 +72,7 @@ end = (dt + timedelta(7 - dt.weekday())) + WEEK start = start.replace(hour=0, minute=0, second=0) end = end.replace(hour=0, minute=0, second=0) - delta = end - start + delta = relativedelta(end, start) return start, end, delta def dayRange(dt): Index: day.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/day.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- day.py 19 Jun 2004 14:53:33 -0000 1.1.1.1 +++ day.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -18,7 +18,8 @@ """ $Id$ """ -from datetime import timedelta + +from dateutil.relativedelta import relativedelta from Products.Calendaring.model import ModelView, registerView class OneDayView(ModelView): @@ -28,6 +29,6 @@ _sub = 'hour_view' name = 'day_view' _args = 3 - _leap = timedelta(0) + _leap = relativedelta(0) registerView(OneDayView) Index: week.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/week.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- week.py 19 Jun 2004 14:53:34 -0000 1.1.1.1 +++ week.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -18,8 +18,8 @@ """ $Id$ """ -from datetime import timedelta -from Products.Calendaring.model import ModelView, registerView, WEEK + +from Products.Calendaring.model import ModelView, registerView, WEEK, WEEKDAY from ComputedAttribute import ComputedAttribute class OneWeekView(ModelView): @@ -37,7 +37,7 @@ _sub = 'day_view' name = 'workdays_view' _args = 3 - _leap = timedelta(5) + _leap = WEEKDAY registerView(WorkdaysView) @@ -49,6 +49,6 @@ _sub = 'week_view' name = 'three_weeks_view' _args = 3 - _leap = timedelta(7) + _leap = WEEK registerView(ThreeWeeksView) Index: __init__.py =================================================================== RCS file: /cvsroot/collective/Calendaring/model/__init__.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- __init__.py 19 Jun 2004 14:53:32 -0000 1.1.1.1 +++ __init__.py 16 Sep 2004 13:46:09 -0000 1.2 @@ -18,7 +18,7 @@ """ $Id$ """ -from _cal import makeRange, DAY, WEEK, MONTH, YEAR, HOUR, SECOND +from _cal import makeRange, DAY, WEEKDAY, WEEK, MONTH, YEAR, HOUR, SECOND _views = {} |