Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f879c7

Browse filesBrowse files
committed
Simplified parse_date implementation
This allows to deal with the previous UTC issue without manually reversing timezone adjustments
1 parent 4a47a9c commit 3f879c7
Copy full SHA for 3f879c7

2 files changed

+9-9Lines changed: 9 additions & 9 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/objects/util.py‎

Copy file name to clipboardExpand all lines: git/objects/util.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from string import digits
1616
import time
17+
import calendar
1718
import os
1819

1920
__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date',
@@ -106,9 +107,10 @@ def parse_date(string_date):
106107
* ISO 8601 2005-04-07T22:13:13
107108
The T can be a space as well
108109
109-
:return: Tuple(int(timestamp), int(offset)), both in seconds since epoch
110+
:return: Tuple(int(timestamp_UTC), int(offset)), both in seconds since epoch
110111
:raise ValueError: If the format could not be understood
111-
:note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY"""
112+
:note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
113+
"""
112114
# git time
113115
try:
114116
if string_date.count(' ') == 1 and string_date.rfind(':') == -1:
@@ -121,6 +123,7 @@ def parse_date(string_date):
121123
offset = verify_utctz(string_date[-5:])
122124
string_date = string_date[:-6] # skip space as well
123125
# END split timezone info
126+
offset = utctz_to_altz(offset)
124127

125128
# now figure out the date and time portion - split time
126129
date_formats = list()
@@ -153,13 +156,10 @@ def parse_date(string_date):
153156
for fmt in date_formats:
154157
try:
155158
dtstruct = time.strptime(date_part, fmt)
156-
fstruct = time.struct_time((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday,
159+
utctime = calendar.timegm((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday,
157160
tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec,
158161
dtstruct.tm_wday, dtstruct.tm_yday, tstruct.tm_isdst))
159-
utctime = time.mktime(fstruct)
160-
# time.mktime returns local time, so we need to adjust it for local offset
161-
utctime -= time.altzone if time.daylight else time.timezone
162-
return int(utctime), utctz_to_altz(offset)
162+
return int(utctime), offset
163163
except ValueError:
164164
continue
165165
# END exception handling
Collapse file

‎git/test/test_util.py‎

Copy file name to clipboardExpand all lines: git/test/test_util.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def assert_rval(rval, veri_time, offset=0):
102102
iso3 = ("2005.04.07 22:13:11 -0000", 0)
103103
alt = ("04/07/2005 22:13:11", 0)
104104
alt2 = ("07.04.2005 22:13:11", 0)
105-
veri_time = 1112911991 # the time this represents
105+
veri_time_utc = 1112911991 # the time this represents, in time since epoch, UTC
106106
for date, offset in (rfc, iso, iso2, iso3, alt, alt2):
107-
assert_rval(parse_date(date), veri_time, offset)
107+
assert_rval(parse_date(date), veri_time_utc, offset)
108108
# END for each date type
109109

110110
# and failure

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.