sim_time/
config.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_with::serde_as;
4
5/// Top level configuration
6#[derive(Clone, Debug, Serialize, Deserialize)]
7pub struct TimeConfig {
8    /// Setting `realtime: true` deactivates sim-time.
9    /// Only if its set to `false` will the [`SimulationConfig`] take effect.
10    pub realtime: bool,
11    /// Configuration of how the simulation should behave
12    #[serde(default)]
13    pub simulation: SimulationConfig,
14}
15
16impl Default for TimeConfig {
17    fn default() -> Self {
18        Self {
19            realtime: true,
20            simulation: SimulationConfig::default(),
21        }
22    }
23}
24
25/// Configuration of how the simulation should behave.
26#[serde_as]
27#[derive(Clone, Debug, Deserialize, Serialize)]
28pub struct SimulationConfig {
29    /// What date should the simulation start at.
30    #[serde(default = "Utc::now")]
31    pub start_at: DateTime<Utc>,
32    /// How long between 'ticks' of the simulation (in real milliseconds).
33    pub tick_interval_ms: u64,
34    /// How many simulated seconds does one tick represent.
35    #[serde_as(as = "serde_with::DurationSeconds<u64>")]
36    pub tick_duration_secs: std::time::Duration,
37    /// Should the simulation transition to real time when it has reached the current time.
38    #[serde(default)]
39    pub transform_to_realtime: bool,
40}
41
42impl Default for SimulationConfig {
43    fn default() -> Self {
44        Self {
45            start_at: chrono::DateTime::parse_from_rfc3339("2021-01-01T00:00:00Z")
46                .unwrap()
47                .with_timezone(&Utc),
48            tick_interval_ms: 1,
49            tick_duration_secs: std::time::Duration::from_secs(1000),
50            transform_to_realtime: false,
51        }
52    }
53}