diff --git a/roundup/date.py b/roundup/date.py
index e7002aec0bec76fa258f4ef83c2263ee54b46996..372ddb2b4f0827ec5b16bec829dec45ad2d5e042 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
-# $Id: date.py,v 1.2 2001-07-22 12:09:32 richard Exp $
+# $Id: date.py,v 1.6 2001-07-31 09:54:18 richard Exp $
import time, re, calendar
'''
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
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):
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."""
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...
# 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)
+ # 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']))
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:
'''
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")
#
# $Log: not supported by cvs2svn $
+# Revision 1.5 2001/07/29 07:01:39 richard
+# Added vim command to all source so that we don't get no steenkin' tabs :)
+#
+# 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