Skip to content

Commit

Permalink
addition of CalendarName for temporal_rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwilliams committed Jul 22, 2024
1 parent c840b7e commit 2b0273b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Err> {
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.")),
}
}
}

0 comments on commit 2b0273b

Please sign in to comment.