Skip to content

Commit

Permalink
remove potential future implementation of DateTime(), Date() and Time()
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 18, 2017
1 parent 0a0c63f commit bb8a604
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
3 changes: 1 addition & 2 deletions NEWS.md
Expand Up @@ -450,8 +450,7 @@ Deprecated or removed
the `allow_prompt` keyword in the `LibGit2.CredentialPayload` constructor ([#23690]).

* `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
---------------------------
Expand Down
19 changes: 6 additions & 13 deletions base/dates/types.jl
Expand Up @@ -256,10 +256,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 @@ -277,9 +277,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 @@ -293,10 +293,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 All @@ -312,13 +312,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
Expand Down
8 changes: 0 additions & 8 deletions test/dates/types.jl
Expand Up @@ -58,14 +58,6 @@ t = Dates.Time(Dates.Nanosecond(82800000000000))
@test Dates.Time(23, 0, 0, 0, 0) == t
@test Dates.Time(23, 0, 0, 0, 0, 0) == t

# Test empty constructors now equivalence
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

# Test various input types for Date/DateTime
test = Dates.Date(1, 1, 1)
@test Dates.Date(Int8(1), Int8(1), Int8(1)) == test
Expand Down

0 comments on commit bb8a604

Please sign in to comment.