mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
possible fix for CI failure
This commit is contained in:
parent
f28e57a367
commit
47fcdd0723
1 changed files with 25 additions and 5 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue