Skip to content

Integrate MonthCode into public API and related adjustments #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/builtins/compiled/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
ArithmeticOverflow, DifferenceSettings, Disambiguation, DisplayCalendar, DisplayOffset,
DisplayTimeZone, OffsetDisambiguation, ToStringRoundingOptions,
},
Duration, PlainDate, PlainDateTime, PlainTime, TemporalError, TemporalResult,
Duration, MonthCode, PlainDate, PlainDateTime, PlainTime, TemporalError, TemporalResult,
};
use alloc::string::String;
use tinystr::TinyAsciiStr;
Expand Down Expand Up @@ -58,7 +58,7 @@ impl ZonedDateTime {
/// Returns the `ZonedDateTime`'s calendar month code.
///
/// Enable with the `compiled_data` feature flag.
pub fn month_code(&self) -> TemporalResult<TinyAsciiStr<4>> {
pub fn month_code(&self) -> TemporalResult<MonthCode> {
let provider = TZ_PROVIDER
.lock()
.map_err(|_| TemporalError::general("Unable to acquire lock"))?;
Expand Down
23 changes: 12 additions & 11 deletions src/builtins/core/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use super::{PartialDate, ZonedDateTime};
mod era;
mod types;

pub(crate) use types::{ascii_four_to_integer, month_to_month_code};
pub use types::{ResolveType, ResolvedCalendarFields};
pub(crate) use types::{month_to_month_code, ResolutionType};
pub use types::{MonthCode, ResolvedCalendarFields};

use era::EraInfo;

Expand Down Expand Up @@ -222,13 +222,13 @@ impl Calendar {
overflow: ArithmeticOverflow,
) -> TemporalResult<PlainDate> {
let resolved_fields =
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolveType::Date)?;
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolutionType::Date)?;

if self.is_iso() {
// Resolve month and monthCode;
return PlainDate::new_with_overflow(
resolved_fields.era_year.year,
resolved_fields.month_code.as_iso_month_integer()?,
resolved_fields.month_code.to_month_integer(),
resolved_fields.day,
self.clone(),
overflow,
Expand Down Expand Up @@ -261,10 +261,10 @@ impl Calendar {
overflow: ArithmeticOverflow,
) -> TemporalResult<PlainMonthDay> {
let resolved_fields =
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolveType::MonthDay)?;
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolutionType::MonthDay)?;
if self.is_iso() {
return PlainMonthDay::new_with_overflow(
resolved_fields.month_code.as_iso_month_integer()?,
resolved_fields.month_code.to_month_integer(),
resolved_fields.day,
self.clone(),
overflow,
Expand All @@ -284,11 +284,11 @@ impl Calendar {
overflow: ArithmeticOverflow,
) -> TemporalResult<PlainYearMonth> {
let resolved_fields =
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolveType::YearMonth)?;
ResolvedCalendarFields::try_from_partial(partial, overflow, ResolutionType::YearMonth)?;
if self.is_iso() {
return PlainYearMonth::new_with_overflow(
resolved_fields.era_year.year,
resolved_fields.month_code.as_iso_month_integer()?,
resolved_fields.month_code.to_month_integer(),
Some(resolved_fields.day),
self.clone(),
overflow,
Expand Down Expand Up @@ -398,12 +398,13 @@ impl Calendar {
}

/// `CalendarMonthCode`
pub fn month_code(&self, iso_date: &IsoDate) -> TemporalResult<TinyAsciiStr<4>> {
pub fn month_code(&self, iso_date: &IsoDate) -> TemporalResult<MonthCode> {
if self.is_iso() {
return Ok(iso_date.as_icu4x()?.month().standard_code.0);
let mc = iso_date.as_icu4x()?.month().standard_code.0;
return Ok(MonthCode(mc));
}
let calendar_date = self.0.date_from_iso(iso_date.as_icu4x()?);
Ok(self.0.month(&calendar_date).standard_code.0)
Ok(MonthCode(self.0.month(&calendar_date).standard_code.0))
}

/// `CalendarDay`
Expand Down
Loading