apple-quant-algorithmic 0.4.0

Apple Quant's algorithmic library.
Documentation
use apple_quant_core::UnwrapOptionExt;
use chrono::NaiveTime;
use chrono_tz::US;

use crate::timestamp::{Timestamp, Timestamped};

use super::{TickTimestamp, UtcNs};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct CurrentSessionStart(Timestamp);

impl CurrentSessionStart {
	pub fn new(
		tick_timestamp: &TickTimestamp,
	) -> Self {
		let utc_ns = ***tick_timestamp;
		utc_ns.into()
	}
}

impl From<UtcNs> for CurrentSessionStart {
	fn from(
		value: UtcNs,
	) -> Self {
		let naive_time = unsafe {
			NaiveTime::from_hms_opt(5, 0, 0).unwrap_unchecked_release()
		};

		let utc_ns = value.previous_time(US::Central, &naive_time);
		Self(utc_ns.into())
	}
}

impl Timestamped for CurrentSessionStart {
	fn timestamp(
		&self,
	) -> Timestamp {
		self.0
	}
}