From 8357a1c0e91edececa842683d906869cb72b4c08 Mon Sep 17 00:00:00 2001 From: Aron Hofer Date: Fri, 15 Sep 2017 14:19:27 -0500 Subject: [PATCH 1/2] DateTime() Date() Time() are deprecated. Will be `now` in future release. --- NEWS.md | 4 ++++ stdlib/Dates/src/deprecated.jl | 4 ++++ stdlib/Dates/src/types.jl | 7 +++++++ stdlib/Dates/test/types.jl | 10 ++++++++++ 4 files changed, 25 insertions(+) diff --git a/NEWS.md b/NEWS.md index 78dcc3caaaa0d..5e93b58447b8a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -970,6 +970,10 @@ Deprecated or removed * `Base.@gc_preserve` has been deprecated in favor of `GC.@preserve` ([#25616]). + * `DateTime()`, `Date()`, and `Time()` have been deprecated, instead use `DateTime(1)`, `Date(1)` + and `Time(0)` respectively. In a future release `DateTime()`, `Date()`, and `Time()` will be + alternatives to `now()` ([#23724]). + Command-line option changes --------------------------- diff --git a/stdlib/Dates/src/deprecated.jl b/stdlib/Dates/src/deprecated.jl index 70ff46de8dd38..8916633ecd26f 100644 --- a/stdlib/Dates/src/deprecated.jl +++ b/stdlib/Dates/src/deprecated.jl @@ -41,3 +41,7 @@ import Base.range @deprecate range(start::DateTime, len::Integer) range(start, Day(1), len) false @deprecate range(start::Date, len::Integer) range(start, Day(1), len) false +# PR #23724 +@deprecate DateTime() DateTime(1) +@deprecate Date() Date(1) +@deprecate Time() Time(0) diff --git a/stdlib/Dates/src/types.jl b/stdlib/Dates/src/types.jl index bb856d790baf0..a20eaf58648a8 100644 --- a/stdlib/Dates/src/types.jl +++ b/stdlib/Dates/src/types.jl @@ -314,6 +314,13 @@ DateTime(y, m=1, d=1, h=0, mi=0, s=0, ms=0) = DateTime(Int64(y), Int64(m), Int64 Date(y, m=1, d=1) = Date(Int64(y), Int64(m), Int64(d)) Time(h, mi=0, s=0, ms=0, us=0, ns=0) = Time(Int64(h), Int64(mi), Int64(s), Int64(ms), Int64(us), Int64(ns)) +# Empty constructors default to 'now' +if VERSION >= v"0.8-" + DateTime() = now() + Date() = today() + Time() = Time(now()) +end + # Traits, Equality Base.isfinite(::Union{Type{T}, T}) where {T<:TimeType} = true calendar(dt::DateTime) = ISOCalendar diff --git a/stdlib/Dates/test/types.jl b/stdlib/Dates/test/types.jl index 1f78f92e56643..c4abe8d8d72a5 100644 --- a/stdlib/Dates/test/types.jl +++ b/stdlib/Dates/test/types.jl @@ -110,6 +110,16 @@ end @test Dates.Time(Dates.Hour(4), Dates.Second(10), Dates.Millisecond(15), Dates.Microsecond(20), Dates.Nanosecond(25)) == Dates.Time(4, 0, 10, 15, 20, 25) end + +@testset "empty constructors" begin + if VERSION >= v"0.8-" + present = now() + @test Dates.DateTime(present) <= Dates.DateTime() + @test Dates.Date(present) <= Dates.Date() + @test Dates.Time(present) <= Dates.Time() + end +end + @testset "various input types for Date/DateTime" begin test = Dates.Date(1, 1, 1) @test Dates.Date(Int8(1), Int8(1), Int8(1)) == test From 3b8c9d37ab0ad0a37d7222825af98aecd78bcf7c Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 18 Sep 2017 10:03:01 +0200 Subject: [PATCH 2/2] remove potential future implementation of DateTime(), Date() and Time() --- NEWS.md | 3 +-- stdlib/Dates/docs/src/index.md | 6 +++--- stdlib/Dates/src/types.jl | 19 ++++++------------- stdlib/Dates/test/types.jl | 9 --------- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5e93b58447b8a..32b2d4b7de818 100644 --- a/NEWS.md +++ b/NEWS.md @@ -971,8 +971,7 @@ Deprecated or removed * `Base.@gc_preserve` has been deprecated in favor of `GC.@preserve` ([#25616]). * `DateTime()`, `Date()`, and `Time()` have been deprecated, instead use `DateTime(1)`, `Date(1)` - and `Time(0)` respectively. In a future release `DateTime()`, `Date()`, and `Time()` will be - alternatives to `now()` ([#23724]). + and `Time(0)` respectively ([#23724]). Command-line option changes --------------------------- diff --git a/stdlib/Dates/docs/src/index.md b/stdlib/Dates/docs/src/index.md index 2ba47fdb1204a..40852affcdd69 100644 --- a/stdlib/Dates/docs/src/index.md +++ b/stdlib/Dates/docs/src/index.md @@ -23,7 +23,7 @@ Dates.Time ```@docs Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64) -Dates.DateTime(::Dates.Period...) +Dates.DateTime(::Dates.Period) Dates.DateTime(::Function, ::Any...) Dates.DateTime(::Dates.TimeType) Dates.DateTime(::AbstractString, ::AbstractString) @@ -32,13 +32,13 @@ Dates.DateFormat Dates.@dateformat_str Dates.DateTime(::AbstractString, ::Dates.DateFormat) Dates.Date(::Int64, ::Int64, ::Int64) -Dates.Date(::Dates.Period...) +Dates.Date(::Dates.Period) Dates.Date(::Function, ::Any, ::Any, ::Any) Dates.Date(::Dates.TimeType) Dates.Date(::AbstractString, ::AbstractString) Dates.Date(::AbstractString, ::Dates.DateFormat) Dates.Time(::Int64::Int64, ::Int64, ::Int64, ::Int64, ::Int64) -Dates.Time(::Dates.TimePeriod...) +Dates.Time(::Dates.TimePeriod) Dates.Time(::Function, ::Any...) Dates.Time(::Dates.DateTime) Dates.now() diff --git a/stdlib/Dates/src/types.jl b/stdlib/Dates/src/types.jl index a20eaf58648a8..5984e8ecb0519 100644 --- a/stdlib/Dates/src/types.jl +++ b/stdlib/Dates/src/types.jl @@ -258,10 +258,10 @@ end Construct a `DateTime` type by `Period` type parts. Arguments may be in any order. DateTime parts not provided will default to the value of `Dates.default(period)`. """ -function DateTime(periods::Period...) +function DateTime(period::Period, periods::Period...) y = Year(1); m = Month(1); d = Day(1) h = Hour(0); mi = Minute(0); s = Second(0); ms = Millisecond(0) - for p in periods + for p in (period, periods...) isa(p, Year) && (y = p::Year) isa(p, Month) && (m = p::Month) isa(p, Day) && (d = p::Day) @@ -279,9 +279,9 @@ end Construct a `Date` type by `Period` type parts. Arguments may be in any order. `Date` parts not provided will default to the value of `Dates.default(period)`. """ -function Date(periods::Period...) +function Date(period::Period, periods::Period...) y = Year(1); m = Month(1); d = Day(1) - for p in periods + for p in (period, periods...) isa(p, Year) && (y = p::Year) isa(p, Month) && (m = p::Month) isa(p, Day) && (d = p::Day) @@ -295,10 +295,10 @@ end Construct a `Time` type by `Period` type parts. Arguments may be in any order. `Time` parts not provided will default to the value of `Dates.default(period)`. """ -function Time(periods::TimePeriod...) +function Time(period::TimePeriod, periods::TimePeriod...) h = Hour(0); mi = Minute(0); s = Second(0) ms = Millisecond(0); us = Microsecond(0); ns = Nanosecond(0) - for p in periods + for p in (period, periods...) isa(p, Hour) && (h = p::Hour) isa(p, Minute) && (mi = p::Minute) isa(p, Second) && (s = p::Second) @@ -314,13 +314,6 @@ DateTime(y, m=1, d=1, h=0, mi=0, s=0, ms=0) = DateTime(Int64(y), Int64(m), Int64 Date(y, m=1, d=1) = Date(Int64(y), Int64(m), Int64(d)) Time(h, mi=0, s=0, ms=0, us=0, ns=0) = Time(Int64(h), Int64(mi), Int64(s), Int64(ms), Int64(us), Int64(ns)) -# Empty constructors default to 'now' -if VERSION >= v"0.8-" - DateTime() = now() - Date() = today() - Time() = Time(now()) -end - # Traits, Equality Base.isfinite(::Union{Type{T}, T}) where {T<:TimeType} = true calendar(dt::DateTime) = ISOCalendar diff --git a/stdlib/Dates/test/types.jl b/stdlib/Dates/test/types.jl index c4abe8d8d72a5..6b7f148872fe9 100644 --- a/stdlib/Dates/test/types.jl +++ b/stdlib/Dates/test/types.jl @@ -111,15 +111,6 @@ end Dates.Microsecond(20), Dates.Nanosecond(25)) == Dates.Time(4, 0, 10, 15, 20, 25) end -@testset "empty constructors" begin - if VERSION >= v"0.8-" - present = now() - @test Dates.DateTime(present) <= Dates.DateTime() - @test Dates.Date(present) <= Dates.Date() - @test Dates.Time(present) <= Dates.Time() - end -end - @testset "various input types for Date/DateTime" begin test = Dates.Date(1, 1, 1) @test Dates.Date(Int8(1), Int8(1), Int8(1)) == test