diff --git a/src/utils/time.rs b/src/utils/time.rs index 5eb474d..317c0b1 100644 --- a/src/utils/time.rs +++ b/src/utils/time.rs @@ -16,8 +16,23 @@ pub fn fmt_time(timestamp: u64) -> String { NaiveDateTime::from_timestamp_opt(timestamp as i64, 0).expect("Failed to parse timestamp!"); // Create a normal DateTime from the NaiveDateTime - let datetime: DateTime = DateTime::from_utc(naive, Utc); + let datetime: DateTime = DateTime::from_naive_utc_and_offset(naive, Utc); // Format the datetime how you want datetime.format("%Y-%m-%d %H:%M:%S").to_string() } + +#[cfg(test)] +mod test { + use crate::utils::time::{fmt_time, time}; + + #[test] + fn test_time() { + assert!(time() > 10); + } + + #[test] + fn test_fmt_time() { + assert_eq!(fmt_time(1693475465), "2023-08-31 09:51:05"); + } +}