|
260 | 260 | Month* = enum ## Represents a month. Note that the enum starts at ``1``,
|
261 | 261 | ## so ``ord(month)`` will give the month number in the
|
262 | 262 | ## range ``1..12``.
|
| 263 | + # mInvalid = (0, "Invalid") # intentionally left out so `items` works |
263 | 264 | mJan = (1, "January")
|
264 | 265 | mFeb = "February"
|
265 | 266 | mMar = "March"
|
@@ -296,7 +297,8 @@ when defined(nimHasStyleChecks):
|
296 | 297 | {.pop.}
|
297 | 298 |
|
298 | 299 | type
|
299 |
| - MonthdayRange* = range[1..31] |
| 300 | + MonthdayRange* = range[0..31] |
| 301 | + ## 0 represents an invalid day of the month |
300 | 302 | HourRange* = range[0..23]
|
301 | 303 | MinuteRange* = range[0..59]
|
302 | 304 | SecondRange* = range[0..60]
|
@@ -670,7 +672,7 @@ proc getDaysInYear*(year: int): int =
|
670 | 672 |
|
671 | 673 | proc assertValidDate(monthday: MonthdayRange, month: Month, year: int)
|
672 | 674 | {.inline.} =
|
673 |
| - assert monthday <= getDaysInMonth(month, year), |
| 675 | + assert monthday > 0 and monthday <= getDaysInMonth(month, year), |
674 | 676 | $year & "-" & intToStr(ord(month), 2) & "-" & $monthday &
|
675 | 677 | " is not a valid date"
|
676 | 678 |
|
@@ -1576,9 +1578,14 @@ proc `<=`*(a, b: DateTime): bool =
|
1576 | 1578 | ## Returns true if ``a`` happened before or at the same time as ``b``.
|
1577 | 1579 | return a.toTime <= b.toTime
|
1578 | 1580 |
|
| 1581 | +proc isDefault[T](a: T): bool = |
| 1582 | + system.`==`(a, default(T)) |
| 1583 | + |
1579 | 1584 | proc `==`*(a, b: DateTime): bool =
|
1580 | 1585 | ## Returns true if ``a`` and ``b`` represent the same point in time.
|
1581 |
| - return a.toTime == b.toTime |
| 1586 | + if a.isDefault: b.isDefault |
| 1587 | + elif b.isDefault: false |
| 1588 | + else: a.toTime == b.toTime |
1582 | 1589 |
|
1583 | 1590 | proc isStaticInterval(interval: TimeInterval): bool =
|
1584 | 1591 | interval.years == 0 and interval.months == 0 and
|
|
0 commit comments