Skip to content

Commit

Permalink
[Dates] Define a method for (:)(a::Date, b::Date) with default step
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Jun 26, 2022
1 parent a60c76e commit 5380495
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/Dates/src/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

StepRange{<:Dates.DatePeriod,<:Real}(start, step, stop) =
throw(ArgumentError("must specify step as a Period when constructing Dates ranges"))
Base.:(:)(a::T, b::T) where {T<:Date} = (:)(a, Day(1), b)

# Given a start and end date, how many steps/periods are in between
guess(a::DateTime, b::DateTime, c) = floor(Int64, (Int128(value(b)) - Int128(value(a))) / toms(c))
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Dates/test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,11 @@ a = Dates.Time(23, 1, 1)
@test length(utm_typemin:-Millisecond(1):utm_typemin) == 1
end

# Issue #45816
@testset "default step for date ranges" begin
r = Date(2000, 1, 1):Date(2000, 12, 31)
@test step(r) === Day(1)
@test length(r) == 366
end

end # RangesTest module

0 comments on commit 5380495

Please sign in to comment.