Skip to content

Commit

Permalink
Restrict argument to isleapyear(::Integer) (#55317)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jariji authored Jul 31, 2024
1 parent d64ebd3 commit fdecc59
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function totaldays(y, m, d)
end

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

# Number of days in month
const DAYSINMONTH = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
Expand Down
1 change: 1 addition & 0 deletions stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ end
@test Dates.isleapyear(-1) == false
@test Dates.isleapyear(4) == true
@test Dates.isleapyear(-4) == true
@test_throws MethodError Dates.isleapyear(Dates.Year(1992))
end
# Create "test" check manually
y = Dates.Year(1)
Expand Down

0 comments on commit fdecc59

Please sign in to comment.