1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-23 06:31:58 +00:00

PR #283 - Merge branch 'fix-missing-microseconds' of https://github.com/camh-/attic into merge

This commit is contained in:
Thomas Waldmann 2015-04-15 03:06:50 +02:00
commit 2f71b39866
2 changed files with 30 additions and 3 deletions

View file

@ -169,8 +169,11 @@ def load(self, id):
@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

View file

@ -1,7 +1,10 @@
import msgpack
from attic.testsuite import AtticTestCase
from attic.archive import CacheChunkBuffer, RobustUnpacker
from attic.testsuite.mock import Mock
from attic.archive import Archive, CacheChunkBuffer, RobustUnpacker
from attic.key import PlaintextKey
from attic.helpers import Manifest
from datetime import datetime, timezone
class MockCache:
@ -14,6 +17,27 @@ def add_chunk(self, id, data, stats=None):
return id, len(data), len(data)
class ArchiveTimestampTestCase(AtticTestCase):
def _test_timestamp_parsing(self, isoformat, expected):
repository = Mock()
key = PlaintextKey()
manifest = Manifest(repository, key)
a = Archive(repository, key, manifest, 'test', create=True)
a.metadata = {b'time': isoformat}
self.assert_equal(a.ts, expected)
def test_with_microseconds(self):
self._test_timestamp_parsing(
'1970-01-01T00:00:01.000001',
datetime(1970, 1, 1, 0, 0, 1, 1, timezone.utc))
def test_without_microseconds(self):
self._test_timestamp_parsing(
'1970-01-01T00:00:01',
datetime(1970, 1, 1, 0, 0, 1, 0, timezone.utc))
class ChunkBufferTestCase(AtticTestCase):
def test(self):