-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dff854a
commit 2988660
Showing
7 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use chrono::prelude::*; | ||
|
||
#[cfg(test)] | ||
pub mod mock_time { | ||
use super::*; | ||
use std::cell::RefCell; | ||
|
||
thread_local! { | ||
static MOCK_TIME: RefCell<Option<DateTime<Utc>>> = RefCell::new(None); | ||
} | ||
|
||
pub fn now() -> DateTime<Utc> { | ||
MOCK_TIME.with(|cell| cell.borrow().as_ref().cloned().unwrap_or_else(Utc::now)) | ||
} | ||
|
||
pub fn set_mock_time(time: DateTime<Utc>) { | ||
MOCK_TIME.with(|cell| *cell.borrow_mut() = Some(time)); | ||
} | ||
|
||
pub fn clear_mock_time() { | ||
MOCK_TIME.with(|cell| *cell.borrow_mut() = None); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
pub use mock_time::now; | ||
|
||
#[cfg(not(test))] | ||
pub fn now() -> DateTime<Utc> { | ||
Utc::now() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters