possible fix for CI failure

This commit is contained in:
Damien Elmes 2020-03-22 13:17:00 +10:00
parent f28e57a367
commit 47fcdd0723

View file

@ -4,15 +4,35 @@
use std::time;
pub(crate) fn i64_unix_secs() -> i64 {
time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs() as i64
elapsed().as_secs() as i64
}
pub(crate) fn i64_unix_millis() -> i64 {
elapsed().as_millis() as i64
}
#[cfg(not(test))]
fn elapsed() -> time::Duration {
time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as i64
}
// when running in CI, shift the current time away from the cutoff point
// to accomodate unit tests that depend on the current time
#[cfg(test)]
fn elapsed() -> time::Duration {
use chrono::{Local, Timelike};
let now = Local::now();
let mut elap = time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH)
.unwrap();
if now.hour() >= 2 && now.hour() < 4 {
elap -= time::Duration::from_secs(60 * 60 * 2);
}
elap
}