File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -672,7 +672,7 @@ proc getDaysInYear*(year: int): int =
672
672
673
673
proc assertValidDate (monthday: MonthdayRange , month: Month , year: int )
674
674
{.inline .} =
675
- assert monthday <= getDaysInMonth (month, year),
675
+ assert monthday > 0 and monthday <= getDaysInMonth (month, year),
676
676
$ year & " -" & intToStr (ord (month), 2 ) & " -" & $ monthday &
677
677
" is not a valid date"
678
678
@@ -1578,9 +1578,14 @@ proc `<=`*(a, b: DateTime): bool =
1578
1578
# # Returns true if ``a`` happened before or at the same time as ``b``.
1579
1579
return a.toTime <= b.toTime
1580
1580
1581
+ proc isDefault [T](a: T): bool =
1582
+ system.`==` (a, default (T))
1583
+
1581
1584
proc `==` * (a, b: DateTime ): bool =
1582
1585
# # Returns true if ``a`` and ``b`` represent the same point in time.
1583
- return a.toTime == b.toTime
1586
+ if a.isDefault: b.isDefault
1587
+ elif b.isDefault: false
1588
+ else : a.toTime == b.toTime
1584
1589
1585
1590
proc isStaticInterval (interval: TimeInterval ): bool =
1586
1591
interval.years == 0 and interval.months == 0 and
Original file line number Diff line number Diff line change @@ -615,14 +615,19 @@ suite "ttimes":
615
615
doAssert between (x, y) == 1 .months + 1 .weeks
616
616
617
617
test " default DateTime" : # https://github.com/nim-lang/RFCs/issues/211
618
+ var num = 0
619
+ for ai in Month : num.inc
620
+ doAssert num == 12
621
+
618
622
var a: DateTime
619
623
doAssert a == DateTime .default
620
624
doAssert ($ a).len > 0 # no crash
621
625
doAssert a.month.Month .ord == 0
622
626
doAssert a.month.Month == cast [Month ](0 )
623
- var num = 0
624
- for ai in Month : num.inc
625
- doAssert num == 12
627
+ doAssert a.monthday == 0
628
+
629
+ doAssertRaises (AssertionError ): discard getDayOfWeek (a.monthday, a.month, a.year)
630
+ doAssertRaises (AssertionError ): discard a.toTime
626
631
627
632
test " inX procs" :
628
633
doAssert initDuration (seconds = 1 ).inSeconds == 1
You can’t perform that action at this time.
0 commit comments