Skip to content

Commit

Permalink
fix nim-lang/RFCs#211: var a: DateTime works
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 17, 2020
1 parent f10689d commit fce0671
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ type
Month* = enum ## Represents a month. Note that the enum starts at ``1``,
## so ``ord(month)`` will give the month number in the
## range ``1..12``.
# mInvalid = (0, "Invalid") # intentionally left out so `items` works
mJan = (1, "January")
mFeb = "February"
mMar = "March"
Expand Down Expand Up @@ -296,7 +297,8 @@ when defined(nimHasStyleChecks):
{.pop.}

type
MonthdayRange* = range[1..31]
MonthdayRange* = range[0..31]
## 0 represents an invalid month
HourRange* = range[0..23]
MinuteRange* = range[0..59]
SecondRange* = range[0..60]
Expand Down
10 changes: 10 additions & 0 deletions tests/stdlib/ttimes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ 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 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)
var num = 0
for ai in Month: num.inc
doAssert num == 12

test "inX procs":
doAssert initDuration(seconds = 1).inSeconds == 1
doAssert initDuration(seconds = -1).inSeconds == -1
Expand Down

0 comments on commit fce0671

Please sign in to comment.