Skip to content

Commit c2af5ca

Browse files
committed
Revert "Fix repr on Period Types, and DateTime, Date (#30817)"
This reverts commit a7fabc9.
1 parent 14250f7 commit c2af5ca

File tree

4 files changed

+10
-70
lines changed

4 files changed

+10
-70
lines changed

stdlib/Dates/docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ Date
244244
value: Int64 735264
245245
246246
julia> t.instant
247-
Dates.UTInstant{Day}(Day(735264))
247+
Dates.UTInstant{Day}(735264 days)
248248
249249
julia> Dates.value(t)
250250
735264
@@ -400,7 +400,7 @@ As a bonus, all period arithmetic objects work directly with ranges:
400400

401401
```jldoctest
402402
julia> dr = Date(2014,1,29):Day(1):Date(2014,2,3)
403-
Date(2014, 1, 29):Day(1):Date(2014, 2, 3)
403+
Date(2014, 1, 29):1 day:Date(2014, 2, 3)
404404
405405
julia> collect(dr)
406406
6-element Array{Date,1}:
@@ -412,7 +412,7 @@ julia> collect(dr)
412412
Date(2014, 2, 3)
413413
414414
julia> dr = Date(2014,1,29):Dates.Month(1):Date(2014,07,29)
415-
Date(2014, 1, 29):Month(1):Date(2014, 7, 29)
415+
Date(2014, 1, 29):1 month:Date(2014, 7, 29)
416416
417417
julia> collect(dr)
418418
7-element Array{Date,1}:

stdlib/Dates/src/io.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,6 @@ end
579579

580580
# show
581581

582-
function Base.show(io::IO, p::P) where P <: Period
583-
if get(io, :compact, false)
584-
print(io, p)
585-
else
586-
print(io, P, '(', p.value, ')')
587-
end
588-
end
589-
590582
function Base.show(io::IO, dt::DateTime)
591583
if get(io, :compact, false)
592584
print(io, dt)
@@ -597,9 +589,9 @@ function Base.show(io::IO, dt::DateTime)
597589
s = second(dt)
598590
ms = millisecond(dt)
599591
if ms == 0
600-
print(io, DateTime, "($y, $m, $d, $h, $mi, $s)")
592+
print(io, "DateTime($y, $m, $d, $h, $mi, $s)")
601593
else
602-
print(io, DateTime, "($y, $m, $d, $h, $mi, $s, $ms)")
594+
print(io, "DateTime($y, $m, $d, $h, $mi, $s, $ms)")
603595
end
604596
end
605597
end
@@ -617,7 +609,7 @@ function Base.show(io::IO, dt::Date)
617609
print(io, dt)
618610
else
619611
y,m,d = yearmonthday(dt)
620-
print(io, Date, "($y, $m, $d)")
612+
print(io, "Date($y, $m, $d)")
621613
end
622614
end
623615

stdlib/Dates/src/periods.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ for period in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond
4545
end
4646

4747
#Print/show/traits
48-
Base.print(io::IO, p::Period) = print(io, value(p), _units(p))
49-
Base.show(io::IO, ::MIME"text/plain", p::Period) = print(io, p)
48+
Base.string(x::Period) = string(value(x), _units(x))
49+
Base.show(io::IO,x::Period) = print(io, string(x))
5050
Base.zero(::Union{Type{P},P}) where {P<:Period} = P(0)
5151
Base.one(::Union{Type{P},P}) where {P<:Period} = 1 # see #16116
5252
Base.typemin(::Type{P}) where {P<:Period} = P(typemin(Int64))

stdlib/Dates/test/io.jl

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,9 @@ module IOTests
55
using Test
66
using Dates
77

8-
@testset "string/show representation of Period" begin
9-
@test string(Dates.Year(2018)) == "2018 years"
10-
@test sprint(show, Dates.Year(2018)) == "Dates.Year(2018)"
11-
@test sprint(print, Dates.Year(2018)) == "2018 years"
12-
@test repr(Dates.Year(2018)) == "Dates.Year(2018)"
13-
14-
@test string(Dates.Month(12)) == "12 months"
15-
@test sprint(show, Dates.Month(12)) == "Dates.Month(12)"
16-
@test sprint(print, Dates.Month(12)) == "12 months"
17-
@test repr(Dates.Month(12)) == "Dates.Month(12)"
18-
19-
@test string(Dates.Week(4)) == "4 weeks"
20-
@test sprint(show, Dates.Week(4)) == "Dates.Week(4)"
21-
@test sprint(print, Dates.Week(4)) == "4 weeks"
22-
@test repr(Dates.Week(4)) == "Dates.Week(4)"
23-
24-
@test string(Dates.Day(12)) == "12 days"
25-
@test sprint(show, Dates.Day(12)) == "Dates.Day(12)"
26-
@test sprint(print,Dates.Day(12)) == "12 days"
27-
@test repr(Dates.Day(12)) == "Dates.Day(12)"
28-
29-
@test string(Dates.Hour(12)) == "12 hours"
30-
@test sprint(show, Dates.Hour(12)) == "Dates.Hour(12)"
31-
@test sprint(print,Dates.Hour(12)) == "12 hours"
32-
@test repr(Dates.Hour(12)) == "Dates.Hour(12)"
33-
34-
@test string(Dates.Minute(12)) == "12 minutes"
35-
@test sprint(show, Dates.Minute(12)) == "Dates.Minute(12)"
36-
@test sprint(print,Dates.Minute(12)) == "12 minutes"
37-
@test repr(Dates.Minute(12)) == "Dates.Minute(12)"
38-
39-
@test string(Dates.Second(12)) == "12 seconds"
40-
@test sprint(show, Dates.Second(12)) == "Dates.Second(12)"
41-
@test sprint(print,Dates.Second(12)) == "12 seconds"
42-
@test repr(Dates.Second(12)) == "Dates.Second(12)"
43-
44-
@test string(Dates.Millisecond(12)) == "12 milliseconds"
45-
@test sprint(show, Dates.Millisecond(12)) == "Dates.Millisecond(12)"
46-
@test sprint(print,Dates.Millisecond(12)) == "12 milliseconds"
47-
@test repr(Dates.Millisecond(12)) == "Dates.Millisecond(12)"
48-
49-
@test string(Dates.Microsecond(12)) == "12 microseconds"
50-
@test sprint(show, Dates.Microsecond(12)) == "Dates.Microsecond(12)"
51-
@test sprint(print,Dates.Microsecond(12)) == "12 microseconds"
52-
@test repr(Dates.Microsecond(12)) == "Dates.Microsecond(12)"
53-
54-
@test string(Dates.Nanosecond(12)) == "12 nanoseconds"
55-
@test sprint(show, Dates.Nanosecond(12)) == "Dates.Nanosecond(12)"
56-
@test sprint(print,Dates.Nanosecond(12)) == "12 nanoseconds"
57-
@test repr(Dates.Nanosecond(12)) == "Dates.Nanosecond(12)"
58-
end
59-
608
@testset "string/show representation of Date" begin
619
@test string(Dates.Date(1, 1, 1)) == "0001-01-01" # January 1st, 1 AD/CE
62-
@test sprint(show, Dates.Date(1, 1, 1)) == "Dates.Date(1, 1, 1)"
10+
@test sprint(show, Dates.Date(1, 1, 1)) == "Date(1, 1, 1)"
6311
@test string(Dates.Date(0, 12, 31)) == "0000-12-31" # December 31, 1 BC/BCE
6412
@test Dates.Date(1, 1, 1) - Dates.Date(0, 12, 31) == Dates.Day(1)
6513
@test Dates.Date(Dates.UTD(-306)) == Dates.Date(0, 2, 29)
@@ -68,7 +16,7 @@ end
6816
@test string(Dates.Date(-1000000, 1, 1)) == "-1000000-01-01"
6917
@test string(Dates.Date(1000000, 1, 1)) == "1000000-01-01"
7018
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
71-
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)"
19+
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "DateTime(2000, 1, 1, 0, 0, 0, 1)"
7220
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 2)) == "2000-01-01T00:00:00.002"
7321
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 500)) == "2000-01-01T00:00:00.5"
7422
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 998)) == "2000-01-01T00:00:00.998"

0 commit comments

Comments
 (0)