chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Deprecate panicking `TimeDelta` initializers

Open pitdicker opened this issue 1 year ago • 2 comments

The following methods can panic and have a try_ variant:

impl Duration {
    pub const fn weeks(weeks: i64) -> Duration;
    pub const fn days(days: i64) -> Duration;
    pub const fn hours(hours: i64) -> Duration;
    pub const fn minutes(minutes: i64) -> Duration;
    pub const fn seconds(seconds: i64) -> Duration;
    pub const fn milliseconds(milliseconds: i64) -> Duration;
}

The replacement methods have been introduced only recently in 0.4.32, and Duration::try_milliseconds has not seen a release yet.

In all other places in chrono we have deprecated such panicking methods, and I suppose we should do the same here. I wonder when would be the right time?

cc @danwilliams

pitdicker avatar Feb 03 '24 12:02 pitdicker

Once replacements are in the field, I think the next release after about 1-2 months should be okay to deprecate.

Might be interesting to pick apart the crates.io downloads to figure out what old releases are still getting picked up (and maybe, why)?

djc avatar Feb 07 '24 09:02 djc

From https://github.com/chronotope/chrono/issues/1408#issuecomment-1931651503:

Might be interesting to pick apart the crates.io downloads to figure out what old releases are still getting picked up (and maybe, why)?

https://lib.rs/crates/chrono/versions has a nice breakdown. With just a superficial look there is a big correlation between use and for how long a version was the latest release.

Top 5:

version date downloads/mo probable reason
total 6.7M
0.4.33 2024-01-25 2.4M (±35%) Most-used is the current release.
0.4.31 2023-09-15 2.1M (±31%) This was the last release for four months before current
0.4.26 2023-05-30 738K (±11%) This was the last release for three months before 5 quick releases
0.4.23 2022-11-12 473K (±7%) Again the last release for four months before before 3 quick releases
0.4.19 2020-09-30 172K (±2.6) The last release for close to two years.

It seems to me there are no obvious blockers for users to upgrade. At least the 150 most popular crates that use chrono don't specify a max version, only a minimum version of chrono.

Also interesting that (2.4 + 0.145 + 2.1 + 0.77) / 6.678 = 71% of our users are now on a version of chrono without the time 0.1 dependency.

I have no idea how to figure out which older version of other crates causes the downloads of for example 0.4.19.

pitdicker avatar Feb 12 '24 08:02 pitdicker