Skip to content

Commit

Permalink
formatter[datetime]: Raise error for invalid format (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 authored Sep 9, 2024
1 parent a2704ae commit 1a22fae
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/formatting/formatter/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ pub enum DatetimeFormatter {
},
}

fn make_static_item(item: Item<'_>) -> Item<'static> {
match item {
Item::Literal(str) => Item::OwnedLiteral(str.into()),
Item::OwnedLiteral(boxed) => Item::OwnedLiteral(boxed),
Item::Space(str) => Item::OwnedSpace(str.into()),
Item::OwnedSpace(boxed) => Item::OwnedSpace(boxed),
Item::Numeric(numeric, pad) => Item::Numeric(numeric, pad),
Item::Fixed(fixed) => Item::Fixed(fixed),
Item::Error => Item::Error,
}
}

impl DatetimeFormatter {
pub(super) fn from_args(args: &[Arg]) -> Result<Self> {
let mut format = None;
Expand Down Expand Up @@ -97,7 +85,10 @@ impl DatetimeFormatter {
};

Ok(Self::Chrono {
items: items.map(make_static_item).collect(),
items: items.parse_to_owned().error(format!(
"Invalid format: \"{}\"",
format.unwrap_or(DEFAULT_DATETIME_FORMAT)
))?,
locale,
})
}
Expand Down

0 comments on commit 1a22fae

Please sign in to comment.