diff --git a/NEWS.md b/NEWS.md index 81209168d808d..3c0aad9e5a387 100644 --- a/NEWS.md +++ b/NEWS.md @@ -299,6 +299,9 @@ Deprecated or removed * Calling `union` with no arguments is deprecated; construct an empty set with an appropriate element type using `Set{T}()` instead ([#23144]). + * Vectorized `DateTime`, `Date`, and `format` methods have been deprecated in favor of + dot-syntax ([#23207]). + * `Base.cpad` has been removed; use an appropriate combination of `rpad` and `lpad` instead ([#23187]). @@ -1156,3 +1159,5 @@ Command-line option changes [#23117]: https://github.com/JuliaLang/julia/issues/23117 [#23144]: https://github.com/JuliaLang/julia/issues/23144 [#23157]: https://github.com/JuliaLang/julia/issues/23157 +[#23187]: https://github.com/JuliaLang/julia/issues/23187 +[#23207]: https://github.com/JuliaLang/julia/issues/23207 diff --git a/base/dates/io.jl b/base/dates/io.jl index 2005b941effab..78f9ef4bb5346 100644 --- a/base/dates/io.jl +++ b/base/dates/io.jl @@ -557,24 +557,3 @@ function Base.string(dt::Date) dd = lpad(d, 2, "0") return "$yy-$mm-$dd" end - -# vectorized -function DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH) - DateTime(Y, DateFormat(f, locale)) -end -function DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat) - return reshape(DateTime[parse(DateTime, y, df) for y in Y], size(Y)) -end -function Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH) - Date(Y, DateFormat(f, locale)) -end -function Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat) - return reshape(Date[Date(parse(Date, y, df)) for y in Y], size(Y)) -end - -function format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH) - format(Y, DateFormat(f, locale)) -end -function format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where T<:TimeType - return reshape([format(y, df) for y in Y], size(Y)) -end diff --git a/base/deprecated.jl b/base/deprecated.jl index 54f57c816bf34..323e378138e2a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1584,6 +1584,26 @@ for op in (:exp, :exp2, :exp10, :log, :log2, :log10, @eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x) end +# deprecate remaining vectorized methods from Base.Dates +@eval Dates @deprecate( + DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH), + DateTime.(Y, f; locale=locale) ) +@eval Dates @deprecate( + DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat), + DateTime.(Y, df) ) +@eval Dates @deprecate( + Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH), + Date.(Y, f; locale=locale) ) +@eval Dates @deprecate( + Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat), + Date.(Y, df) ) +@eval Dates @deprecate( + format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH), + format.(Y, f; locale=locale) ) +@eval Dates @deprecate( + format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where {T<:TimeType}, + format.(Y, df) ) + # PR #22182 @deprecate is_apple Sys.isapple @deprecate is_bsd Sys.isbsd diff --git a/test/dates/io.jl b/test/dates/io.jl index 4a34d87859637..c7523277e4535 100644 --- a/test/dates/io.jl +++ b/test/dates/io.jl @@ -319,19 +319,18 @@ f = "ymd" @test Dates.Date(string(Dates.Date(dt))) == Dates.Date(dt) @test Dates.DateTime(string(dt)) == dt -# Vectorized +# formerly vectorized Date/DateTime/format methods dr = ["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05", "2000-01-06", "2000-01-07", "2000-01-08", "2000-01-09", "2000-01-10"] dr2 = [Dates.Date(2000) : Dates.Date(2000, 1, 10);] -@test Dates.Date(dr) == dr2 -@test Dates.Date(dr, "yyyy-mm-dd") == dr2 +@test Dates.Date.(dr) == dr2 +@test Dates.Date.(dr, dateformat"yyyy-mm-dd") == dr2 @test Dates.DateTime.(dr) == Dates.DateTime.(dr2) -@test Dates.DateTime(dr, "yyyy-mm-dd") == Dates.DateTime.(dr2) +@test Dates.DateTime.(dr, dateformat"yyyy-mm-dd") == Dates.DateTime.(dr2) -@test Dates.format(dr2) == dr -@test Dates.format(dr2, "yyyy-mm-dd") == dr +@test Dates.format.(dr2, "yyyy-mm-dd") == dr -@test typeof(Dates.Date(dr)) == Array{Date, 1} +@test typeof(Dates.Date.(dr)) == Array{Date, 1} # Issue 13 t = Dates.DateTime(1, 1, 1, 14, 51, 0, 118)