Skip to content

Commit

Permalink
Merge pull request JuliaLang#23724 from invenia/ah/EmptyDatesNow
Browse files Browse the repository at this point in the history
Deprecate DateTime() Date() Time()
  • Loading branch information
omus committed Jan 23, 2018
2 parents dcb0517 + 3b8c9d3 commit 1888eb6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ 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 ([#23724]).

Command-line option changes
---------------------------

Expand Down
6 changes: 3 additions & 3 deletions stdlib/Dates/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions stdlib/Dates/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ 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 "various input types for Date/DateTime" begin
test = Dates.Date(1, 1, 1)
@test Dates.Date(Int8(1), Int8(1), Int8(1)) == test
Expand Down

0 comments on commit 1888eb6

Please sign in to comment.