apple_quant_algorithmic/timestamp/
current_session_start.rs1use apple_quant_core::UnwrapOptionExt;
2use chrono::NaiveTime;
3use chrono_tz::US;
4
5use crate::timestamp::{Timestamp, Timestamped};
6
7use super::{TickTimestamp, UtcNs};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct CurrentSessionStart(Timestamp);
11
12impl CurrentSessionStart {
13 pub fn new(
14 tick_timestamp: &TickTimestamp,
15 ) -> Self {
16 let utc_ns = ***tick_timestamp;
17 utc_ns.into()
18 }
19}
20
21impl From<UtcNs> for CurrentSessionStart {
22 fn from(
23 value: UtcNs,
24 ) -> Self {
25 let naive_time = unsafe {
26 NaiveTime::from_hms_opt(5, 0, 0).unwrap_unchecked_release()
27 };
28
29 let utc_ns = value.previous_time(US::Central, &naive_time);
30 Self(utc_ns.into())
31 }
32}
33
34impl Timestamped for CurrentSessionStart {
35 fn timestamp(
36 &self,
37 ) -> Timestamp {
38 self.0
39 }
40}