X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=roundup%2Fdate.py;h=fae7fbbc3492d95e738f4151409a2242187b31c8;hb=a1338c6eb3833d03c2ea4e43ec51e9626eb58e2f;hp=e7002aec0bec76fa258f4ef83c2263ee54b46996;hpb=9af8ac2feb15e0b28d547b7bf0af9103376a5210;p=roundup.git diff --git a/roundup/date.py b/roundup/date.py index e7002ae..fae7fbb 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -1,4 +1,4 @@ -# $Id: date.py,v 1.2 2001-07-22 12:09:32 richard Exp $ +# $Id: date.py,v 1.5 2001-07-29 07:01:39 richard Exp $ import time, re, calendar @@ -56,19 +56,20 @@ class Date: ''' isDate = 1 - def __init__(self, spec='.', offset=0, set=None): + def __init__(self, spec='.', offset=0): """Construct a date given a specification and a time zone offset. 'spec' is a full date or a partial form, with an optional - added or subtracted interval. + added or subtracted interval. Or a date 9-tuple. 'offset' is the local time zone offset from GMT in hours. """ - if set is None: + if type(spec) == type(''): self.set(spec, offset=offset) else: + y,m,d,H,M,S,x,x,x = spec + ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0)) self.year, self.month, self.day, self.hour, self.minute, \ - self.second, x, x, x = set - self.offset = offset + self.second, x, x, x = time.gmtime(ts) def applyInterval(self, interval): ''' Apply the interval to this date @@ -90,7 +91,7 @@ class Date: self.hour + other.sign * other.hour, self.minute + other.sign * other.minute, self.second + other.sign * other.second, 0, 0, 0) - return Date(set = time.gmtime(calendar.timegm(t))) + return Date(time.gmtime(calendar.timegm(t))) # XXX deviates from spec to allow subtraction of dates as well def __sub__(self, other): @@ -128,7 +129,7 @@ class Date: self.hour - other.sign * other.hour, self.minute - other.sign * other.minute, self.second - other.sign * other.second, 0, 0, 0) - return Date(set = time.gmtime(calendar.timegm(t))) + return Date(time.gmtime(calendar.timegm(t))) def __cmp__(self, other): """Compare this date to another date.""" @@ -139,8 +140,8 @@ class Date: def __str__(self): """Return this date as a string in the yyyy-mm-dd.hh:mm:ss format.""" - return time.strftime('%Y-%m-%d.%T', (self.year, self.month, - self.day, self.hour, self.minute, self.second, 0, 0, 0)) + return time.strftime('%Y-%m-%d.%T', (self.year, self.month, self.day, + self.hour, self.minute, self.second, 0, 0, 0)) def pretty(self): ''' print up the date date using a pretty format... @@ -162,23 +163,26 @@ class Date: info = m.groupdict() # get the current date/time using the offset - y,m,d,H,M,S,x,x,x = time.gmtime(time.time()) - ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0)) - self.year, self.month, self.day, self.hour, self.minute, \ - self.second, x, x, x = time.gmtime(ts) + y,m,d,H,M,S,x,x,x = time.gmtime() + # override year, month, day parts if info['m'] is not None and info['d'] is not None: - self.month = int(info['m']) - self.day = int(info['d']) - if info['y'] is not None: - self.year = int(info['y']) - self.hour = self.minute = self.second = 0 + m = int(info['m']) + d = int(info['d']) + if info['y'] is not None: y = int(info['y']) + H = M = S = 0 + # override hour, minute, second parts if info['H'] is not None and info['M'] is not None: - self.hour = int(info['H']) - self.minute = int(info['M']) - if info['S'] is not None: - self.second = int(info['S']) + H = int(info['H']) - offset + M = int(info['M']) + S = 0 + if info['S'] is not None: S = int(info['S']) + + # now handle the adjustment of hour + ts = calendar.timegm((y,m,d,H,M,S,0,0,0)) + self.year, self.month, self.day, self.hour, self.minute, \ + self.second, x, x, x = time.gmtime(ts) if info['o']: self.applyInterval(Interval(info['o'])) @@ -193,6 +197,9 @@ class Date: self.year, self.month, self.day, self.hour, self.minute, \ self.second, x, x, x = time.gmtime(calendar.timegm(t)) + def get_tuple(self): + return (self.year, self.month, self.day, self.hour, self.minute, + self.second, 0, 0, 0) class Interval: ''' @@ -321,6 +328,10 @@ class Interval: return '1/2 an hour' return '%s/4 hour'%quart + def get_tuple(self): + return (self.year, self.month, self.day, self.hour, self.minute, + self.second) + def test(): intervals = (" 3w 1 d 2:00", " + 2d", "3w") @@ -344,6 +355,17 @@ if __name__ == '__main__': # # $Log: not supported by cvs2svn $ +# Revision 1.4 2001/07/25 04:09:34 richard +# Fixed offset handling (shoulda read the spec a little better) +# +# Revision 1.3 2001/07/23 07:56:05 richard +# Storing only marshallable data in the db - no nasty pickled class references. +# +# Revision 1.2 2001/07/22 12:09:32 richard +# Final commit of Grande Splite +# # Revision 1.1 2001/07/22 11:58:35 richard # More Grande Splite # +# +# vim: set filetype=python ts=4 sw=4 et si