1use calendar_types::{
4 duration::{Duration, SignedDuration},
5 primitive::Sign,
6 time::{Date, DateTime, Hour, Minute, NonLeapSecond, Utc},
7};
8
9pub use calendar_types::time::TimeFormat;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum DateTimeOrDate<M = TimeFormat> {
14 DateTime(DateTime<M>),
16 Date(Date),
18}
19
20impl<M> DateTimeOrDate<M> {
21 pub fn is_date(&self) -> bool {
23 matches!(self, Self::Date(_))
24 }
25
26 pub fn is_date_time(&self) -> bool {
28 matches!(self, Self::DateTime(_))
29 }
30
31 pub fn map_marker<N>(self, f: impl FnOnce(M) -> N) -> DateTimeOrDate<N> {
33 match self {
34 Self::DateTime(dt) => DateTimeOrDate::DateTime(DateTime {
35 date: dt.date,
36 time: dt.time,
37 marker: f(dt.marker),
38 }),
39 Self::Date(d) => DateTimeOrDate::Date(d),
40 }
41 }
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
46pub struct UtcOffset {
47 pub sign: Sign,
49 pub hour: Hour,
51 pub minute: Minute,
53 pub second: NonLeapSecond,
55}
56
57impl std::fmt::Display for UtcOffset {
58 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 write!(
60 f,
61 "{}{:02}:{:02}",
62 self.sign.as_char(),
63 self.hour as u8,
64 self.minute as u8
65 )?;
66 let sec = self.second as u8;
67 if sec != 0 {
68 write!(f, ":{sec:02}")?;
69 }
70 Ok(())
71 }
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
80pub enum Period<M = TimeFormat> {
81 Explicit {
83 start: DateTime<M>,
85 end: DateTime<M>,
87 },
88 Start {
90 start: DateTime<M>,
92 duration: Duration,
94 },
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq)]
103pub enum RDate<M = TimeFormat> {
104 DateTime(DateTime<M>),
105 Date(Date),
106 Period(Period<M>),
107}
108
109#[derive(Debug, Clone, PartialEq, Eq)]
111pub enum RDateSeq<M = TimeFormat> {
112 DateTime(Vec<DateTime<M>>),
113 Date(Vec<Date>),
114 Period(Vec<Period<M>>),
115}
116
117#[derive(Debug, Clone, PartialEq, Eq)]
119pub enum ExDateSeq<M = TimeFormat> {
120 DateTime(Vec<DateTime<M>>),
121 Date(Vec<Date>),
122}
123
124#[derive(Debug, Clone, Copy, PartialEq, Eq)]
130pub enum TriggerValue {
131 Duration(SignedDuration),
133 DateTime(DateTime<Utc>),
135}