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

Parsing Periods #38869

Open
oxinabox opened this issue Dec 14, 2020 · 3 comments
Open

Parsing Periods #38869

oxinabox opened this issue Dec 14, 2020 · 3 comments
Labels
domain:dates Dates, times, and the Dates stdlib module

Comments

@oxinabox
Copy link
Contributor

It would be useful to have the functionality in Dates for parsing periods.
E.g. getting an anser like

julia>parse(Dates.CompondPeriod, "00:15:00", periodformat"HH:MM:SS")
15 minutes

Or even


```julia
julia>parse(Millisecond, "00:15:00", periodformat"HH:MM:SS")
900000 milliseconds

Having this kind of functionality for working with Periods would have been useful for
JuliaLogging/LoggingExtras.jl#32

@quinnj
Copy link
Member

quinnj commented Dec 14, 2020

I mean, it's not pretty, but you can do: Dates.Millisecond(Dates.Nanosecond(Dates.value(Dates.Time("00:15:00", "HH:MM:SS"))))

@oxinabox
Copy link
Contributor Author

oxinabox commented Dec 14, 2020

you can also do:
parse(DateTime, "0:15:00", dateformat"HH:MM:SS") - DateTime(1)
(note the 1 not 0 cf #38870)

@JeffBezanson JeffBezanson added the domain:dates Dates, times, and the Dates stdlib module label Dec 14, 2020
@kcajf
Copy link
Contributor

kcajf commented Jan 5, 2021

While I haven't seen it used much, there is also an ISO 8601 format for representing durations / periods: https://en.wikipedia.org/wiki/ISO_8601#Durations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dates Dates, times, and the Dates stdlib module
Projects
None yet
Development

No branches or pull requests

4 participants