--- a/utils.py Mon Feb 09 14:07:19 2009 +0200
+++ b/utils.py Mon Feb 09 22:17:10 2009 +0200
@@ -2,7 +2,7 @@
Miscellaneous things
"""
-import datetime
+import datetime, calendar, pytz
from qmsk.web.urltree import URLType
@@ -58,3 +58,22 @@
return date.strftime(self.date_fmt)
+class URLTimestampType (URLType) :
+ """
+ Handles an integer UNIX timestamp as an UTC datetime
+ """
+
+ def parse (self, timestamp_str) :
+ """
+ timestamp_str -> pytz.utc datetime.datetime
+ """
+
+ return datetime.datetime.utcfromtimestamp(int(timestamp_str)).replace(tzinfo=pytz.utc)
+
+ def build (self, dtz) :
+ """
+ pytz.utc datetime.datetime -> timestamp_str
+ """
+
+ return str(calendar.timegm(dtz.utctimetuple()))
+