diff --git a/Cargo.lock b/Cargo.lock index bc65833..30e76fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -739,9 +739,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "f56b4c72906975ca04becb8a30e102dfecddd0c06181e3e95ddc444be28881f8" dependencies = [ "android-tzdata", "iana-time-zone", @@ -749,7 +749,7 @@ dependencies = [ "num-traits", "time 0.1.45", "wasm-bindgen", - "winapi", + "windows-targets 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 46b849e..f3a9cb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,5 +37,5 @@ webauthn-rs = { version = "0.4.8", features = ["danger-allow-state-serialisation url = "2.4.1" light-openid = { version = "1.0.1", features=["crypto-wrapper"] } bincode = "2.0.0-rc.3" -chrono = "0.4.26" +chrono = "0.4.27" lazy_static = "1.4.0" \ No newline at end of file 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"); + } +}