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

Rename Duration to TimeDelta, add type alias #1406

Merged
merged 12 commits into from
Feb 5, 2024

Conversation

pitdicker
Copy link
Collaborator

@pitdicker pitdicker commented Feb 2, 2024

We have discussed something like this many times. Reasons to rename Duration to TimeDelta:

  • A Duration is usually understood to be strictly positive. Our type can be both positive and negative. That makes it more flexible, which is a good thing for a date and time library. The name TimeDelta can better represent a signed value.
  • The standard library made its Duration type unsigned, as that is a better match for system APIs. We want to avoid confusion with that type.
  • The name OldDuration we currently use as an alias in our documentation to ease the confusion a little is just sad (and not really helping).
  • On our 0.5 branch we have already renamed it to TimeDelta, and we expect users to eventually migrate. By making the name available now we can ease the migration a little when the time comes.
  • The name difference between our 0.4 and 0.5 branches is my biggest source of merge conflicts. It would make me happy if we can make them the same.

The old name Duration will remain available as a type alias for TimeDelta, so this is not a breaking change.

@pitdicker pitdicker force-pushed the time_delta branch 2 times, most recently from a1a070a to dc814ab Compare February 2, 2024 19:39
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: 41 lines in your changes are missing coverage. Please review.

Comparison is base (f4b4701) 91.84% compared to head (4be71c2) 91.85%.

Files Patch % Lines
src/time_delta.rs 95.85% 31 Missing ⚠️
src/datetime/mod.rs 78.26% 5 Missing ⚠️
src/naive/datetime/mod.rs 96.80% 3 Missing ⚠️
src/date.rs 92.59% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1406   +/-   ##
=======================================
  Coverage   91.84%   91.85%           
=======================================
  Files          38       38           
  Lines       17518    17526    +8     
=======================================
+ Hits        16090    16098    +8     
  Misses       1428     1428           

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

@pitdicker pitdicker force-pushed the time_delta branch 2 times, most recently from 4c84e2d to 174f04a Compare February 2, 2024 19:56
@pitdicker pitdicker marked this pull request as ready for review February 2, 2024 20:00
Copy link
Collaborator Author

@pitdicker pitdicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a review of all lines. It was not a trivial find-and-replace, but it seems like I didn't mangle things.

@djc
Copy link
Member

djc commented Feb 5, 2024

You refer to TimeSpan a number of times in your OP. Which is it -- TimeDelta or TimeSpan?

@pitdicker
Copy link
Collaborator Author

You refer to TimeSpan a number of times in your OP. Which is it -- TimeDelta or TimeSpan?

TimeDelta. Working on chrono makes me feel dumb surprisingly often.

@pitdicker
Copy link
Collaborator Author

There was a little discussion on possible names in #1137 (comment). I don't care deeply about the names, but TimeDelta and TimeSpan have my preference. It seems you and @esheppa had a preference for TimeDelta as that is what is already on the 0.5 branch.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay -- do we want to deprecate the Duration alias, and if so, when?

src/lib.rs Outdated
@@ -467,6 +467,8 @@ extern crate alloc;

mod duration;
pub use duration::Duration;
/// Alias of [`Duration`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be formatted as a type, that is, with empty lines around it and not between a bunch of imports.

src/lib.rs Outdated
//! [`Duration::from_std`](https://docs.rs/time/0.1.40/time/struct.Duration.html#method.from_std)
//! and
//! [`Duration::to_std`](https://docs.rs/time/0.1.40/time/struct.Duration.html#method.to_std)
//! ### Time span / Duration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use "Time delta" in the title here?

@pitdicker
Copy link
Collaborator Author

Thank you! Looking forward to less merge conflicts (going to introduce plenty of new ones though now that I'm starting to work on the 0.5 branch).

Okay -- do we want to deprecate the Duration alias, and if so, when?

I feel that deprecating the type would cause a lot of churn while bringing little benefit. New code can start using TimeDelta and be compatible with 0.5. But personally I'd leave it available until 0.5.

@pitdicker pitdicker merged commit ce97c2e into chronotope:main Feb 5, 2024
37 checks passed
@pitdicker pitdicker deleted the time_delta branch February 5, 2024 11:31
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.

2 participants