From cc2953e6632d6efb9d79c002d791bfbf56f17eae Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Sat, 13 Jun 2009 09:01:12 -0700 Subject: [PATCH] util: hooray! A clean implementation of this simple utility! Black Dew pointed out that the inverse of time.gmtime() is hidden in the "calendar" module. --- src/allmydata/util/time_format.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/allmydata/util/time_format.py b/src/allmydata/util/time_format.py index e9b081f6..97d7c034 100644 --- a/src/allmydata/util/time_format.py +++ b/src/allmydata/util/time_format.py @@ -7,7 +7,7 @@ # ISO-8601: # http://www.cl.cam.ac.uk/~mgk25/iso-time.html -import datetime, re, time +import calendar, datetime, re, time def iso_utc_date(now=None, t=time.time): if now is None: @@ -42,16 +42,7 @@ def iso_utc_time_to_seconds(isotime, _conversion_re=re.compile(r"(?P\d{4}) else: subsecfloat = 0 - # Brian's hack to figure out the offset from localtime to UTC. - localseconds = time.mktime( (year, month, day, hour, minute, second, 0, 1, 0) ) - asifutcstr = iso_utc(localseconds) - asifm = _conversion_re.match(asifutcstr) - asifyear, asifmonth, asifday = int(asifm.group('year')), int(asifm.group('month')), int(asifm.group('day')) - asifhour, asifminute, asifsecond = int(asifm.group('hour')), int(asifm.group('minute')), int(asifm.group('second')) - asifutcsecs = time.mktime( (asifyear, asifmonth, asifday, asifhour, asifminute, asifsecond, 0, 1, 0) ) - offset = asifutcsecs - localseconds - - return localseconds - offset + subsecfloat + return calendar.timegm( (year, month, day, hour, minute, second, 0, 1, 0) ) + subsecfloat def parse_duration(s): orig = s -- 2.45.2