2020-02-10 05:19:39 +01:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
use std::time;
|
|
|
|
|
2020-03-05 05:55:03 +01:00
|
|
|
pub(crate) fn i64_unix_secs() -> i64 {
|
2020-03-22 04:17:00 +01:00
|
|
|
elapsed().as_secs() as i64
|
2020-02-10 05:19:39 +01:00
|
|
|
}
|
2020-03-05 05:55:03 +01:00
|
|
|
|
|
|
|
pub(crate) fn i64_unix_millis() -> i64 {
|
2020-03-22 04:17:00 +01:00
|
|
|
elapsed().as_millis() as i64
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(test))]
|
|
|
|
fn elapsed() -> time::Duration {
|
2020-03-05 05:55:03 +01:00
|
|
|
time::SystemTime::now()
|
|
|
|
.duration_since(time::SystemTime::UNIX_EPOCH)
|
|
|
|
.unwrap()
|
2020-03-22 04:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2020-03-05 05:55:03 +01:00
|
|
|
}
|