fix https://github.com/nim-lang/RFCs/issues/211: var a: DateTime compiles and is usable (#14002) [backport:1.2]

* fix https://github.com/nim-lang/RFCs/issues/211: `var a: DateTime` works
* assertValidDate checks for sentinel month
This commit is contained in:
Timothee Cour
2020-04-18 07:22:03 -07:00
committed by GitHub
parent d839eb9352
commit e3919b658f
2 changed files with 25 additions and 3 deletions

View File

@@ -614,6 +614,21 @@ suite "ttimes":
doAssert x + between(x, y) == y
doAssert between(x, y) == 1.months + 1.weeks
test "default DateTime": # https://github.com/nim-lang/RFCs/issues/211
var num = 0
for ai in Month: num.inc
doAssert num == 12
var a: DateTime
doAssert a == DateTime.default
doAssert ($a).len > 0 # no crash
doAssert a.month.Month.ord == 0
doAssert a.month.Month == cast[Month](0)
doAssert a.monthday == 0
doAssertRaises(AssertionError): discard getDayOfWeek(a.monthday, a.month, a.year)
doAssertRaises(AssertionError): discard a.toTime
test "inX procs":
doAssert initDuration(seconds = 1).inSeconds == 1
doAssert initDuration(seconds = -1).inSeconds == -1