Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using repr on DateTime shows pretty-printed version #29909

Closed
omus opened this issue Nov 2, 2018 · 9 comments · Fixed by #30200
Closed

Using repr on DateTime shows pretty-printed version #29909

omus opened this issue Nov 2, 2018 · 9 comments · Fixed by #30200
Labels
dates Dates, times, and the Dates stdlib module display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia

Comments

@omus
Copy link
Member

omus commented Nov 2, 2018

According to the docstring for repr:

Note that repr(x) is usually similar to how the value of x would be entered in Julia

Unfortunately this is not the behaviour of Date and DateTime:

julia> using Dates

julia> x = Date(2018)
2018-01-01

julia> repr(x)
"2018-01-01"

julia> y = DateTime(2018)
2018-01-01T00:00:00

julia> repr(y)
"2018-01-01T00:00:00"
@omus omus added the dates Dates, times, and the Dates stdlib module label Nov 2, 2018
@omus
Copy link
Member Author

omus commented Nov 2, 2018

cc: @quinnj

@omus
Copy link
Member Author

omus commented Nov 2, 2018

I'll note that I thought of this based upon a comment @JeffBezanson made on discourse.

@StefanKarpinski
Copy link
Member

Yeah, this is not the desired behavior—it should print the way you input it.

@ararslan ararslan added the display and printing Aesthetics and correctness of printed representations of objects. label Nov 2, 2018
@quinnj
Copy link
Member

quinnj commented Nov 3, 2018

Yeah, looks like TimeTypes are just hitting the default path which calls show. Should be an easy up-for-grabs if anyone wants to take a crack at it.

@quinnj quinnj added the good first issue Indicates a good issue for first-time contributors to Julia label Nov 3, 2018
@p-murli
Copy link

p-murli commented Nov 13, 2018

Hey, I'd like to contribute to this if it is open. I'm a beginner, so could you also guide me on how to get started with this issue?

@omus
Copy link
Member Author

omus commented Nov 14, 2018

Hi @p-murli. To get started you should take a look at the code that the Dates stdlib uses for show and string. You can do that easily by running using Dates; @edit show(stdout, today()). I think what we want is to have the current show methods be print methods instead and add some new show methods. The end result should look like:

julia> using Dates

julia> d = Date(2018)
2018-01-01

julia> print(d)
2018-01-01
julia> string(d)
"2018-01-01"

julia> show(d)
Date(2018, 1, 1)

julia> repr(d)
"Date(2018, 1, 1)"

I'll mention that the repr method calls show and string calls print so you should only need to define Base.show(io::IO, ...) and Base.print(io::IO, ...) methods.

@sam0410
Copy link
Contributor

sam0410 commented Nov 29, 2018

Hi @omus, Please tell me if I am missing something. But aren't the following two outputs contradictory ?
julia> d = Date(2018)
2018-01-01
and
julia> show(d)
Date(2018, 1, 1)

@JeffBezanson
Copy link
Member

REPL printing calls display, which calls the 3-argument form of show (including a MIME type). So they can be different, e.g.

julia> [1,2]
2-element Array{Int64,1}:
 1
 2

julia> show([1,2])
[1, 2]

@sam0410
Copy link
Contributor

sam0410 commented Dec 2, 2018

Thanks @JeffBezanson .
I added a PR. Please review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module display and printing Aesthetics and correctness of printed representations of objects. good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants