commit ddda393f3d62cf234655ae3cca9769403491fb70 Author: Arturo Filastò art@fuffa.org Date: Fri Oct 17 17:37:53 2014 +0200
Fix time conversions to be all be in UTC --- ooni/otime.py | 17 +++++++++++++++-- ooni/tests/test_utils.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/ooni/otime.py b/ooni/otime.py index 60725c3..1406fbf 100644 --- a/ooni/otime.py +++ b/ooni/otime.py @@ -1,4 +1,17 @@ -from datetime import datetime +from datetime import datetime, timedelta, tzinfo + +class UTC(tzinfo): + """UTC""" + ZERO = timedelta(0) + + def utcoffset(self, dt): + return self.ZERO + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return self.ZERO
def prettyDateNow(): """ @@ -67,7 +80,7 @@ def timestamp(t=None):
def epochToTimestamp(seconds): - return timestamp(datetime.fromtimestamp(seconds)) + return timestamp(datetime.fromtimestamp(seconds, UTC()))
def epochToUTC(seconds): diff --git a/ooni/tests/test_utils.py b/ooni/tests/test_utils.py index 829ba90..be5d578 100644 --- a/ooni/tests/test_utils.py +++ b/ooni/tests/test_utils.py @@ -8,7 +8,7 @@ class TestUtils(unittest.TestCase): def setUp(self): self.test_details = { 'test_name': 'foo', - 'start_time': 441759600 + 'start_time': 441763200 } self.extension = 'ext' self.prefix = 'prefix'
tor-commits@lists.torproject.org