From 9f99aa1abfa265b562f2874b92ca6d2269bed12b Mon Sep 17 00:00:00 2001 From: Cam Hutchison Date: Mon, 6 Apr 2015 22:17:38 +1000 Subject: [PATCH] archive: Fix parsing with missing microseconds. Archive timestamps are stored as the output of datetime.isoformat(). This function omits microseconds in the string output if the microseconds are zero (as documented and explained at https://bugs.python.org/issue7342). Parsing of timestamps assumes there are always microseconds present after a decimal point. This is not always true. Handle this case where it is not true by explicitly using '0' microseconds when not present. This commit fixes #282 --- attic/archive.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/attic/archive.py b/attic/archive.py index d78ce4b85..df789ac24 100644 --- a/attic/archive.py +++ b/attic/archive.py @@ -163,8 +163,11 @@ class Archive: @property def ts(self): """Timestamp of archive creation in UTC""" - t, f = self.metadata[b'time'].split('.', 1) - return datetime.strptime(t, '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) + timedelta(seconds=float('.' + f)) + t = self.metadata[b'time'].split('.', 1) + dt = datetime.strptime(t[0], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc) + if len(t) > 1: + dt += timedelta(seconds=float('.' + t[1])) + return dt def __repr__(self): return 'Archive(%r)' % self.name