Skip to content

Commit

Permalink
Deprecate panicking TimeDelta constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 1, 2024
1 parent af76fe9 commit 006d58d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/time_delta.rs
Expand Up @@ -102,6 +102,10 @@ impl TimeDelta {
/// Panics when the duration is out of bounds.
#[inline]
#[must_use]
#[deprecated(
since = "0.4.35",
note = "Use `TimeDelta::try_weeks` instead or consider the `Days` type"
)]
pub const fn weeks(weeks: i64) -> TimeDelta {
expect!(TimeDelta::try_weeks(weeks), "TimeDelta::weeks out of bounds")
}
Expand Down Expand Up @@ -129,6 +133,10 @@ impl TimeDelta {
/// Panics when the `TimeDelta` would be out of bounds.
#[inline]
#[must_use]
#[deprecated(
since = "0.4.35",
note = "Use `TimeDelta::try_days` instead or consider the `Days` type"
)]
pub const fn days(days: i64) -> TimeDelta {
expect!(TimeDelta::try_days(days), "TimeDelta::days out of bounds")
}
Expand All @@ -155,6 +163,7 @@ impl TimeDelta {
/// Panics when the `TimeDelta` would be out of bounds.
#[inline]
#[must_use]
#[deprecated(since = "0.4.35", note = "Use `TimeDelta::try_hours` instead")]
pub const fn hours(hours: i64) -> TimeDelta {
expect!(TimeDelta::try_hours(hours), "TimeDelta::hours out of bounds")
}
Expand All @@ -180,6 +189,7 @@ impl TimeDelta {
/// Panics when the `TimeDelta` would be out of bounds.
#[inline]
#[must_use]
#[deprecated(since = "0.4.35", note = "Use `TimeDelta::try_minutes` instead")]
pub const fn minutes(minutes: i64) -> TimeDelta {
expect!(TimeDelta::try_minutes(minutes), "TimeDelta::minutes out of bounds")
}
Expand All @@ -204,6 +214,7 @@ impl TimeDelta {
/// (in this context, this is the same as `i64::MIN / 1_000` due to rounding).
#[inline]
#[must_use]
#[deprecated(since = "0.4.35", note = "Use `TimeDelta::try_seconds` instead")]
pub const fn seconds(seconds: i64) -> TimeDelta {
expect!(TimeDelta::try_seconds(seconds), "TimeDelta::seconds out of bounds")
}
Expand All @@ -227,7 +238,7 @@ impl TimeDelta {
/// Panics when the `TimeDelta` would be out of bounds, i.e. when `milliseconds` is more than
/// `i64::MAX` or less than `-i64::MAX`. Notably, this is not the same as `i64::MIN`.
#[inline]
#[deprecated]
#[deprecated(since = "0.4.35", note = "Use `TimeDelta::try_milliseconds` instead")]
pub const fn milliseconds(milliseconds: i64) -> TimeDelta {
expect!(TimeDelta::try_milliseconds(milliseconds), "TimeDelta::milliseconds out of bounds")
}
Expand Down Expand Up @@ -683,6 +694,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
#[should_panic(expected = "TimeDelta::seconds out of bounds")]
fn test_duration_seconds_max_overflow_panic() {
let _ = TimeDelta::seconds(i64::MAX / 1_000 + 1);
Expand All @@ -704,6 +716,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
#[should_panic(expected = "TimeDelta::seconds out of bounds")]
fn test_duration_seconds_min_underflow_panic() {
let _ = TimeDelta::seconds(-i64::MAX / 1_000 - 1);
Expand Down Expand Up @@ -766,6 +779,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
#[should_panic(expected = "TimeDelta::milliseconds out of bounds")]
fn test_duration_milliseconds_min_underflow_panic() {
// Here we ensure that trying to create a value one millisecond below the
Expand Down

0 comments on commit 006d58d

Please sign in to comment.