Skip to main content

ical/value/
duration.rs

1//! # Duration value
2//!
3//! The decoded duration value kind.
4//!
5//! Backs `DURATION` and the duration form of other properties (RFC 5545 3.3.6):
6//! an ISO 8601 duration such as `P15DT5H0M20S` or `-P1D`, always prefixed by `P`
7//! (with an optional leading sign). The value is kept as its raw text; the crate
8//! does not parse it into day/hour/minute/second components.
9
10use alloc::{borrow::Cow, string::String};
11
12/// A decoded duration value (ISO 8601 `P...`), kept as its raw text.
13#[derive(Clone, Debug, Default, PartialEq, Eq)]
14pub struct IcalDuration<'a>(pub Cow<'a, str>);
15
16impl<'a> From<&'a str> for IcalDuration<'a> {
17    fn from(value: &'a str) -> Self {
18        Self(Cow::Borrowed(value))
19    }
20}
21
22impl From<String> for IcalDuration<'_> {
23    fn from(value: String) -> Self {
24        Self(Cow::Owned(value))
25    }
26}
27
28impl<'a> From<Cow<'a, str>> for IcalDuration<'a> {
29    fn from(value: Cow<'a, str>) -> Self {
30        Self(value)
31    }
32}