Optimize cache management
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
pub mod crypt_utils;
|
||||
pub mod err;
|
||||
pub mod string_utils;
|
||||
pub mod time;
|
||||
pub mod time_utils;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use chrono::DateTime;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
/// Get the current time since epoch
|
||||
pub fn time() -> u64 {
|
||||
@@ -19,9 +19,27 @@ pub fn fmt_time(timestamp: u64) -> String {
|
||||
datetime.format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
|
||||
/// Convert UNIX time to system time
|
||||
pub fn unix_to_system_time(time: u64) -> SystemTime {
|
||||
UNIX_EPOCH + Duration::from_secs(time)
|
||||
}
|
||||
|
||||
/// Format UNIX time to HTTP date
|
||||
pub fn unix_to_http_date(time: u64) -> String {
|
||||
httpdate::fmt_http_date(unix_to_system_time(time))
|
||||
}
|
||||
|
||||
/// Get build time in UNIX format
|
||||
pub fn build_time() -> u64 {
|
||||
let build_time = build_time::build_time_local!();
|
||||
let date =
|
||||
chrono::DateTime::parse_from_rfc3339(build_time).expect("Failed to parse compile date");
|
||||
date.timestamp() as u64
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::utils::time::{fmt_time, time};
|
||||
use crate::utils::time_utils::{fmt_time, time};
|
||||
|
||||
#[test]
|
||||
fn test_time() {
|
||||
Reference in New Issue
Block a user