Merge lp:~fgallaire/bzr/fix-localtime into lp:bzr

Proposed by Florent Gallaire
Status: Needs review
Proposed branch: lp:~fgallaire/bzr/fix-localtime
Merge into: lp:bzr
Diff against target: 79 lines (+34/-5)
3 files modified
bzrlib/osutils.py (+19/-5)
bzrlib/tests/test_osutils.py (+12/-0)
doc/en/release-notes/bzr-2.8.txt (+3/-0)
To merge this branch: bzr merge lp:~fgallaire/bzr/fix-localtime
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+320299@code.launchpad.net

Description of the change

Fix buggy on Windows and 32-bit platforms local_time_offset().
_format_date() fail back to 'original' timezone when 'local' is buggy.

To post a comment you must log in.
lp:~fgallaire/bzr/fix-localtime updated
6623. By Florent Gallaire

Fix for Windows and 32-bit platforms buggy local_time_offset().

Unmerged revisions

6623. By Florent Gallaire

Fix for Windows and 32-bit platforms buggy local_time_offset().

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/osutils.py'
--- bzrlib/osutils.py 2017-03-17 10:39:02 +0000
+++ bzrlib/osutils.py 2017-03-22 04:32:31 +0000
@@ -839,11 +839,18 @@
839839
840840
841def local_time_offset(t=None):841def local_time_offset(t=None):
842 """Return offset of local zone from GMT, either at present or at time t."""842 """Return offset of local zone from GMT, either at present or at time t.
843 Return None if buggy gmtime() or localtime().
844 """
843 if t is None:845 if t is None:
844 t = time.time()846 t = time.time()
845 offset = datetime.fromtimestamp(t) - datetime.utcfromtimestamp(t)847 try:
846 return offset.days * 86400 + offset.seconds848 # datetime.fromtimestamp() and datetime.utcfromtimestamp() are as buggy
849 # as time.gmtime(). Not fixable (https://bugs.python.org/issue1647654).
850 offset = datetime.fromtimestamp(t) - datetime.utcfromtimestamp(t)
851 return offset.days * 86400 + offset.seconds
852 except ValueError:
853 return None
847854
848weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']855weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
849_default_format_by_weekday_num = [wd + " %Y-%m-%d %H:%M:%S" for wd in weekdays]856_default_format_by_weekday_num = [wd + " %Y-%m-%d %H:%M:%S" for wd in weekdays]
@@ -922,8 +929,15 @@
922 offset = 0929 offset = 0
923 tt = gmtime(t + offset)930 tt = gmtime(t + offset)
924 elif timezone == 'local':931 elif timezone == 'local':
925 tt = time.localtime(t)932 local_offset = local_time_offset(t)
926 offset = local_time_offset(t)933 if local_offset:
934 tt = time.localtime(t)
935 offset = local_offset
936 else:
937 # If buggy, use 'original' timezone
938 if offset is None:
939 offset = 0
940 tt = gmtime(t + offset)
927 else:941 else:
928 raise errors.UnsupportedTimezoneFormat(timezone)942 raise errors.UnsupportedTimezoneFormat(timezone)
929 if date_fmt is None:943 if date_fmt is None:
930944
=== modified file 'bzrlib/tests/test_osutils.py'
--- bzrlib/tests/test_osutils.py 2016-02-01 18:06:32 +0000
+++ bzrlib/tests/test_osutils.py 2017-03-22 04:32:31 +0000
@@ -436,6 +436,18 @@
436 eighteen_hours = 18 * 3600436 eighteen_hours = 18 * 3600
437 self.assertTrue(-eighteen_hours < offset < eighteen_hours)437 self.assertTrue(-eighteen_hours < offset < eighteen_hours)
438438
439 def test_local_time_offset_with_negative_windows_timestamp(self):
440 # Fri 1969-10-10 00:00:00 +0000
441 offset = osutils.local_time_offset(-7171200)
442
443 def test_local_time_offset_with_negative_32bit_timestamp(self):
444 # Mon 1900-01-01 00:00:00 +0000
445 offset = osutils.local_time_offset(-2208988800)
446
447 def test_local_time_offset_with_positive_32bit_timestamp(self):
448 # Sat 2039-01-01 00:00:00 +0000
449 offset = osutils.local_time_offset(2177452800)
450
439451
440class TestFdatasync(tests.TestCaseInTempDir):452class TestFdatasync(tests.TestCaseInTempDir):
441453
442454
=== modified file 'doc/en/release-notes/bzr-2.8.txt'
--- doc/en/release-notes/bzr-2.8.txt 2017-03-17 10:39:02 +0000
+++ doc/en/release-notes/bzr-2.8.txt 2017-03-22 04:32:31 +0000
@@ -39,6 +39,9 @@
39 * Fix for Windows and 32-bit platforms buggy gmtime().39 * Fix for Windows and 32-bit platforms buggy gmtime().
40 (Florent Gallaire, #1669178, #1670243)40 (Florent Gallaire, #1669178, #1670243)
4141
42 * Fix for Windows and 32-bit platforms buggy local_time_offset().
43 (Florent Gallaire, #1674195)
44
42Documentation45Documentation
43*************46*************
4447