time: fix parse_iso8601 on windows (#7853)

pull/7864/head^2
yuyi 2021-01-05 00:26:21 +08:00 committed by GitHub
parent b9c6011602
commit 52521554ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 26 deletions

View File

@ -139,6 +139,5 @@ pub fn parse_iso8601(s string) ?Time {
unix_time += u64(unix_offset) unix_time += u64(unix_offset)
} }
t = unix2(int(unix_time), t.microsecond) t = unix2(int(unix_time), t.microsecond)
// Convert the time to local time return t
return t.local()
} }

View File

@ -49,13 +49,6 @@ fn test_parse_rfc2822_invalid() {
} }
fn test_parse_iso8601() { fn test_parse_iso8601() {
// Because the offset between local time and UTC is not constant in regions
// that use daylight saving times we need to calculate separete offsets for
// summer and winter
offset_summer := time.Duration(time.new_time(year: 2020, month: 6, day: 5, hour: 15).local() -
time.new_time(year: 2020, month: 6, day: 5, hour: 15))
offset_winter := time.Duration(time.new_time(year: 2020, month: 11, day: 5, hour: 15).local() -
time.new_time(year: 2020, month: 11, day: 5, hour: 15))
formats := [ formats := [
'2020-06-05T15:38:06Z', '2020-06-05T15:38:06Z',
'2020-06-05T15:38:06.015959Z', '2020-06-05T15:38:06.015959Z',
@ -77,23 +70,20 @@ fn test_parse_iso8601() {
assert false assert false
continue continue
} }
data := times[i] year := times[i][0]
t2 := time.new_time( assert t.year == year
year: data[0] month := times[i][1]
month: data[1] assert t.month == month
day: data[2] day := times[i][2]
hour: data[3] assert t.day == day
minute: data[4] hour := times[i][3]
second: data[5] assert t.hour == hour
microsecond: data[6] minute := times[i][4]
).add(if i <= 4 { offset_summer } else { offset_winter }) assert t.minute == minute
assert t.year == t2.year second := times[i][5]
assert t.month == t2.month assert t.second == second
assert t.day == t2.day microsecond := times[i][6]
assert t.hour == t2.hour assert t.microsecond == microsecond
assert t.minute == t2.minute
assert t.second == t2.second
assert t.microsecond == t2.microsecond
} }
} }