mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 07:30:05 +08:00
feat: v0.6.42
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.6.41"
|
version = "0.6.42"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Hatter's Rust Util"
|
description = "Hatter's Rust Util"
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
use std::time::{SystemTime, Duration};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
pub fn get_current_secs() -> u64 {
|
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 {
|
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> {
|
pub fn parse_duration(t: &str) -> Option<Duration> {
|
||||||
@@ -26,12 +34,12 @@ pub fn parse_duration(t: &str) -> Option<Duration> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_current_secs() {
|
fn test_get_current_secs() {
|
||||||
assert!(get_current_secs() != 0);
|
assert_ne!(get_current_secs(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_current_millis() {
|
fn test_get_current_millis() {
|
||||||
assert!(get_current_millis() != 0);
|
assert_ne!(get_current_millis(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user