diff --git a/NEWS.md b/NEWS.md index 08194c862fc6a..cea01c38acaf1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -94,7 +94,6 @@ Standard library changes #### Dates * `DateTime` and `Time` formatting/parsing now supports 12-hour clocks with AM/PM via `I` and `p` codes, similar to `strftime` ([#32308]). -* Fixed `repr` such that it displays `Time` as it would be entered in Julia ([#32103]). #### Statistics diff --git a/stdlib/Dates/docs/src/index.md b/stdlib/Dates/docs/src/index.md index 80d3c366f9988..c248742f49b7b 100644 --- a/stdlib/Dates/docs/src/index.md +++ b/stdlib/Dates/docs/src/index.md @@ -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 @@ -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). diff --git a/stdlib/Dates/src/io.jl b/stdlib/Dates/src/io.jl index ab86ab90ebdb3..51b5f7838769b 100644 --- a/stdlib/Dates/src/io.jl +++ b/stdlib/Dates/src/io.jl @@ -580,40 +580,6 @@ 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 @@ -621,7 +587,7 @@ function Base.print(io::IO, dt::DateTime) end end -function Base.print(io::IO, dt::Date) +function Base.show(io::IO, dt::Date) format(io, dt, dateformat"YYYY-mm-dd") end diff --git a/stdlib/Dates/test/io.jl b/stdlib/Dates/test/io.jl index f317c65fbf9dc..3c30ade1e1e2e 100644 --- a/stdlib/Dates/test/io.jl +++ b/stdlib/Dates/test/io.jl @@ -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) @@ -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"