1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: make parse_iso8601 support format without microseconds (#7176)

This commit is contained in:
Takahiro Yaota
2020-12-09 01:53:54 +09:00
committed by GitHub
parent d5915bde7c
commit 036e762446
2 changed files with 27 additions and 8 deletions

View File

@@ -49,13 +49,25 @@ fn test_parse_rfc2822_invalid() {
}
fn test_iso8601_parse_utc() {
format_utc := '2020-06-05T15:38:06.015959Z'
t_utc := time.parse_iso8601(format_utc) or {
panic(err)
formats := [
'2020-06-05T15:38:06.015959Z',
'2020-06-05T15:38:06Z',
]
times := [
[2020, 6, 5, 15, 38, 6, 15959],
[2020, 6, 5, 15, 38, 6, 0],
]
for i, format in formats {
t := time.parse_iso8601(format) or { panic(err) }
tt := times[i]
assert t.year == tt[0]
assert t.month == tt[1]
assert t.day == tt[2]
assert t.hour == tt[3]
assert t.minute == tt[4]
assert t.second == tt[5]
assert t.microsecond == tt[6]
}
assert t_utc.year == 2020
assert t_utc.month == 6
assert t_utc.day == 5
}
fn test_iso8601_parse_local() {