| 1 | mod content_line_parts; |
| 2 | mod date_content_line; |
| 3 | mod parameters; |
| 4 | mod rule_content_line; |
| 5 | mod start_date_content_line; |
| 6 | |
| 7 | use std::fmt::Display; |
| 8 | use std::str::FromStr; |
| 9 | |
| 10 | use crate::RRule; |
| 11 | use crate::Tz; |
| 12 | use crate::Unvalidated; |
| 13 | |
| 14 | pub(crate) use content_line_parts::ContentLineCaptures; |
| 15 | pub(crate) use start_date_content_line::StartDateContentLine; |
| 16 | |
| 17 | use super::ParseError; |
| 18 | |
| 19 | #[derive(Debug, PartialEq)] |
| 20 | pub(crate) enum ContentLine { |
| 21 | RRule(RRule<Unvalidated>), |
| 22 | ExRule(RRule<Unvalidated>), |
| 23 | ExDate(Vec<chrono::DateTime<Tz>>), |
| 24 | RDate(Vec<chrono::DateTime<Tz>>), |
| 25 | } |
| 26 | |
| 27 | #[derive(Debug, PartialEq, Clone, Copy)] |
| 28 | pub(crate) enum PropertyName { |
| 29 | RRule, |
| 30 | ExRule, |
| 31 | ExDate, |
| 32 | RDate, |
| 33 | DtStart, |
| 34 | } |
| 35 | |
| 36 | impl Display for PropertyName { |
| 37 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 38 | match *self { |
| 39 | Self::RRule => write!(f, "RRULE"), |
| 40 | Self::ExRule => write!(f, "EXRULE"), |
| 41 | Self::ExDate => write!(f, "EXDATE"), |
| 42 | Self::RDate => write!(f, "RDATE"), |
| 43 | Self::DtStart => write!(f, "DTSTART"), |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl FromStr for PropertyName { |
| 49 | type Err = ParseError; |
| 50 | |
| 51 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 52 | let name = match &s[..].to_uppercase()[..] { |
| 53 | "RRULE" => Self::RRule, |
| 54 | "EXRULE" => Self::ExRule, |
| 55 | "RDATE" => Self::RDate, |
| 56 | "EXDATE" => Self::ExDate, |
| 57 | "DTSTART" => Self::DtStart, |
| 58 | _ => return Err(ParseError::UnrecognizedPropertyName(s.into())), |
| 59 | }; |
| 60 | Ok(name) |
| 61 | } |
| 62 | } |