Skip to content

Commit

Permalink
DateTime() Date() Time() are deprecated.
Browse files Browse the repository at this point in the history
Will be `now` in future release.
  • Loading branch information
a-hofer committed Jan 19, 2018
1 parent 625923f commit 8357a1c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------

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)
7 changes: 7 additions & 0 deletions stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8357a1c

Please sign in to comment.