Skip to content

Commit

Permalink
Revert "Fix repr on DateTime (JuliaLang#30200)"
Browse files Browse the repository at this point in the history
This reverts commit 8d8b3d9.

Conflicts:
	NEWS.md
  • Loading branch information
JeffBezanson committed Dec 16, 2019
1 parent c2af5ca commit b0f0b2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 62 deletions.
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Standard library changes

#### Statistics


#### Sockets


Expand Down
47 changes: 23 additions & 24 deletions stdlib/Dates/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,29 +400,29 @@ As a bonus, all period arithmetic objects work directly with ranges:

```jldoctest
julia> dr = Date(2014,1,29):Day(1):Date(2014,2,3)
Date(2014, 1, 29):1 day:Date(2014, 2, 3)
2014-01-29:1 day:2014-02-03
julia> collect(dr)
6-element Array{Date,1}:
Date(2014, 1, 29)
Date(2014, 1, 30)
Date(2014, 1, 31)
Date(2014, 2, 1)
Date(2014, 2, 2)
Date(2014, 2, 3)
2014-01-29
2014-01-30
2014-01-31
2014-02-01
2014-02-02
2014-02-03
julia> dr = Date(2014,1,29):Dates.Month(1):Date(2014,07,29)
Date(2014, 1, 29):1 month:Date(2014, 7, 29)
2014-01-29:1 month:2014-07-29
julia> collect(dr)
7-element Array{Date,1}:
Date(2014, 1, 29)
Date(2014, 2, 28)
Date(2014, 3, 29)
Date(2014, 4, 29)
Date(2014, 5, 29)
Date(2014, 6, 29)
Date(2014, 7, 29)
2014-01-29
2014-02-28
2014-03-29
2014-04-29
2014-05-29
2014-06-29
2014-07-29
```

## Adjuster Functions
Expand Down Expand Up @@ -492,15 +492,14 @@ julia> filter(dr) do x
Dates.dayofweekofmonth(x) == 2
end
8-element Array{Date,1}:
Date(2014, 4, 8)
Date(2014, 5, 13)
Date(2014, 6, 10)
Date(2014, 7, 8)
Date(2014, 8, 12)
Date(2014, 9, 9)
Date(2014, 10, 14)
Date(2014, 11, 11)
2014-04-08
2014-05-13
2014-06-10
2014-07-08
2014-08-12
2014-09-09
2014-10-14
2014-11-11
```

Additional examples and tests are available in [`stdlib/Dates/test/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/adjusters.jl).
Expand Down
36 changes: 1 addition & 35 deletions stdlib/Dates/src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -580,48 +580,14 @@ end
# show

function Base.show(io::IO, dt::DateTime)
if get(io, :compact, false)
print(io, dt)
else
y,m,d = yearmonthday(dt)
h = hour(dt)
mi = minute(dt)
s = second(dt)
ms = millisecond(dt)
if ms == 0
print(io, "DateTime($y, $m, $d, $h, $mi, $s)")
else
print(io, "DateTime($y, $m, $d, $h, $mi, $s, $ms)")
end
end
end

function Base.show(io::IO, ::MIME"text/plain", dt::DateTime)
print(io, dt)
end

function Base.show(io::IO, ::MIME"text/plain", dt::Date)
print(io, dt)
end

function Base.show(io::IO, dt::Date)
if get(io, :compact, false)
print(io, dt)
else
y,m,d = yearmonthday(dt)
print(io, "Date($y, $m, $d)")
end
end

function Base.print(io::IO, dt::DateTime)
if millisecond(dt) == 0
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS")
else
format(io, dt, dateformat"YYYY-mm-dd\THH:MM:SS.s")
end
end

function Base.print(io::IO, dt::Date)
function Base.show(io::IO, dt::Date)
format(io, dt, dateformat"YYYY-mm-dd")
end

Expand Down
4 changes: 2 additions & 2 deletions stdlib/Dates/test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Dates

@testset "string/show representation of Date" begin
@test string(Dates.Date(1, 1, 1)) == "0001-01-01" # January 1st, 1 AD/CE
@test sprint(show, Dates.Date(1, 1, 1)) == "Date(1, 1, 1)"
@test sprint(show, Dates.Date(1, 1, 1)) == "0001-01-01"
@test string(Dates.Date(0, 12, 31)) == "0000-12-31" # December 31, 1 BC/BCE
@test Dates.Date(1, 1, 1) - Dates.Date(0, 12, 31) == Dates.Day(1)
@test Dates.Date(Dates.UTD(-306)) == Dates.Date(0, 2, 29)
Expand All @@ -16,7 +16,7 @@ using Dates
@test string(Dates.Date(-1000000, 1, 1)) == "-1000000-01-01"
@test string(Dates.Date(1000000, 1, 1)) == "1000000-01-01"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "DateTime(2000, 1, 1, 0, 0, 0, 1)"
@test sprint(show, Dates.DateTime(2000, 1, 1, 0, 0, 0, 1)) == "2000-01-01T00:00:00.001"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 2)) == "2000-01-01T00:00:00.002"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 500)) == "2000-01-01T00:00:00.5"
@test string(Dates.DateTime(2000, 1, 1, 0, 0, 0, 998)) == "2000-01-01T00:00:00.998"
Expand Down

0 comments on commit b0f0b2f

Please sign in to comment.