From: stefan Date: Mon, 23 Feb 2009 19:24:57 +0000 (+0000) Subject: Robustify Date.set. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d2f2c9ff47c1b90b5973e46109f9ef3d1dba024f;p=roundup.git Robustify Date.set. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4164 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/date.py b/roundup/date.py index 7daf952..f857bf7 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -295,7 +295,10 @@ class Date: info = m.groupdict() - # determine whether we need to add anything at the end + # If add_granularity is true, construct the maximum time given + # the precision of the input. For example, given the input + # "12:15", construct "12:15:59". Or, for "2008", construct + # "2008-12-31.23:59:59". if add_granularity: for gran in 'SMHdmy': if info[gran] is not None: @@ -308,6 +311,8 @@ class Date: else: add_granularity = Interval('+1%s'%gran) break + else: + raise ValueError(self._('Could not determine granularity')) # get the current date as our default dt = datetime.datetime.utcnow() diff --git a/test/test_dates.py b/test/test_dates.py index a8c79ea..0dd8251 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -37,7 +37,9 @@ class DateTestCase(unittest.TestCase): ae(str(date), '2000-02-29.00:00:00') date = Date("2001-02-27 + 2d") ae(str(date), '2001-03-01.00:00:00') - + date = Date("2009", add_granularity=True) + self.assertRaises(ValueError, Date, ". +30d", add_granularity=True) + def testDate(self): ae = self.assertEqual date = Date("2000-04-17")