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

Missing division of time periods #29395

Closed
cstjean opened this issue Sep 27, 2018 · 6 comments
Closed

Missing division of time periods #29395

cstjean opened this issue Sep 27, 2018 · 6 comments

Comments

@cstjean
Copy link
Contributor

cstjean commented Sep 27, 2018

Currently,

julia> Millisecond(10) / Millisecond(1)
10.0

julia> Minute(10) / Millisecond(1)
ERROR: MethodError: no method matching /(::Minute, ::Millisecond)

If division is supported at all, it would be very convenient to be able to divide across compatible units.

@oscardssmith
Copy link
Member

The problem is that there is no unique answer here. Consider Year(1)/Day(1) should this be 364 or 365?

@cstjean
Copy link
Contributor Author

cstjean commented Sep 27, 2018

Right, it should only be done for units that can be converted.

julia> convert(Millisecond, Year(1))
ERROR: MethodError: Cannot `convert` an object of type Year to an object of type Millisecond
Closest candidates are:
  convert(::Type{Millisecond}, ::Second) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/Dates/src/periods.jl:421
  convert(::Type{Millisecond}, ::Minute) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/Dates/src/periods.jl:421
  convert(::Type{Millisecond}, ::Hour) at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/Dates/src/periods.jl:421
  ...
Stacktrace:
 [1] top-level scope at none:0

julia> convert(Millisecond, Day(1))
86400000 milliseconds

Converting the bigger of the two units to the smaller unit seems like the best way to go about it.

@oscardssmith
Copy link
Member

in that case, only second to millisecond should work, as leap seconds allow impression for all larger units

@oscardssmith
Copy link
Member

it's unfortunate, but time units really sex sic suck

@cstjean
Copy link
Contributor Author

cstjean commented Sep 28, 2018

in that case, only second to millisecond should work, as leap seconds allow impression for all larger units

I think that Dates is not meant for high-fidelity date manipulation. Its DateTime + Period arithmetic is not even associative 😛

julia> DateTime(2017, 2) + (Day(30) + Month(1))
2017-03-31T00:00:00

julia> (DateTime(2017, 2) + Day(30)) + Month(1)
2017-04-03T00:00:00

In any case, all I'm asking is for / to be the natural extension of convert.

@laborg
Copy link
Contributor

laborg commented Feb 8, 2022

This has been implemented in #43360

julia> Minute(10) / Millisecond(1)
600000.0

@laborg laborg closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants