From 96b12970a7c2329915a994e6cacab0b88f92d6e7 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Thu, 10 Aug 2017 15:28:51 -0700 Subject: [PATCH] Deprecate vectorized Dates.format methods in favor of compact broadcast syntax. --- NEWS.md | 4 ++-- base/dates/io.jl | 8 -------- base/deprecated.jl | 8 +++++++- test/dates/io.jl | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index fde4ae5f462fa..d44e04e7946d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -299,8 +299,8 @@ 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` and `Date` methods have been deprecated in favor of dot-syntax - ([#CATS]). + * Vectorized `DateTime`, `Date`, and `format` methods have been deprecated in favor of + dot-syntax ([#CATS]). * `Base.cpad` has been removed; use an appropriate combination of `rpad` and `lpad` instead ([#23187]). diff --git a/base/dates/io.jl b/base/dates/io.jl index aa0711d2b3fbb..78f9ef4bb5346 100644 --- a/base/dates/io.jl +++ b/base/dates/io.jl @@ -557,11 +557,3 @@ function Base.string(dt::Date) dd = lpad(d, 2, "0") return "$yy-$mm-$dd" end - -# vectorized -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 577b8e1afdae8..323e378138e2a 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1584,7 +1584,7 @@ for op in (:exp, :exp2, :exp10, :log, :log2, :log10, @eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x) end -# deprecate reamining vectorized methods from Base.Dates +# deprecate remaining vectorized methods from Base.Dates @eval Dates @deprecate( DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH), DateTime.(Y, f; locale=locale) ) @@ -1597,6 +1597,12 @@ end @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 diff --git a/test/dates/io.jl b/test/dates/io.jl index fe267361a7955..d37bda2462ffa 100644 --- a/test/dates/io.jl +++ b/test/dates/io.jl @@ -328,8 +328,7 @@ dr2 = [Dates.Date(2000) : Dates.Date(2000, 1, 10);] @test Dates.DateTime.(dr) == Dates.DateTime.(dr2) @test Dates.DateTime.(dr, "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}