]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/util/time_format.py
revert previous commit to fix attribution (vanity)
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / util / time_format.py
index e9b081f6de2eaee98abef75225e22eb1cbef0f7d..c481adc37fe734ed6f1896732ee57d71e3b2e049 100644 (file)
@@ -1,13 +1,10 @@
-#  Copyright (c) 2001 Autonomous Zone Industries
-#  Copyright (c) 2002-2007 Bryce "Zooko" Wilcox-O'Hearn
-#  This file is licensed under the
-#    GNU Lesser General Public License v2.1.
-#    See the file COPYING or visit http://www.gnu.org/ for details.
-
 # ISO-8601:
 # http://www.cl.cam.ac.uk/~mgk25/iso-time.html
 
-import datetime, re, time
+import calendar, datetime, re, time
+
+def format_time(t):
+    return time.strftime("%Y-%m-%d %H:%M:%S", t)
 
 def iso_utc_date(now=None, t=time.time):
     if now is None:
@@ -19,11 +16,6 @@ def iso_utc(now=None, sep='_', t=time.time):
         now = t()
     return datetime.datetime.utcfromtimestamp(now).isoformat(sep)
 
-def iso_local(now=None, sep='_', t=time.time):
-    if now is None:
-        now = t()
-    return datetime.datetime.fromtimestamp(now).isoformat(sep)
-
 def iso_utc_time_to_seconds(isotime, _conversion_re=re.compile(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})[T_ ](?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})(?P<subsecond>\.\d+)?")):
     """
     The inverse of iso_utc().
@@ -42,16 +34,7 @@ def iso_utc_time_to_seconds(isotime, _conversion_re=re.compile(r"(?P<year>\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