Skip to content

Commit

Permalink
Add zero for TimeType (#35554)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugomez authored Apr 23, 2020
1 parent b00d544 commit 3a06a2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Standard library changes

#### Dates
* The `eps` function now accepts `TimeType` types ([#31487]).
* The `zero` function now accepts `TimeType` types ([#35554]).


#### Statistics

Expand Down
6 changes: 6 additions & 0 deletions stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ Base.eps(::Type{Date}) = Day(1)
Base.eps(::Type{Time}) = Nanosecond(1)
Base.eps(::T) where T <: TimeType = eps(T)::Period

# zero returns dt::T - dt::T
Base.zero(::Type{DateTime}) = Millisecond(0)
Base.zero(::Type{Date}) = Day(0)
Base.zero(::Type{Time}) = Nanosecond(0)
Base.zero(::T) where T <: TimeType = zero(T)::Period


Base.typemax(::Union{DateTime, Type{DateTime}}) = DateTime(146138512, 12, 31, 23, 59, 59)
Base.typemin(::Union{DateTime, Type{DateTime}}) = DateTime(-146138511, 1, 1, 0, 0, 0)
Expand Down
6 changes: 6 additions & 0 deletions stdlib/Dates/test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ c = Dates.Time(0)
@test eps(a) == Dates.Millisecond(1)
@test eps(b) == Dates.Day(1)
@test eps(c) == Dates.Nanosecond(1)
@test zero(DateTime) == Dates.Millisecond(0)
@test zero(Date) == Dates.Day(0)
@test zero(Time) == Dates.Nanosecond(0)
@test zero(a) == Dates.Millisecond(0)
@test zero(b) == Dates.Day(0)
@test zero(c) == Dates.Nanosecond(0)
@test string(typemax(Dates.DateTime)) == "146138512-12-31T23:59:59"
@test string(typemin(Dates.DateTime)) == "-146138511-01-01T00:00:00"
@test typemax(Dates.DateTime) - typemin(Dates.DateTime) == Dates.Millisecond(9223372017043199000)
Expand Down

0 comments on commit 3a06a2e

Please sign in to comment.