Skip to content

Commit 257907d

Browse files
authored
Merge pull request #34116 from JuliaLang/jb/revert_date2
revert date printing changes
2 parents aa07c1c + b0f0b2f commit 257907d

File tree

5 files changed

+29
-125
lines changed

5 files changed

+29
-125
lines changed

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ Standard library changes
101101

102102
#### Statistics
103103

104-
105104
#### Sockets
106105

107106

stdlib/Dates/docs/src/index.md

Lines changed: 24 additions & 25 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,29 +400,29 @@ 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+
2014-01-29:1 day:2014-02-03
404404
405405
julia> collect(dr)
406406
6-element Array{Date,1}:
407-
Date(2014, 1, 29)
408-
Date(2014, 1, 30)
409-
Date(2014, 1, 31)
410-
Date(2014, 2, 1)
411-
Date(2014, 2, 2)
412-
Date(2014, 2, 3)
407+
2014-01-29
408+
2014-01-30
409+
2014-01-31
410+
2014-02-01
411+
2014-02-02
412+
2014-02-03
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+
2014-01-29:1 month:2014-07-29
416416
417417
julia> collect(dr)
418418
7-element Array{Date,1}:
419-
Date(2014, 1, 29)
420-
Date(2014, 2, 28)
421-
Date(2014, 3, 29)
422-
Date(2014, 4, 29)
423-
Date(2014, 5, 29)
424-
Date(2014, 6, 29)
425-
Date(2014, 7, 29)
419+
2014-01-29
420+
2014-02-28
421+
2014-03-29
422+
2014-04-29
423+
2014-05-29
424+
2014-06-29
425+
2014-07-29
426426
```
427427

428428
## Adjuster Functions
@@ -492,15 +492,14 @@ julia> filter(dr) do x
492492
Dates.dayofweekofmonth(x) == 2
493493
end
494494
8-element Array{Date,1}:
495-
Date(2014, 4, 8)
496-
Date(2014, 5, 13)
497-
Date(2014, 6, 10)
498-
Date(2014, 7, 8)
499-
Date(2014, 8, 12)
500-
Date(2014, 9, 9)
501-
Date(2014, 10, 14)
502-
Date(2014, 11, 11)
503-
495+
2014-04-08
496+
2014-05-13
497+
2014-06-10
498+
2014-07-08
499+
2014-08-12
500+
2014-09-09
501+
2014-10-14
502+
2014-11-11
504503
```
505504

506505
Additional examples and tests are available in [`stdlib/Dates/test/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/adjusters.jl).

stdlib/Dates/src/io.jl

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -579,57 +579,15 @@ 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)
591-
if get(io, :compact, false)
592-
print(io, dt)
593-
else
594-
y,m,d = yearmonthday(dt)
595-
h = hour(dt)
596-
mi = minute(dt)
597-
s = second(dt)
598-
ms = millisecond(dt)
599-
if ms == 0
600-
print(io, DateTime, "($y, $m, $d, $h, $mi, $s)")
601-
else
602-
print(io, DateTime, "($y, $m, $d, $h, $mi, $s, $ms)")
603-
end
604-
end
605-
end
606-
607-
function Base.show(io::IO, ::MIME"text/plain", dt::DateTime)
608-
print(io, dt)
609-
end
610-
611-
function Base.show(io::IO, ::MIME"text/plain", dt::Date)
612-
print(io, dt)
613-
end
614-
615-
function Base.show(io::IO, dt::Date)
616-
if get(io, :compact, false)
617-
print(io, dt)
618-
else
619-
y,m,d = yearmonthday(dt)
620-
print(io, Date, "($y, $m, $d)")
621-
end
622-
end
623-
624-
function Base.print(io::IO, dt::DateTime)
625583
if millisecond(dt) == 0
626584
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS")
627585
else
628586
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS.s")
629587
end
630588
end
631589

632-
function Base.print(io::IO, dt::Date)
590+
function Base.show(io::IO, dt::Date)
633591
format(io, dt, dateformat"YYYY-mm-dd")
634592
end
635593

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)) == "0001-01-01"
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)) == "2000-01-01T00:00:00.001"
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)