Преглед на файлове

use safe parse_timestamp to parse timestamps, fixes #2994

also: refactor so it is possible to get tz-unaware datetime
objects from parse_timestamp.

(cherry picked from commit 7996a87357e4e67a833bcee5a54ef8b41c491518)
Thomas Waldmann преди 8 години
родител
ревизия
a9aa3c5f34
променени са 1 файла, в които са добавени 6 реда и са изтрити 3 реда
  1. 6 3
      src/borg/helpers.py

+ 6 - 3
src/borg/helpers.py

@@ -318,7 +318,7 @@ class Manifest:
 
 
     @property
     @property
     def last_timestamp(self):
     def last_timestamp(self):
-        return datetime.strptime(self.timestamp, ISO_FORMAT)
+        return parse_timestamp(self.timestamp, tzinfo=None)
 
 
     @classmethod
     @classmethod
     def load(cls, repository, operations, key=None, force_tam_not_required=False):
     def load(cls, repository, operations, key=None, force_tam_not_required=False):
@@ -523,10 +523,13 @@ def to_localtime(ts):
     return datetime(*time.localtime((ts - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds())[:6])
     return datetime(*time.localtime((ts - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds())[:6])
 
 
 
 
-def parse_timestamp(timestamp):
+def parse_timestamp(timestamp, tzinfo=timezone.utc):
     """Parse a ISO 8601 timestamp string"""
     """Parse a ISO 8601 timestamp string"""
     fmt = ISO_FORMAT if '.' in timestamp else ISO_FORMAT_NO_USECS
     fmt = ISO_FORMAT if '.' in timestamp else ISO_FORMAT_NO_USECS
-    return datetime.strptime(timestamp, fmt).replace(tzinfo=timezone.utc)
+    dt = datetime.strptime(timestamp, fmt)
+    if tzinfo is not None:
+        dt = dt.replace(tzinfo=tzinfo)
+    return dt
 
 
 
 
 def timestamp(s):
 def timestamp(s):