StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | #[cfg(test)] |
| 2 | use chrono::TimeZone; |
| 3 | use chrono::{DateTime, Utc}; |
| 4 | #[cfg(test)] |
| 5 | use std::sync::atomic::{AtomicI64, Ordering}; |
| 6 | |
| 7 | #[cfg(not(test))] |
| 8 | pub fn get_current_time() -> DateTime<Utc> { |
| 9 | Utc::now() |
| 10 | } |
| 11 | |
| 12 | thread_local! { |
| 13 | #[cfg(test)] |
| 14 | static CURRENT_SECS: AtomicI64 = const { AtomicI64::new(0) }; |
| 15 | } |
| 16 | #[cfg(test)] |
| 17 | pub fn get_current_time() -> DateTime<Utc> { |
| 18 | CURRENT_SECS.with(|current_secs| { |
| 19 | Utc.timestamp_opt(current_secs.load(Ordering::SeqCst), 0) |
| 20 | .unwrap() |
| 21 | }) |
| 22 | } |
| 23 | #[cfg(test)] |
| 24 | pub fn test_offset_time(offset_secs: i64) { |
| 25 | CURRENT_SECS.with(|current_secs| { |
| 26 | current_secs.fetch_add(offset_secs, Ordering::SeqCst); |
| 27 | }) |
| 28 | } |
| 29 |