summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-04-18 07:22:03 -0700
committerGitHub <noreply@github.com>2020-04-18 16:22:03 +0200
commite3919b658fb6abaf3b58bbf813bed6f59bd4d1c9 (patch)
tree746a0a27a607294903fba643a943a75b0f0b5901 /tests/stdlib
parentd839eb9352a6711fcdee23457605a1fa2e41f7d6 (diff)
downloadNim-e3919b658fb6abaf3b58bbf813bed6f59bd4d1c9.tar.gz
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
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/ttimes.nim15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/stdlib/ttimes.nim b/tests/stdlib/ttimes.nim
index 60e2ffdbe..a8da15f3d 100644
--- a/tests/stdlib/ttimes.nim
+++ b/tests/stdlib/ttimes.nim
@@ -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