From: richard Date: Tue, 13 Apr 2004 05:28:00 +0000 (+0000) Subject: stop Interval from displaying an empty string (sf bug 934022) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=39cdf5643c8a5db95d124b3306dd4805b85a1d89;p=roundup.git stop Interval from displaying an empty string (sf bug 934022) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2282 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index e0d24b8..377ed7e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -29,6 +29,7 @@ Fixed: - roundup scripts may now be asked for their version (sf rfe 798657) - sqlite backend had stopped using the global lock - better check for anonymous viewing of user items (sf bug 933510) +- stop Interval from displaying an empty string (sf bug 934022) 2004-03-27 0.7.0b2 diff --git a/roundup/date.py b/roundup/date.py index 3d096d7..2869368 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -15,13 +15,14 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: date.py,v 1.65 2004-04-06 22:43:59 richard Exp $ +# $Id: date.py,v 1.66 2004-04-13 05:28:00 richard Exp $ """Date, time and time interval handling. """ __docformat__ = 'restructuredtext' import time, re, calendar, types +from types import * from i18n import _ def _add_granularity(src, order, value = 1): @@ -433,7 +434,9 @@ class Interval: ''' def __init__(self, spec, sign=1, allowdate=1, add_granularity=0): """Construct an interval given a specification.""" - if type(spec) == type(''): + if type(spec) in (IntType, FloatType, LongType): + self.from_seconds(spec) + elif type(spec) in (StringType, UnicodeType): self.set(spec, allowdate=allowdate, add_granularity=add_granularity) else: if len(spec) == 7: @@ -533,6 +536,8 @@ class Interval: l.append('%d:%02d'%(self.hour, self.minute)) if l: l.insert(0, {1:'+', -1:'-'}[self.sign]) + else: + l.append('00:00') return ' '.join(l) def __add__(self, other): @@ -680,6 +685,42 @@ class Interval: return '%s%04d%02d%02d%02d%02d%02d'%(sign, self.year, self.month, self.day, self.hour, self.minute, self.second) + def as_seconds(self): + '''Calculate the Interval as a number of seconds. + + Months are counted as 30 days, years as 365 days. Returns a Long + int. + ''' + n = self.year * 365L + n = n + self.month * 30 + n = n + self.day + n = n * 24 + n = n + self.hour + n = n * 60 + n = n + self.minute + n = n * 60 + n = n + self.second + return n * self.sign + + def from_seconds(self, val): + '''Figure my second, minute, hour and day values using a seconds + value. + ''' + if val < 0: + self.sign = -1 + val = -val + else: + self.sign = 1 + self.second = val % 60 + val = val / 60 + self.minute = val % 60 + val = val / 60 + self.hour = val % 24 + val = val / 24 + self.day = val + self.month = self.year = 0 + + def fixTimeOverflow(time): """ Handle the overflow in the time portion (H, M, S) of "time": (sign, y,m,d,H,M,S)