diff options
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/time.rs b/src/time.rs index b0ab4ab..4abb3f9 100644 --- a/src/time.rs +++ b/src/time.rs @@ -59,14 +59,9 @@ pub fn unpin() { } pub fn parse(ts: &str) -> Option<DateTime<Utc>> { - DateTime::parse_from_rfc3339(ts) - .ok() - .map(|d| d.with_timezone(&Utc)) - .or_else(|| { - chrono::NaiveDateTime::parse_from_str(ts, "%Y-%m-%d %H:%M:%S") - .ok() - .map(|n| Utc.from_utc_datetime(&n)) - }) + DateTime::parse_from_rfc3339(ts).ok().map(|d| d.with_timezone(&Utc)).or_else(|| { + chrono::NaiveDateTime::parse_from_str(ts, "%Y-%m-%d %H:%M:%S").ok().map(|n| Utc.from_utc_datetime(&n)) + }) } pub fn delta_secs(a: &str, b: &str) -> Option<i64> { @@ -132,7 +127,7 @@ pub fn virtualize() -> clock::VirtualClock { #[cfg(feature = "test-support")] mod clock { - use super::*; + use super::{DateTime, Utc}; use std::cell::Cell; use std::sync::{Mutex, MutexGuard}; @@ -143,7 +138,7 @@ mod clock { static AT: Mutex<Option<DateTime<Utc>>> = Mutex::new(None); static OWNER: Mutex<()> = Mutex::new(()); -// VirtualClock stays `pub`: lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it. + // VirtualClock stays `pub`: lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it. pub struct VirtualClock { // Held, never read: owning the mutex *is* the virtual clock's lease, // and dropping this guard is what releases it. @@ -151,7 +146,7 @@ mod clock { } pub fn virtualize() -> VirtualClock { - let owner = OWNER.lock().unwrap_or_else(|e| e.into_inner()); + let owner = OWNER.lock().unwrap_or_else(std::sync::PoisonError::into_inner); *lock(&AT) = Some(Utc::now()); ON.set(true); VirtualClock { _owner: owner } @@ -165,7 +160,7 @@ mod clock { } fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> { - m.lock().unwrap_or_else(|e| e.into_inner()) + m.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } pub fn now() -> Option<DateTime<Utc>> { |
