summarylogtreecommitdiffstats
path: root/0001-Fix-timezone-for-Russia-Co-905.patch
blob: e55bfe11ca41b0cc46b69972a9560e58e48ad4ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From 699966d29bc497b3bdc7aa20aefb00f77c68d665 Mon Sep 17 00:00:00 2001
From: Eric L <ericzolf@users.noreply.github.com>
Date: Thu, 20 Jul 2023 19:59:42 +0200
Subject: [PATCH] Fix timezone for Russia & Co (#905)

FIX: timezone was not always correctly calculated in countries with historically changing DST, closes #902
---
 src/rdiff_backup/Time.py | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/rdiff_backup/Time.py b/src/rdiff_backup/Time.py
index ba33cd3..a929d30 100644
--- a/src/rdiff_backup/Time.py
+++ b/src/rdiff_backup/Time.py
@@ -314,28 +314,15 @@ def _get_tzd(timeinseconds=None):
     """
     if timeinseconds is None:
         timeinseconds = time.time()
-    dst_in_effect = time.daylight and time.localtime(timeinseconds)[8]
-    if dst_in_effect:
-        offset = -time.altzone / 60
-    else:
-        offset = -time.timezone / 60
-    if offset > 0:
-        prefix = "+"
-    elif offset < 0:
-        prefix = "-"
-    else:
-        return "Z"  # time is already in UTC
-
+    tzd = time.strftime("%z", time.localtime(timeinseconds))
     if Globals.use_compatible_timestamps:
         time_separator = '-'
     else:
         time_separator = ':'
-    hours, minutes = list(map(abs, divmod(offset, 60)))
-    assert 0 <= hours <= 23, (
-        "Hours {hrs} must be between 0 and 23".format(hrs=hours))
-    assert 0 <= minutes <= 59, (
-        "Minutes {mins} must be between 0 and 59".format(mins=minutes))
-    return "%s%02d%s%02d" % (prefix, hours, time_separator, minutes)
+    if tzd == "+0000":
+        return "Z"
+    else:
+        return tzd[:3] + time_separator + tzd[3:]
 
 
 def _tzd_to_seconds(tzd):
-- 
2.41.0