diff --git a/stdlib/Dates/src/adjusters.jl b/stdlib/Dates/src/adjusters.jl index 245e2678a9d77..dee2894ff5d4e 100644 --- a/stdlib/Dates/src/adjusters.jl +++ b/stdlib/Dates/src/adjusters.jl @@ -204,6 +204,41 @@ function adjust(df::DateFunction, start, step, limit) throw(ArgumentError("Adjustment limit reached: $limit iterations")) end +""" + adjust(df, start[, step, limit]) -> TimeType + adjust(df, start) -> TimeType + +Adjusts the date in `start` until the `f::Function` passed using `df` returns `true`. +The optional `step` parameter dictates the change in `start` on every iteration. +If `limit` iterations occur, then an [`ArgumentError`](@ref) is thrown. + +The default values for parameters `start` and `limit` are 1 Day and 10,000 respectively. + +# Examples +```jldoctest +julia> adjust(date -> month(date) == 10, Date(2022, 1, 1), step=Month(3), limit=10) +2022-10-01 + +julia> adjust(date -> year(date) == 2025, Date(2022, 1, 1), step=Year(1), limit=4) +2025-01-01 + +julia> adjust(date -> day(date) == 15, Date(2022, 1, 1), step=Year(1), limit=3) +ERROR: ArgumentError: Adjustment limit reached: 3 iterations +Stacktrace: +[...] + +julia> adjust(date -> month(date) == 10, Date(2022, 1, 1)) +2022-10-01 + +julia> adjust(date -> year(date) == 2025, Date(2022, 1, 1)) +2025-01-01 + +julia> adjust(date -> year(date) == 2224, Date(2022, 1, 1)) +ERROR: ArgumentError: Adjustment limit reached: 10000 iterations +Stacktrace: +[...] +``` +""" function adjust(func::Function, start; step::Period=Day(1), limit::Int=10000) return adjust(DateFunction(func, start), start, step, limit) end diff --git a/stdlib/Dates/test/runtests.jl b/stdlib/Dates/test/runtests.jl index 7ac46bd69139c..ad2ee43cedfb1 100644 --- a/stdlib/Dates/test/runtests.jl +++ b/stdlib/Dates/test/runtests.jl @@ -9,9 +9,7 @@ for file in readlines(joinpath(@__DIR__, "testgroups")) end @testset "Docstrings" begin - undoc = Docs.undocumented_names(Dates) - @test_broken isempty(undoc) - @test undoc == [:adjust] + @test isempty(Docs.undocumented_names(Dates)) end end