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

x.json: fix parsing of time fields, that have just a single date encoded inside the parsed string (fix #16722)

This commit is contained in:
Delyan Angelov
2022-12-20 16:34:04 +02:00
parent c84eb29b78
commit 3c920f2ee6
2 changed files with 10 additions and 0 deletions

View File

@ -79,6 +79,12 @@ fn test_types() {
assert json.decode[StructType[int]]('{"val": false}')!.val == 0
assert json.decode[StructType[time.Time]]('{"val": "2022-03-11T13:54:25.000Z"}')!.val == fixed_time
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.year == 2001
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.month == 1
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.day == 5
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.hour == 0
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.minute == 0
assert json.decode[StructType[time.Time]]('{"val": "2001-01-05"}')!.val.second == 0
assert json.decode[StructType[time.Time]]('{"val": "2022-03-11 13:54:25.000"}')!.val == fixed_time
assert json.decode[StructType[time.Time]]('{"val": 1647006865}')!.val == fixed_time
assert json.decode[StructType[time.Time]]('{"val": "1647006865"}')!.val == fixed_time