ical/value/datetime.rs
1//! # Date and time values
2//!
3//! The decoded date/time value kinds: a calendar date, a date-time, and a
4//! time.
5//!
6//! [`IcalDate`] (RFC 5545 3.3.4, `YYYYMMDD`) backs date-valued properties,
7//! [`IcalDateTime`] (RFC 5545 3.3.5, `YYYYMMDDTHHMMSS` with an optional `Z`
8//! suffix or a companion `TZID` parameter) backs `DTSTART` / `DTEND` /
9//! `DTSTAMP` and friends, and [`IcalTime`] (RFC 5545 3.3.12, `HHMMSS` with an
10//! optional `Z` suffix) backs bare time values. All three are kept as their
11//! raw text rather than decoded into calendar fields: the grammars carry
12//! timezone-dependent and reduced-precision forms whose meaning depends on
13//! companion parameters, so decoding here would risk a lossy round-trip.
14//! Callers that need calendar semantics parse the string themselves. Pure
15//! data, no escaping; the owning property's wire name lives on
16//! [`crate::prop::IcalProp::name`].
17
18use alloc::{borrow::Cow, string::String, vec::Vec};
19
20/// A decoded date value (`YYYYMMDD`), kept as its raw text.
21#[derive(Clone, Debug, Default, PartialEq, Eq)]
22pub struct IcalDate<'a>(pub Cow<'a, str>);
23
24impl<'a> From<&'a str> for IcalDate<'a> {
25 fn from(value: &'a str) -> Self {
26 Self(Cow::Borrowed(value))
27 }
28}
29
30impl From<String> for IcalDate<'_> {
31 fn from(value: String) -> Self {
32 Self(Cow::Owned(value))
33 }
34}
35
36impl<'a> From<Cow<'a, str>> for IcalDate<'a> {
37 fn from(value: Cow<'a, str>) -> Self {
38 Self(value)
39 }
40}
41
42/// A decoded comma-separated list of date-ish values, each kept as its raw
43/// text.
44///
45/// Backs `RDATE` and `EXDATE`, which RFC 5545 3.8.5.1 and 3.8.5.2 define as
46/// lists rather than single values. An item is a `DATE`, a `DATE-TIME` or (for
47/// `RDATE`) a `PERIOD`, whichever the property's `VALUE` parameter declares,
48/// and it is kept exactly as written, so a period item keeps its `start/end`
49/// or `start/duration` form.
50#[derive(Clone, Debug, Default, PartialEq, Eq)]
51pub struct IcalDateTimeList<'a>(pub Vec<Cow<'a, str>>);
52
53impl<'a> From<Vec<Cow<'a, str>>> for IcalDateTimeList<'a> {
54 fn from(values: Vec<Cow<'a, str>>) -> Self {
55 Self(values)
56 }
57}
58
59/// A decoded date-time value (`YYYYMMDDTHHMMSS`, optional `Z` or `TZID`), kept
60/// as its raw text.
61#[derive(Clone, Debug, Default, PartialEq, Eq)]
62pub struct IcalDateTime<'a>(pub Cow<'a, str>);
63
64impl<'a> From<&'a str> for IcalDateTime<'a> {
65 fn from(value: &'a str) -> Self {
66 Self(Cow::Borrowed(value))
67 }
68}
69
70impl From<String> for IcalDateTime<'_> {
71 fn from(value: String) -> Self {
72 Self(Cow::Owned(value))
73 }
74}
75
76impl<'a> From<Cow<'a, str>> for IcalDateTime<'a> {
77 fn from(value: Cow<'a, str>) -> Self {
78 Self(value)
79 }
80}
81
82/// A decoded time value (`HHMMSS`, optional `Z`), kept as its raw text.
83#[derive(Clone, Debug, Default, PartialEq, Eq)]
84pub struct IcalTime<'a>(pub Cow<'a, str>);
85
86impl<'a> From<&'a str> for IcalTime<'a> {
87 fn from(value: &'a str) -> Self {
88 Self(Cow::Borrowed(value))
89 }
90}
91
92impl From<String> for IcalTime<'_> {
93 fn from(value: String) -> Self {
94 Self(Cow::Owned(value))
95 }
96}
97
98impl<'a> From<Cow<'a, str>> for IcalTime<'a> {
99 fn from(value: Cow<'a, str>) -> Self {
100 Self(value)
101 }
102}