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

Add subsec_micros and subsec_millis methods to TimeDelta #1668

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ggoetz
Copy link

@ggoetz ggoetz commented Feb 26, 2025

This PR revives @botahamec 's PR #1351, which has been abandoned, and adds subsec_micros and subsec_millis to the public API for chrono::TimeDelta, for consistency with the API of std::time::Duration.

Summary of changes:

  • expose TimeDelta constants like NANOS_PER_MICRO and companions in chrono's lib.rs. See the comment thread on the original PR description for the rationale behind the move.
  • update the docstring for TimeDelta::subsec_nanos() and add a test for the method.
  • add subsec_millis and subsec_micros, along with unit tests.

Fixes: #1348

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.07%. Comparing base (2b7a28e) to head (25936a4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1668      +/-   ##
==========================================
+ Coverage   91.05%   91.07%   +0.01%     
==========================================
  Files          37       37              
  Lines       17402    17431      +29     
==========================================
+ Hits        15846    15875      +29     
  Misses       1556     1556              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@djc
Copy link
Member

djc commented Feb 26, 2025

Honestly I'm not convinced by the argument that these consts should be made public just so two of them can make a single appearance in a docstring. IMO it would be fine to leave the constants alone and use literals to explain the methods.

@ggoetz ggoetz force-pushed the subsec-millis-micros branch from 5aee138 to 25936a4 Compare February 26, 2025 19:59
@ggoetz
Copy link
Author

ggoetz commented Feb 26, 2025

Honestly I'm not convinced by the argument that these consts should be made public just so two of them can make a single appearance in a docstring. IMO it would be fine to leave the constants alone and use literals to explain the methods.

Makes sense to me -- and there was precedent with the previous docstring for subsec_nanos to only use a literal without exposing the corresponding const. I've reverted the commit that exposed the constants.

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

Successfully merging this pull request may close these issues.

Add subsec methods to Duration
2 participants