From 2b0273b18695784b5adeabf3aef8a140591c51d9 Mon Sep 17 00:00:00 2001 From: jasonwilliams Date: Mon, 22 Jul 2024 23:43:44 +0100 Subject: [PATCH] addition of CalendarName for temporal_rs --- src/options.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/options.rs b/src/options.rs index 890b7c56..639be014 100644 --- a/src/options.rs +++ b/src/options.rs @@ -689,3 +689,43 @@ impl fmt::Display for TemporalRoundingMode { .fmt(f) } } + +/// values for `CalendarName`, whether to show the calendar in toString() methods +/// https://tc39.es/proposal-temporal/#sec-temporal-gettemporalshowcalendarnameoption +#[derive(Debug, Clone, Copy)] +pub enum CalendarName { + /// `Auto` option + Auto, + /// `Always` option + Always, + /// `Never` option + Never, + // `Critical` option + Critical, +} + +impl fmt::Display for CalendarName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + CalendarName::Auto => "auto", + CalendarName::Always => "always", + CalendarName::Never => "never", + CalendarName::Critical => "critical", + } + .fmt(f) + } +} + +impl FromStr for CalendarName { + type Err = TemporalError; + + fn from_str(s: &str) -> Result { + match s { + "auto" => Ok(Self::Auto), + "always" => Ok(Self::Always), + "never" => Ok(Self::Never), + "critical" => Ok(Self::Critical), + _ => Err(TemporalError::range().with_message("Invalid CalendarName provided.")), + } + } +}