mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time, x.json2: improve iso8601 time decoding (#18496)
This commit is contained in:
parent
d7a50b4a22
commit
5006ffb304
@ -252,7 +252,7 @@ fn parse_iso8601_time(s string) !(int, int, int, int, i64, bool) {
|
||||
microsecond_ = nanosecond_ / 1000
|
||||
} else {
|
||||
count = unsafe {
|
||||
C.sscanf(&char(s.str), c'%2d:%2d:%2d.%6d%c%2d:%2d', &hour_, &minute_, &second_,
|
||||
C.sscanf(&char(s.str), c'%2d:%2d:%2d.%9d%c%2d:%2d', &hour_, &minute_, &second_,
|
||||
µsecond_, &char(&plus_min_z), &offset_hour, &offset_minute)
|
||||
}
|
||||
// Missread microsecond ([Sec Hour Minute].len == 3 < 4)
|
||||
|
@ -117,10 +117,10 @@ pub fn decode[T](src string) !T {
|
||||
typ.$(field.name) = res[json_name]!.str()
|
||||
}
|
||||
} $else $if field.typ is time.Time {
|
||||
typ.$(field.name) = res[field.name]!.to_time()!
|
||||
typ.$(field.name) = res[json_name]!.to_time()!
|
||||
} $else $if field.typ is ?time.Time {
|
||||
if json_name in res {
|
||||
typ.$(field.name) = res[field.name]!.to_time()!
|
||||
typ.$(field.name) = res[json_name]!.to_time()!
|
||||
}
|
||||
} $else $if field.is_array {
|
||||
// typ.$(field.name) = res[field.name]!.arr()
|
||||
@ -393,8 +393,8 @@ pub fn (f Any) to_time() !time.Time {
|
||||
return time.unix(f)
|
||||
}
|
||||
string {
|
||||
if f.len == 10 && f[4] == `-` && f[7] == `-` {
|
||||
// just a date in the format `2001-01-01`
|
||||
is_iso8601 := f[4] == `-` && f[7] == `-`
|
||||
if is_iso8601 {
|
||||
return time.parse_iso8601(f)!
|
||||
}
|
||||
is_rfc3339 := f.len == 24 && f[23] == `Z` && f[10] == `T`
|
||||
|
Loading…
Reference in New Issue
Block a user