فهرست منبع

use ISO_FORMAT* constants

(cherry picked from commit 457f5ceb30c1817556c1423ef42be4a63dee9ff1)
Thomas Waldmann 7 سال پیش
والد
کامیت
da30e54fc4
1فایلهای تغییر یافته به همراه3 افزوده شده و 5 حذف شده
  1. 3 5
      borg/helpers.py

+ 3 - 5
borg/helpers.py

@@ -314,7 +314,7 @@ class Manifest:
         if self.timestamp is None:
         if self.timestamp is None:
             self.timestamp = datetime.utcnow().isoformat()
             self.timestamp = datetime.utcnow().isoformat()
         else:
         else:
-            prev_ts = datetime.strptime(self.timestamp, "%Y-%m-%dT%H:%M:%S.%f")
+            prev_ts = datetime.strptime(self.timestamp, ISO_FORMAT)
             incremented = (prev_ts + timedelta(microseconds=1)).isoformat()
             incremented = (prev_ts + timedelta(microseconds=1)).isoformat()
             self.timestamp = max(incremented, datetime.utcnow().isoformat())
             self.timestamp = max(incremented, datetime.utcnow().isoformat())
         # include checks for limits as enforced by limited unpacker (used by load())
         # include checks for limits as enforced by limited unpacker (used by load())
@@ -493,10 +493,8 @@ def to_localtime(ts):
 
 
 def parse_timestamp(timestamp):
 def parse_timestamp(timestamp):
     """Parse a ISO 8601 timestamp string"""
     """Parse a ISO 8601 timestamp string"""
-    if '.' in timestamp:  # microseconds might not be present
-        return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f').replace(tzinfo=timezone.utc)
-    else:
-        return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S').replace(tzinfo=timezone.utc)
+    fmt = ISO_FORMAT if '.' in timestamp else ISO_FORMAT_NO_USECS
+    return datetime.strptime(timestamp, fmt).replace(tzinfo=timezone.utc)
 
 
 
 
 def load_excludes(fh):
 def load_excludes(fh):