Skip to content

Commit 2b31eab

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 b0691b5 commit 2b31eab

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

stdlib/Dates/src/types.jl

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

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

208208
# Number of days in month
209209
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)