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

Provide access to subsecond nanos in the public interface of Duration. #154

Closed
tylerreisinger opened this issue May 25, 2017 · 8 comments
Closed

Comments

@tylerreisinger
Copy link

tylerreisinger commented May 25, 2017

The way the Duration struct is implemented, if there are more total nanoseconds represented than i64::MAX, it is impossible to see greater than millisecond precision on the outside despite that information being stored. It would be useful to have a method similar to std::time::Duration::subsec_nanos which can return only the number of nanoseconds past the nearest second.

Additionally, for interfacing with chrono, it would be useful to have a constructor to create a Duration from a number of whole seconds plus the additional nanoseconds similar to std::time::Duration::new to efficiently construct Duration objects with full precision.

@lifthrasiir lifthrasiir self-assigned this Jun 21, 2017
@lifthrasiir
Copy link
Contributor

lifthrasiir commented Jun 21, 2017

I don't intend to modify time::Duration by now, but I plan for the new duration-like type for Chrono 0.4.1 (originally intended for 0.4.0 but delayed due to the time constraint) and I'll take care of this suggestion. Thank you for pointing out.

@kosta
Copy link

kosta commented Sep 3, 2017

@lifthrasiir is there a public branch that I can track for the time::Duration replacement?

@kangalio
Copy link

What is the state of this? I am working on implementing chrono support for the PyO3 Python bindings crate. Chrono's lacking Duration API artificially limits the size of Duration's that can be supported, which is unfortunate.

@pickfire
Copy link

pickfire commented Mar 7, 2021

@kangalioo I think adding it as a feature to chrono does not requires us to change the public interface. #542

@pitdicker
Copy link
Collaborator

Added in #1327.

@kangalio
Copy link

kangalio commented Oct 5, 2023

Thanks!

I would vouch to re-open this issue though, because the second part of the issue is not part of #1327:

Additionally, for interfacing with chrono, it would be useful to have a constructor to create a Duration from a number of whole seconds plus the additional nanoseconds similar to std::time::Duration::new to efficiently construct Duration objects with full precision.

This specifically is what would be needed in pyo3 to support sub-second precision in the Python<->Rust conversion (code permalink)

@djc
Copy link
Contributor

djc commented Oct 6, 2023

Please just file a new issue so we can track that request separately.

@pitdicker
Copy link
Collaborator

Sorry, I missed that part of the first post. #1137 includes a Duration::new method.

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

7 participants