replace manual time convertions with std ones
This commit is contained in:
parent
db034cee00
commit
be3a635fe7
@ -585,23 +585,17 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime
|
|||||||
|
|
||||||
fn timestamp_to_string(timestamp: SystemTime) -> BaseNString {
|
fn timestamp_to_string(timestamp: SystemTime) -> BaseNString {
|
||||||
let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
|
let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
|
||||||
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
|
let micros: u64 = duration.as_micros().try_into().unwrap();
|
||||||
micros.to_base_fixed_len(CASE_INSENSITIVE)
|
micros.to_base_fixed_len(CASE_INSENSITIVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
|
fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
|
||||||
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
|
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) {
|
||||||
|
Ok(micros) => micros,
|
||||||
|
Err(_) => return Err("timestamp not an int"),
|
||||||
|
};
|
||||||
|
|
||||||
if micros_since_unix_epoch.is_err() {
|
let duration = Duration::from_micros(micros_since_unix_epoch);
|
||||||
return Err("timestamp not an int");
|
|
||||||
}
|
|
||||||
|
|
||||||
let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();
|
|
||||||
|
|
||||||
let duration = Duration::new(
|
|
||||||
micros_since_unix_epoch / 1_000_000,
|
|
||||||
1000 * (micros_since_unix_epoch % 1_000_000) as u32,
|
|
||||||
);
|
|
||||||
Ok(UNIX_EPOCH + duration)
|
Ok(UNIX_EPOCH + duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1098,7 +1098,7 @@ fn new(
|
|||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||||
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
|
let nanos = duration.as_nanos();
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
nanos.hash(&mut stable_hasher);
|
nanos.hash(&mut stable_hasher);
|
||||||
let anon_id_seed = stable_hasher.finish();
|
let anon_id_seed = stable_hasher.finish();
|
||||||
|
Loading…
Reference in New Issue
Block a user