beacon-biosignals / TimeSpans.jl

A Julia package that provides a `TimeSpan` type for representing a continuous span between two points in time.
Other
6 stars 2 forks source link

Better printing for TimeSpans #62

Open ericphanson opened 8 months ago

ericphanson commented 8 months ago

Currently, we print them as things like TimeSpan(00:00:00.000000000, 09:45:00.000000000). This can be nice since it's "readable" but it is frustrating if you need to copy-paste into a REPL or such. I think we should use a roundtrippable implementation.

One option if we are attached to the current printing is to print it like

TimeSpan("00:00:00.000000000", "09:45:07.000000000")

(with quotes) and add a TimeSpan(::AbstractString, ::AbstractString) constructor to parse the strings.

kleinschmidt commented 8 months ago

Does repr give you something useful? IIUC that's meant to be the "gimme a string I can eval to get this thing back" function, not print

ericphanson commented 8 months ago

It does not:

julia> repr(TimeSpan(0,1))
"TimeSpan(00:00:00.000000000, 00:00:00.000000001)"

Also:

help?> repr
search: repr replaceproperty! reinterpret repeat replace replace! replacefield!

  repr(x; context=nothing)

  Create a string from any value using the show function. You should not add
  methods to repr; define a show method instead.
kleinschmidt commented 8 months ago

huh, well there ya go. adding a string constructor and putting quotes around makes the most sense to me then.