Skip to content

Commit b0f0b2f

Browse files
committed
Revert "Fix repr on DateTime (#30200)"
This reverts commit 8d8b3d9. Conflicts: NEWS.md
1 parent c2af5ca commit b0f0b2f

File tree

4 files changed

+26
-62
lines changed

4 files changed

+26
-62
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: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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):1 day: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):1 month: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 & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -580,48 +580,14 @@ end
580580
# show
581581

582582
function Base.show(io::IO, dt::DateTime)
583-
if get(io, :compact, false)
584-
print(io, dt)
585-
else
586-
y,m,d = yearmonthday(dt)
587-
h = hour(dt)
588-
mi = minute(dt)
589-
s = second(dt)
590-
ms = millisecond(dt)
591-
if ms == 0
592-
print(io, "DateTime($y, $m, $d, $h, $mi, $s)")
593-
else
594-
print(io, "DateTime($y, $m, $d, $h, $mi, $s, $ms)")
595-
end
596-
end
597-
end
598-
599-
function Base.show(io::IO, ::MIME"text/plain", dt::DateTime)
600-
print(io, dt)
601-
end
602-
603-
function Base.show(io::IO, ::MIME"text/plain", dt::Date)
604-
print(io, dt)
605-
end
606-
607-
function Base.show(io::IO, dt::Date)
608-
if get(io, :compact, false)
609-
print(io, dt)
610-
else
611-
y,m,d = yearmonthday(dt)
612-
print(io, "Date($y, $m, $d)")
613-
end
614-
end
615-
616-
function Base.print(io::IO, dt::DateTime)
617583
if millisecond(dt) == 0
618584
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS")
619585
else
620586
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS.s")
621587
end
622588
end
623589

624-
function Base.print(io::IO, dt::Date)
590+
function Base.show(io::IO, dt::Date)
625591
format(io, dt, dateformat"YYYY-mm-dd")
626592
end
627593

stdlib/Dates/test/io.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Dates
77

88
@testset "string/show representation of Date" begin
99
@test string(Dates.Date(1, 1, 1)) == "0001-01-01" # January 1st, 1 AD/CE
10-
@test sprint(show, Dates.Date(1, 1, 1)) == "Date(1, 1, 1)"
10+
@test sprint(show, Dates.Date(1, 1, 1)) == "0001-01-01"
1111
@test string(Dates.Date(0, 12, 31)) == "0000-12-31" # December 31, 1 BC/BCE
1212
@test Dates.Date(1, 1, 1) - Dates.Date(0, 12, 31) == Dates.Day(1)
1313
@test Dates.Date(Dates.UTD(-306)) == Dates.Date(0, 2, 29)
@@ -16,7 +16,7 @@ using Dates
1616
@test string(Dates.Date(-1000000, 1, 1)) == "-1000000-01-01"
1717
@test string(Dates.Date(1000000, 1, 1)) == "1000000-01-01"
1818
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
19-
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "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"
2020
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 2)) == "2000-01-01T00:00:00.002"
2121
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 500)) == "2000-01-01T00:00:00.5"
2222
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 998)) == "2000-01-01T00:00:00.998"

0 commit comments

Comments
 (0)