Skip to content

Commit

Permalink
stop using deprecated Duration::milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemis21 committed Apr 19, 2024
1 parent 8d803e6 commit c786f06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/game/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use serde::Serialize;

/// Utility to construct a `chrono::Duration` from a number of seconds in a constant context.
const fn seconds(n: i64) -> chrono::Duration {
chrono::Duration::milliseconds(n * 1000)
match chrono::Duration::try_milliseconds(n * 1000) {
Some(duration) => duration,
// unwrap/expect not yet const
_ => panic!("duration should be in range")
}
}

/// Game constants. This is generic over the maximum number of guesses, to
Expand Down
2 changes: 1 addition & 1 deletion src/game/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async fn get_clip(
) -> Result<(ContentType, Vec<u8>), ApiError> {
let game = auth.game(&mut tx, id).await?;
let end = game.time_unlocked();
let start = chrono::Duration::milliseconds(seek.unwrap_or(0).into());
let start = chrono::Duration::try_milliseconds(seek.unwrap_or(0).into()).expect("clip start time should be in range");
if start >= end {
return Err(ApiError::forbidden(
"cannot seek past end of unlocked music",
Expand Down

0 comments on commit c786f06

Please sign in to comment.