Skip to content

Commit 3ee946e

Browse files
author
Richard Jones
committed
Fixed offset handling (shoulda read the spec a little better)
1 parent 13edf10 commit 3ee946e

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

roundup/date.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: date.py,v 1.3 2001-07-23 07:56:05 richard Exp $
1+
# $Id: date.py,v 1.4 2001-07-25 04:09:34 richard Exp $
22

33
import time, re, calendar
44

@@ -66,9 +66,10 @@ def __init__(self, spec='.', offset=0):
6666
if type(spec) == type(''):
6767
self.set(spec, offset=offset)
6868
else:
69+
y,m,d,H,M,S,x,x,x = spec
70+
ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0))
6971
self.year, self.month, self.day, self.hour, self.minute, \
70-
self.second, x, x, x = spec
71-
self.offset = offset
72+
self.second, x, x, x = time.gmtime(ts)
7273

7374
def applyInterval(self, interval):
7475
''' Apply the interval to this date
@@ -139,8 +140,8 @@ def __cmp__(self, other):
139140

140141
def __str__(self):
141142
"""Return this date as a string in the yyyy-mm-dd.hh:mm:ss format."""
142-
return time.strftime('%Y-%m-%d.%T', (self.year, self.month,
143-
self.day, self.hour, self.minute, self.second, 0, 0, 0))
143+
return time.strftime('%Y-%m-%d.%T', (self.year, self.month, self.day,
144+
self.hour, self.minute, self.second, 0, 0, 0))
144145

145146
def pretty(self):
146147
''' print up the date date using a pretty format...
@@ -162,23 +163,26 @@ def set(self, spec, offset=0, date_re=re.compile(r'''
162163
info = m.groupdict()
163164

164165
# get the current date/time using the offset
165-
y,m,d,H,M,S,x,x,x = time.gmtime(time.time())
166-
ts = calendar.timegm((y,m,d,H+offset,M,S,0,0,0))
167-
self.year, self.month, self.day, self.hour, self.minute, \
168-
self.second, x, x, x = time.gmtime(ts)
166+
y,m,d,H,M,S,x,x,x = time.gmtime()
169167

168+
# override year, month, day parts
170169
if info['m'] is not None and info['d'] is not None:
171-
self.month = int(info['m'])
172-
self.day = int(info['d'])
173-
if info['y'] is not None:
174-
self.year = int(info['y'])
175-
self.hour = self.minute = self.second = 0
170+
m = int(info['m'])
171+
d = int(info['d'])
172+
if info['y'] is not None: y = int(info['y'])
173+
H = M = S = 0
176174

175+
# override hour, minute, second parts
177176
if info['H'] is not None and info['M'] is not None:
178-
self.hour = int(info['H'])
179-
self.minute = int(info['M'])
180-
if info['S'] is not None:
181-
self.second = int(info['S'])
177+
H = int(info['H']) - offset
178+
M = int(info['M'])
179+
S = 0
180+
if info['S'] is not None: S = int(info['S'])
181+
182+
# now handle the adjustment of hour
183+
ts = calendar.timegm((y,m,d,H,M,S,0,0,0))
184+
self.year, self.month, self.day, self.hour, self.minute, \
185+
self.second, x, x, x = time.gmtime(ts)
182186

183187
if info['o']:
184188
self.applyInterval(Interval(info['o']))
@@ -351,6 +355,9 @@ def test():
351355

352356
#
353357
# $Log: not supported by cvs2svn $
358+
# Revision 1.3 2001/07/23 07:56:05 richard
359+
# Storing only marshallable data in the db - no nasty pickled class references.
360+
#
354361
# Revision 1.2 2001/07/22 12:09:32 richard
355362
# Final commit of Grande Splite
356363
#

0 commit comments

Comments
 (0)