Skip to content
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

Refactor TemporalFields interface and add FieldsKey enum #87

Merged
merged 6 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ exclude = [
tinystr = "0.7.6"
icu_calendar = { version = "1.5.2", default-features = false, features = ["compiled_data"] }
rustc-hash = { version = "2.0.0", features = ["std"] }
bitflags = "2.6.0"
num-bigint = { version = "0.4.6", features = ["serde"] }
num-traits = "0.2.19"
ixdtf = { version = "0.2.0", features = ["duration"]}
21 changes: 15 additions & 6 deletions src/components/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::{
duration::{DateDuration, TimeDuration},
Date, DateTime, Duration, MonthDay, YearMonth,
},
fields::{FieldKey, TemporalFields},
iso::{IsoDate, IsoDateSlots},
options::{ArithmeticOverflow, TemporalUnit},
TemporalError, TemporalFields, TemporalResult,
TemporalError, TemporalResult,
};

use icu_calendar::{
Expand Down Expand Up @@ -298,12 +299,16 @@ impl Calendar {
);
}

let era =
Era::from_str(&fields.era()).map_err(|e| TemporalError::general(format!("{e:?}")))?;
let month_code = MonthCode::from_str(&fields.month_code())
.map_err(|e| TemporalError::general(format!("{e:?}")))?;
// NOTE: This might preemptively throw as `ICU4X` does not support constraining.
// Resolve month and monthCode;
let calendar_date = self.0.date_from_codes(
Era::from(fields.era()),
era,
fields.year().unwrap_or(0),
MonthCode(fields.month_code()),
month_code,
fields.day().unwrap_or(0) as u8,
)?;
let iso = self.0.date_to_iso(&calendar_date);
Expand Down Expand Up @@ -354,11 +359,15 @@ impl Calendar {
);
}

let era =
Era::from_str(&fields.era()).map_err(|e| TemporalError::general(format!("{e:?}")))?;
let month_code = MonthCode::from_str(&fields.month_code())
.map_err(|e| TemporalError::general(format!("{e:?}")))?;
// NOTE: This might preemptively throw as `ICU4X` does not support regulating.
let calendar_date = self.0.date_from_codes(
Era::from(fields.era()),
era,
fields.year().unwrap_or(0),
MonthCode(fields.month_code()),
month_code,
fields.day().unwrap_or(1) as u8,
)?;
let iso = self.0.date_to_iso(&calendar_date);
Expand Down Expand Up @@ -604,7 +613,7 @@ impl Calendar {
}

/// Provides field keys to be ignored depending on the calendar.
pub fn field_keys_to_ignore(&self, _keys: &[String]) -> TemporalResult<Vec<String>> {
pub fn field_keys_to_ignore(&self, _keys: &[FieldKey]) -> TemporalResult<Vec<FieldKey>> {
// TODO: Research and implement the appropriate KeysToIgnore for all `BuiltinCalendars.`
Err(TemporalError::range().with_message("FieldKeysToIgnore is not yet implemented."))
}
Expand Down
Loading