Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone fix #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions git-remote-hg
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,38 @@ 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)
""" Converts UTC-offset (in negated seconds) to "+HHmm" notation.

Examples:
>>> gittz_fixed(-1*3600) # Paris
'+0100'
>>> gittz_fixed(5*3600) # New York
'-0500'
>>> gittz_fixed(int(3.5*3600)) # St. John\'s
'-0330'
>>> gittz_fixed(int(-3.5*3600)) # Tehran
'+0330'
"""
sign = 1 if tz < 0 else -1
return '%+03d%02d' % (sign * (abs(tz) / 3600), abs(tz) % 3600 / 60)

def pytz(tz):
""" Converts timezone in "+HHmm" notation to UTC-offset (in negated seconds).

Examples:
>>> pytz_fixed('+0100') # Paris
-3600
>>> pytz_fixed('-0500') # New York
18000
>>> pytz_fixed('-0330') # St. John\'s (fails!)
12600
>>> pytz_fixed('+0330') # Tehran
-12600
"""
tz = int(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' }
Expand Down Expand Up @@ -260,9 +291,7 @@ class Parser:
if ex:
user += ex

tz = int(tz)
tz = ((tz / 100) * 3600) + ((tz % 100) * 60)
return (user, int(date), -tz)
return (user, int(date), pytz(tz))

def fix_file_path(path):
path = os.path.normpath(path)
Expand Down
34 changes: 34 additions & 0 deletions test/main.t
Original file line number Diff line number Diff line change
Expand Up @@ -1024,4 +1024,38 @@ test_expect_success 'clone replace directory with a file' '
check_files gitrepo "dir_or_file"
'

test_expect_success 'timezone issues' '
test_when_finished "rm -rf hgrepo gitrepo1 gitrepo2" &&

(
hg init hgrepo &&
cd hgrepo &&
echo one > content &&
hg add content &&
hg commit -m one
) &&

echo "Tue, 27 Sep 2016 00:00:00 -0230" > expected_timestamp &&

(
git clone "hg::hgrepo" gitrepo1 &&
cd gitrepo1 &&
echo two >> content &&
git add content &&
git commit -m two --date="$(cat ../expected_timestamp)" &&
git push &&
cd ..
) &&

git clone "hg::hgrepo" gitrepo2 &&

(
cd gitrepo2 &&
git log -1 --format="%aD" > ../actual_timestamp &&
cd ..
) &&

test_cmp expected_timestamp actual_timestamp
'

test_done