mirror of
https://github.com/mnauw/git-remote-hg.git
synced 2025-11-02 01:25:49 +01:00
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 <felipe.contreras@gmail.com>
This commit is contained in:
committed by
Felipe Contreras
parent
4878023a8b
commit
e17e147fb1
@@ -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' }
|
||||
|
||||
@@ -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*" &&
|
||||
|
||||
(
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user