Skip to content

Commit a8f7e37

Browse files
committed
fix(commit): serialization timezone handling
Previously timezones which were not divisable by 3600s would be parsed correctly, but would serialize into a full hour, rounded up. Now floating point computation is used which fixes the issue. Related to #336
1 parent 039e265 commit a8f7e37

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

‎doc/source/changes.rst

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Changelog
33
=========
44

5+
1.0.2 - Fixes
6+
=============
7+
8+
* CRITICAL: fixed incorrect `Commit` object serialization when authored or commit date had timezones which were not
9+
divisable by 3600 seconds. This would happen if the timezone was something like `+0530` for instance.
10+
* A list of all additional fixes can be found `on github <https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v1.0.2+-+Fixes%22+is%3Aclosed>`_
11+
512
1.0.1 - Fixes
613
=============
714

‎git/objects/util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def utctz_to_altz(utctz):
7373
def altz_to_utctz_str(altz):
7474
"""As above, but inverses the operation, returning a string that can be used
7575
in commit objects"""
76-
utci = -1 * int((altz / 3600) * 100)
76+
utci = -1 * int((float(altz) / 3600) * 100)
7777
utcs = str(abs(utci))
7878
utcs = "0" * (4 - len(utcs)) + utcs
7979
prefix = (utci < 0 and '-') or '+'

‎git/test/performance/test_commit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_commit_iteration(self):
7676
% (nc, elapsed_time, nc / elapsed_time), file=sys.stderr)
7777

7878
def test_commit_serialization(self):
79-
assert_commit_serialization(self.gitrwrepo, self.gitrwrepo.head, True)
79+
assert_commit_serialization(self.gitrwrepo, '58c78e6', True)
8080

8181
rwrepo = self.gitrwrepo
8282
make_object = rwrepo.odb.store

0 commit comments

Comments
 (0)