--- a/utils.py Wed Feb 11 23:38:05 2009 +0200
+++ b/utils.py Thu Feb 12 00:16:52 2009 +0200
@@ -35,9 +35,12 @@
class URLDateType (URLType) :
"""
- Handle dates in URLs as naive datetime objects (with indeterminate time info)
+ Handle dates in URLs as shortened UTC datetime timestamps
"""
+ # percision = hour
+ SCALE = 60 * 60
+
def __init__ (self, date_fmt) :
"""
Format/parse dates using the given format
@@ -45,19 +48,27 @@
self.date_fmt = date_fmt
- def parse (self, date_str) :
+ def parse (self, sts_str) :
"""
- date_str -> naive datetime.datetime
+ short_timestamp_str -> datetime.datetime
"""
- return datetime.datetime.strptime(date_str, self.date_fmt)
+ # scale -> from_utc + return
+ return from_utc_timestamp(int(sts_str) * self.SCALE)
- def build (self, date) :
+ def build (self, dtz) :
"""
- datetime.date -> date_str
+ datetime.datetime -> short_timestamp_str
"""
- return date.strftime(self.date_fmt)
+ # force it to be interpreted as UTC
+ dt_utc = dtz.replace(tzinfo=pytz.utc)
+
+ # scale the UTC timestamp
+ sts = to_utc_timestamp(dt_utc) / self.SCALE
+
+ # str
+ return str(sts)
class URLTimestampType (URLType) :
"""