1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 15:40:03 +08:00

feat: v0.6.42

This commit is contained in:
2023-09-09 17:33:56 +08:00
parent 7e5bec260f
commit 5cdad86ea6
2 changed files with 14 additions and 6 deletions

View File

@@ -1,11 +1,19 @@
use std::time::{SystemTime, Duration};
use std::time::{Duration, SystemTime};
pub fn get_current_secs() -> u64 {
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0 /* SHOULD NOT HAPPEN */)
get_secs(&SystemTime::now())
}
pub fn get_current_millis() -> u128 {
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_millis()).unwrap_or(0 /* SHOULD NOT HAPPEN */)
get_millis(&SystemTime::now())
}
pub fn get_secs(system_time: &SystemTime) -> u64 {
system_time.duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0 /* SHOULD NOT HAPPEN */)
}
pub fn get_millis(system_time: &SystemTime) -> u128 {
system_time.duration_since(SystemTime::UNIX_EPOCH).map(|d| d.as_millis()).unwrap_or(0 /* SHOULD NOT HAPPEN */)
}
pub fn parse_duration(t: &str) -> Option<Duration> {
@@ -26,12 +34,12 @@ pub fn parse_duration(t: &str) -> Option<Duration> {
#[test]
fn test_get_current_secs() {
assert!(get_current_secs() != 0);
assert_ne!(get_current_secs(), 0);
}
#[test]
fn test_get_current_millis() {
assert!(get_current_millis() != 0);
assert_ne!(get_current_millis(), 0);
}
#[test]