diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-03-01 12:56:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-01 21:56:20 +0100 |
commit | 22d1ba4be76569d1df96cc8bfed47fccfc833019 (patch) | |
tree | 5f8b72dcba8a37362b15de7eac7504be021f758a /lib/pure | |
parent | 525ab5a497d1b998bc67c5b1225db3556ac77d27 (diff) | |
download | Nim-22d1ba4be76569d1df96cc8bfed47fccfc833019.tar.gz |
fixes #13543 and added times.isLeapDay (#13547)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/times.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 3fc4d69df..92b6cd3b7 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -637,6 +637,19 @@ proc isLeapYear*(year: int): bool = doAssert not isLeapYear(1900) year mod 4 == 0 and (year mod 100 != 0 or year mod 400 == 0) +proc isLeapDay*(t: DateTime): bool {.since: (1,1).} = + ## returns whether `t` is a leap day, ie, Feb 29 in a leap year. This matters + ## as it affects time offset calculations. + runnableExamples: + let t = initDateTime(29, mFeb, 2020, 00, 00, 00, utc()) + doAssert t.isLeapDay + doAssert t+1.years-1.years != t + let t2 = initDateTime(28, mFeb, 2020, 00, 00, 00, utc()) + doAssert not t2.isLeapDay + doAssert t2+1.years-1.years == t2 + doAssertRaises(Exception): discard initDateTime(29, mFeb, 2021, 00, 00, 00, utc()) + t.year.isLeapYear and t.month == mFeb and t.monthday == 29 + proc getDaysInMonth*(month: Month, year: int): int = ## Get the number of days in ``month`` of ``year``. # http://www.dispersiondesign.com/articles/time/number_of_days_in_a_month |