Skip to content

Commit

Permalink
refactor: deprecated function updated and unused import deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Mar 15, 2024
1 parent 4167b86 commit d83f8c6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Duration, Utc};
use chrono::{DateTime, TimeDelta, Utc};

pub const DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";

Expand All @@ -14,9 +14,15 @@ pub fn now() -> u64 {
}

/// Returns the datetime some seconds ago.
///
/// # Panics
///
/// The function panics if the number of seconds passed as a parameter
/// are more than `i64::MAX` / `1_000` or less than `-i64::MAX` / `1_000`.
#[must_use]
pub fn seconds_ago_utc(seconds: i64) -> DateTime<chrono::Utc> {
Utc::now() - Duration::seconds(seconds)
Utc::now()
- TimeDelta::try_seconds(seconds).expect("seconds should be more than i64::MAX / 1_000 or less than -i64::MAX / 1_000")
}

/// Returns the current time in database format.
Expand Down

0 comments on commit d83f8c6

Please sign in to comment.