Skip to main content

jobberdb/
context.rs

1//! Temporal context of a jobber run.
2//!
3//! Having this is necessary for testing.
4
5use super::prelude::*;
6
7/// Temporal context of a jobber run.
8#[derive(PartialEq, Clone, Debug)]
9pub struct Context(DateTime);
10
11impl Context {
12    /// Create new context with current time.
13    pub fn now() -> Self {
14        Self(DateTime::now())
15    }
16    /// Create new context with given time.
17    /// Only use in tests!
18    pub fn new_test(local: &str) -> Self {
19        Self(local.into())
20    }
21    /// Return time in context
22    pub fn time(&self) -> DateTime {
23        self.0
24    }
25    /// Return time in context
26    pub fn date(&self) -> Date {
27        self.0.date()
28    }
29}