This commit is contained in:
		@@ -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<Utc> = DateTime::from_utc(naive, Utc);
 | 
			
		||||
    let datetime: DateTime<Utc> = 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");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user