Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit1e1e19d

Browse files
committed
Merge branch 'yarikoptic-bf/time_parse' into 0.3
2 parents891b124 +3f879c7 commit1e1e19d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

‎git/objects/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
fromstringimportdigits
1616
importtime
17+
importcalendar
1718
importos
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
ifstring_date.count(' ')==1andstring_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,10 +156,10 @@ def parse_date(string_date):
153156
forfmtindate_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-
returnint(time.mktime(fstruct)),utctz_to_altz(offset)
162+
returnint(utctime),offset
160163
exceptValueError:
161164
continue
162165
# END exception handling

‎git/test/test_util.py

Lines 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=1112904791# the time this represents
105+
veri_time_utc=1112911991# the time this represents, in time since epoch, UTC
106106
fordate,offsetin (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)

[8]ページ先頭

©2009-2025 Movatter.jp