From: richard Date: Sun, 14 Jul 2002 06:05:50 +0000 (+0000) Subject: . fixed the date module so that Date(". - 2d") works X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e0077935dd4b8819b95033a2caa925300ce3cb1c;p=roundup.git . fixed the date module so that Date(". - 2d") works git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@873 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/admin.py b/roundup/admin.py index e54ef7c..b8cfb84 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.16 2002-07-09 04:19:09 richard Exp $ +# $Id: admin.py,v 1.17 2002-07-14 06:05:50 richard Exp $ import sys, os, getpass, getopt, re, UserDict, shlex, shutil try: @@ -956,9 +956,7 @@ Date format is "YYYY-MM-DD" eg: raise ValueError, _('Invalid format') m = m.groupdict() if m['period']: - # TODO: need to fix date module. one should be able to say - # pack_before = date.Date(". - %s"%value) - pack_before = date.Date(".") + date.Interval("- %s"%value) + pack_before = date.Date(". - %s"%value) elif m['date']: pack_before = date.Date(value) self.db.pack(pack_before) @@ -1125,6 +1123,11 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.16 2002/07/09 04:19:09 richard +# Added reindex command to roundup-admin. +# Fixed reindex on first access. +# Also fixed reindexing of entries that change. +# # Revision 1.15 2002/06/17 23:14:44 richard # . #569415 ] {version} # diff --git a/roundup/date.py b/roundup/date.py index c40c4dc..94db02e 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: date.py,v 1.21 2002-05-15 06:32:46 richard Exp $ +# $Id: date.py,v 1.22 2002-07-14 06:05:50 richard Exp $ __doc__ = """ Date, time and time interval handling. @@ -91,29 +91,17 @@ class Date: self.year, self.month, self.day, self.hour, self.minute, \ self.second, x, x, x = time.gmtime(ts) - def applyInterval(self, interval): - ''' Apply the interval to this date + def addInterval(self, interval): + ''' Add the interval to this date, returning the date tuple ''' - t = (self.year + interval.year, - self.month + interval.month, - self.day + interval.day, - self.hour + interval.hour, - self.minute + interval.minute, - self.second + interval.second, 0, 0, 0) - self.year, self.month, self.day, self.hour, self.minute, \ - self.second, x, x, x = time.gmtime(calendar.timegm(t)) - - def __add__(self, other): - """Add an interval to this date to produce another date. - """ # do the basic calc - sign = other.sign - year = self.year + sign * other.year - month = self.month + sign * other.month - day = self.day + sign * other.day - hour = self.hour + sign * other.hour - minute = self.minute + sign * other.minute - second = self.second + sign * other.second + sign = interval.sign + year = self.year + sign * interval.year + month = self.month + sign * interval.month + day = self.day + sign * interval.day + hour = self.hour + sign * interval.hour + minute = self.minute + sign * interval.minute + second = self.second + sign * interval.second # now cope with under- and over-flow # first do the time @@ -148,8 +136,18 @@ class Date: # re-figure the number of days for this month if month == 2 and calendar.isleap(year): month_days = 29 else: month_days = mdays[month] + return (year, month, day, hour, minute, second, 0, 0, 0) - return Date((year, month, day, hour, minute, second, 0, 0, 0)) + def applyInterval(self, interval): + ''' Apply the interval to this date + ''' + self.year, self.month, self.day, self.hour, self.minute, \ + self.second, x, x, x = self.addInterval(interval) + + def __add__(self, interval): + """Add an interval to this date to produce another date. + """ + return Date(self.addInterval(interval)) # XXX deviates from spec to allow subtraction of dates as well def __sub__(self, other): @@ -440,6 +438,9 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.21 2002/05/15 06:32:46 richard +# . reverting to dates for intervals > 2 months sucks +# # Revision 1.20 2002/02/21 23:34:51 richard # Oops, there's 24 hours in a day, and subtraction of intervals now works # properly. diff --git a/test/test_dates.py b/test/test_dates.py index 14da7ec..942aa57 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_dates.py,v 1.11 2002-02-21 23:34:52 richard Exp $ +# $Id: test_dates.py,v 1.12 2002-07-14 06:05:50 richard Exp $ import unittest, time @@ -74,8 +74,12 @@ class DateTestCase(unittest.TestCase): # now check calculations date = Date('2000-01-01') + Interval('- 2y 2m') ae(str(date), '1997-11-01.00:00:00') + date = Date('2000-01-01 - 2y 2m') + ae(str(date), '1997-11-01.00:00:00') date = Date('2000-01-01') + Interval('2m') ae(str(date), '2000-03-01.00:00:00') + date = Date('2000-01-01 + 2m') + ae(str(date), '2000-03-01.00:00:00') date = Date('2000-01-01') + Interval('60d') ae(str(date), '2000-03-01.00:00:00') @@ -150,6 +154,10 @@ def suite(): # # $Log: not supported by cvs2svn $ +# Revision 1.11 2002/02/21 23:34:52 richard +# Oops, there's 24 hours in a day, and subtraction of intervals now works +# properly. +# # Revision 1.10 2002/02/21 23:11:45 richard # . fixed some problems in date calculations (calendar.py doesn't handle over- # and under-flow). Also, hour/minute/second intervals may now be more than