es_entity/clock/
config.rs1use chrono::{DateTime, Utc};
2
3#[derive(Debug, Clone)]
5pub struct ArtificialClockConfig {
6 pub start_at: DateTime<Utc>,
8 pub mode: ArtificialMode,
10}
11
12fn truncate_to_millis(time: DateTime<Utc>) -> DateTime<Utc> {
15 DateTime::from_timestamp_millis(time.timestamp_millis()).expect("valid timestamp")
16}
17
18impl ArtificialClockConfig {
19 pub fn manual() -> Self {
21 Self {
22 start_at: truncate_to_millis(Utc::now()),
23 mode: ArtificialMode::Manual,
24 }
25 }
26
27 pub fn manual_at(start_at: DateTime<Utc>) -> Self {
29 Self {
30 start_at: truncate_to_millis(start_at),
31 mode: ArtificialMode::Manual,
32 }
33 }
34
35 pub fn auto(time_scale: f64) -> Self {
37 Self {
38 start_at: truncate_to_millis(Utc::now()),
39 mode: ArtificialMode::AutoAdvance { time_scale },
40 }
41 }
42
43 pub fn auto_at(start_at: DateTime<Utc>, time_scale: f64) -> Self {
45 Self {
46 start_at: truncate_to_millis(start_at),
47 mode: ArtificialMode::AutoAdvance { time_scale },
48 }
49 }
50}
51
52impl Default for ArtificialClockConfig {
53 fn default() -> Self {
54 Self::manual()
55 }
56}
57
58#[derive(Debug, Clone, Copy)]
60pub enum ArtificialMode {
61 AutoAdvance {
64 time_scale: f64,
66 },
67 Manual,
70}