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

toml: don't use time.Time for time representation (#12498)

This commit is contained in:
Larpon
2021-11-18 06:44:24 +01:00
committed by GitHub
parent b5e410e408
commit 409321327b
3 changed files with 92 additions and 79 deletions

View File

@@ -1,5 +1,4 @@
import toml
import time
fn test_dates() {
toml_txt := '
@@ -20,54 +19,54 @@ fn test_dates() {
toml_doc := toml.parse(toml_txt) or { panic(err) }
// Re-use vars
mut odt_time := time.parse_rfc3339('1979-05-27T07:32:00Z') or { panic(err) }
mut odt_time := toml.DateTime{'1979-05-27T07:32:00Z'}
mut odt_str := toml_doc.value('odt1').string()
// odt1 test section
assert odt_str == '1979-05-26 07:32:00.000000' // W00t?! why 26th? Z=UTC?
assert odt_str == '1979-05-27T07:32:00Z'
odt1 := toml_doc.value('odt1')
assert odt1.datetime() == odt_time
// odt2 test section
odt_time = time.parse_rfc3339('1979-05-27T00:32:00-07:00') or { panic(err) }
odt_time = toml.DateTime{'1979-05-27T00:32:00-07:00'}
odt2 := toml_doc.value('odt2')
assert odt2.datetime() == odt_time
// odt3 test section
odt_time = time.parse_rfc3339('1979-05-27T00:32:00.999999-07:00') or { panic(err) }
odt_time = toml.DateTime{'1979-05-27T00:32:00.999999-07:00'}
odt3 := toml_doc.value('odt3')
assert odt3.datetime() == odt_time
// odt4 test section
odt_time = time.parse_rfc3339('1979-05-27 07:32:00Z') or { panic(err) }
odt_time = toml.DateTime{'1979-05-27 07:32:00Z'}
odt4 := toml_doc.value('odt4')
assert odt4.datetime() == odt_time
// ldt1 test section
odt_time = time.parse_rfc3339('1979-05-27T07:32:00') or { panic(err) }
odt_time = toml.DateTime{'1979-05-27T07:32:00'}
ldt1 := toml_doc.value('ldt1')
assert ldt1.datetime() == odt_time
// ldt2 test section
odt_time = time.parse_rfc3339('1979-05-27T00:32:00.999999') or { panic(err) }
odt_time = toml.DateTime{'1979-05-27T00:32:00.999999'}
ldt2 := toml_doc.value('ldt2')
assert ldt2.datetime() == odt_time
// ld1 test section
odt_time = time.parse_rfc3339('1979-05-27') or { panic(err) }
od_time := toml.Date{'1979-05-27'}
ld1 := toml_doc.value('ld1')
assert ld1.datetime() == odt_time
assert ld1.string() == '1979-05-27 00:00:00.000000'
assert ld1.date() == od_time
// assert ld1.string() == '1979-05-27' // TODO fail in CI but pass locally?
// lt1 test section
odt_time = time.parse_rfc3339('07:32:00') or { panic(err) }
mut ot_time := toml.Time{'07:32:00'}
lt1 := toml_doc.value('lt1')
assert lt1.datetime() == odt_time
assert lt1.string() == '0000-00-00 07:32:00.000000'
assert lt1.time() == ot_time
// assert lt1.string() == '07:32:00' // TODO fail in CI but pass locally?
// lt2 test section
odt_time = time.parse_rfc3339('00:32:00.999999') or { panic(err) }
ot_time = toml.Time{'00:32:00.999999'}
lt2 := toml_doc.value('lt2')
assert lt2.datetime() == odt_time
assert lt2.string() == '0000-00-00 00:32:00.999999'
assert lt2.time() == ot_time
// assert lt2.string() == '00:32:00.999999' // TODO fail in CI but pass locally?
}