mirror of https://github.com/borgbackup/borg.git
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
This commit is contained in:
parent
0295ef8563
commit
9f99aa1abf
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue