Skip to content

Commit 2eef480

Browse files
jarijiKristofferC
authored andcommitted
Restrict argument to isleapyear(::Integer) (#55317)
In 1.10 we have ```jl julia> isleapyear(Year(1992)) false ``` which is semantically incorrect because `Year(1992)` is a duration (1992 years), not an instant. This PR restricts the currently unrestricted argument to integers. (cherry picked from commit fdecc59)
1 parent f705611 commit 2eef480

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

stdlib/Dates/src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function totaldays(y, m, d)
183183
end
184184

185185
# If the year is divisible by 4, except for every 100 years, except for every 400 years
186-
isleapyear(y) = (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0))
186+
isleapyear(y::Integer) = (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0))
187187

188188
# Number of days in month
189189
const DAYSINMONTH = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

stdlib/Dates/test/types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
@test Dates.isleapyear(-1) == false
4242
@test Dates.isleapyear(4) == true
4343
@test Dates.isleapyear(-4) == true
44+
@test_throws MethodError Dates.isleapyear(Dates.Year(1992))
4445
end
4546
# Create "test" check manually
4647
y = Dates.Year(1)

0 commit comments

Comments
 (0)