summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c0ee621)
raw | patch | inline | side by side (parent: c0ee621)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 13 Apr 2004 05:28:00 +0000 (05:28 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Tue, 13 Apr 2004 05:28:00 +0000 (05:28 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2282 57a73879-2fb5-44c3-a270-3262357dd7e2
CHANGES.txt | patch | blob | history | |
roundup/date.py | patch | blob | history |
diff --git a/CHANGES.txt b/CHANGES.txt
index e0d24b89171eb1eb074a1af5106b62c50bc6b676..377ed7e2c6b8b895571b1812b4f33cfc7038cb49 100644 (file)
--- a/CHANGES.txt
+++ b/CHANGES.txt
- 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 3d096d7df4186cd85aa3d1f2c729f65e2db5f697..286936856a1cb0066e44c228ccae6c3dcc011cb9 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
# 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):
'''
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:
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):
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)