Can clear 2FA login history from edit_user page

This commit is contained in:
2022-11-12 11:16:55 +01:00
parent 7a3eaa944e
commit 7e1cbb184d
6 changed files with 226 additions and 10 deletions

View File

@ -1,3 +1,4 @@
use chrono::{DateTime, NaiveDateTime, Utc};
use std::time::{SystemTime, UNIX_EPOCH};
/// Get the current time since epoch
@ -7,3 +8,16 @@ pub fn time() -> u64 {
.unwrap()
.as_secs()
}
/// Format unix timestamp to a human-readable string
pub fn fmt_time(timestamp: u64) -> String {
// Create a NaiveDateTime from the timestamp
let naive =
NaiveDateTime::from_timestamp_opt(timestamp as i64, 0).expect("Failed to parse timestamp!");
// Create a normal DateTime from the NaiveDateTime
let datetime: DateTime<Utc> = DateTime::from_utc(naive, Utc);
// Format the datetime how you want
datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}