From e17e147fb165b5c635e45c07a9aeceaa9db7fc7a Mon Sep 17 00:00:00 2001 From: Oliver Stueker Date: Mon, 7 Dec 2015 17:41:44 -0330 Subject: [PATCH] Fix timezone issue with negative offsets The current code miscalculates the time-zone offsets for time zones that don't have a full-hour offset and are located west of UTC (e.g. St. John's, Newfoundland). Basically it's caused because 33 // 10 == 3, but -33 // 10 != -3. Take the example of St. John's (-0330). The correct integer timezone should be 3.5 * 3600 (12600), however, since we are not checking for negative module arithmetic, instead of calculating the timezone for (-3, -30), we are doing it for (-4, 70), which would be OK... if we had hours of 100 minutes: -4 * 100 + 70 = -330 We could fix the code to use proper negative arithmetic (mod -100), but why bother with the extra complexity? Let's just use absolute numbers and fix the sign later. This fixes issue #48. Commit message written by Felipe Contreras. Signed-off-by: Felipe Contreras --- git-remote-hg | 8 +++++--- test/bidi.t | 2 +- test/main.t | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 859eed6..a4689ed 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -72,12 +72,14 @@ def gitmode(flags): return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644' def gittz(tz): - return '%+03d%02d' % (-tz / 3600, -tz % 3600 / 60) + sign = 1 if tz < 0 else -1 + return '%+03d%02d' % (sign * (abs(tz) / 3600), abs(tz) % 3600 / 60) def hgtz(tz): tz = int(tz) - tz = ((tz / 100) * 3600) + ((tz % 100) * 60) - return -tz + sign = 1 if tz < 0 else -1 + tz = ((abs(tz) / 100) * 3600) + ((abs(tz) % 100) * 60) + return sign * tz def hgmode(mode): m = { '100755': 'x', '120000': 'l' } diff --git a/test/bidi.t b/test/bidi.t index 1c41fea..9bc9821 100755 --- a/test/bidi.t +++ b/test/bidi.t @@ -240,7 +240,7 @@ test_expect_success 'hg tags' ' test_cmp expected actual ' -test_expect_failure 'test timezones' ' +test_expect_success 'test timezones' ' test_when_finished "rm -rf gitrepo* hgrepo*" && ( diff --git a/test/main.t b/test/main.t index 3af4fce..d51021c 100755 --- a/test/main.t +++ b/test/main.t @@ -1052,7 +1052,7 @@ test_expect_success 'push annotated tag' ' test_cmp expected actual ' -test_expect_failure 'timezone issues with negative offsets' ' +test_expect_success 'timezone issues with negative offsets' ' test_when_finished "rm -rf hgrepo gitrepo1 gitrepo2" && hg init hgrepo &&