mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-16 08:04:20 +00:00
Merge pull request #6495 from GULPF/Fix-countLeapYears
Fix countLeapYears
This commit is contained in:
@@ -1025,7 +1025,7 @@ proc countLeapYears*(yearSpan: int): int =
|
||||
## counts the number of leap years up to January 1st of a given year.
|
||||
## Keep in mind that if specified year is a leap year, the leap day
|
||||
## has not happened before January 1st of that year.
|
||||
(((yearSpan - 1) / 4) - ((yearSpan - 1) / 100) + ((yearSpan - 1) / 400)).int
|
||||
(yearSpan - 1) div 4 - (yearSpan - 1) div 100 + (yearSpan - 1) div 400
|
||||
|
||||
proc countDays*(yearSpan: int): int =
|
||||
## Returns the number of days spanned by a given number of years.
|
||||
|
||||
@@ -235,3 +235,9 @@ block dstTest:
|
||||
parsedJul = parse("2016-07-01 04:00:00+01:00", "yyyy-MM-dd HH:mm:sszzz")
|
||||
doAssert toTime(parsedJan) == fromSeconds(1451962800)
|
||||
doAssert toTime(parsedJul) == fromSeconds(1467342000)
|
||||
|
||||
block countLeapYears:
|
||||
# 1920, 2004 and 2020 are leap years, and should be counted starting at the following year
|
||||
doAssert countLeapYears(1920) + 1 == countLeapYears(1921)
|
||||
doAssert countLeapYears(2004) + 1 == countLeapYears(2005)
|
||||
doAssert countLeapYears(2020) + 1 == countLeapYears(2021)
|
||||
Reference in New Issue
Block a user