Skip to content
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
16 changes: 6 additions & 10 deletions src/builtins/compiled/zoneddatetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::provider::TransitionDirection;
use crate::ZonedDateTime;
use crate::{
options::{
ArithmeticOverflow, DifferenceSettings, Disambiguation, DisplayCalendar, DisplayOffset,
DisplayTimeZone, OffsetDisambiguation, RoundingOptions, ToStringRoundingOptions,
DifferenceSettings, Disambiguation, DisplayCalendar, DisplayOffset, DisplayTimeZone,
OffsetDisambiguation, Overflow, RoundingOptions, ToStringRoundingOptions,
},
Calendar, Duration, PlainTime, TemporalResult, TimeZone,
};
Expand Down Expand Up @@ -69,7 +69,7 @@ impl ZonedDateTime {
#[inline]
pub fn from_partial(
partial: PartialZonedDateTime,
overflow: Option<ArithmeticOverflow>,
overflow: Option<Overflow>,
disambiguation: Option<Disambiguation>,
offset_option: Option<OffsetDisambiguation>,
) -> TemporalResult<Self> {
Expand All @@ -88,7 +88,7 @@ impl ZonedDateTime {
fields: ZonedDateTimeFields,
disambiguation: Option<Disambiguation>,
offset_option: Option<OffsetDisambiguation>,
overflow: Option<ArithmeticOverflow>,
overflow: Option<Overflow>,
) -> TemporalResult<Self> {
self.with_with_provider(
fields,
Expand All @@ -115,11 +115,7 @@ impl ZonedDateTime {
/// Adds a [`Duration`] to the current `ZonedDateTime`.
///
/// Enable with the `compiled_data` feature flag.
pub fn add(
&self,
duration: &Duration,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
pub fn add(&self, duration: &Duration, overflow: Option<Overflow>) -> TemporalResult<Self> {
self.add_with_provider(duration, overflow, &*TZ_PROVIDER)
}

Expand All @@ -129,7 +125,7 @@ impl ZonedDateTime {
pub fn subtract(
&self,
duration: &Duration,
overflow: Option<ArithmeticOverflow>,
overflow: Option<Overflow>,
) -> TemporalResult<Self> {
self.subtract_with_provider(duration, overflow, &*TZ_PROVIDER)
}
Expand Down
10 changes: 5 additions & 5 deletions src/builtins/core/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
duration::DateDuration, Duration, PlainDate, PlainDateTime, PlainMonthDay, PlainYearMonth,
},
iso::IsoDate,
options::{ArithmeticOverflow, Unit},
options::{Overflow, Unit},
parsers::parse_allowed_calendar_formats,
TemporalError, TemporalResult,
};
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Calendar {
pub fn date_from_fields(
&self,
fields: CalendarFields,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<PlainDate> {
let resolved_fields =
ResolvedCalendarFields::try_from_fields(self, &fields, overflow, ResolutionType::Date)?;
Expand Down Expand Up @@ -227,7 +227,7 @@ impl Calendar {
pub fn month_day_from_fields(
&self,
mut fields: CalendarFields,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<PlainMonthDay> {
// You are allowed to specify year information, however
// it is *only* used for resolving the given month/day data.
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Calendar {
pub fn year_month_from_fields(
&self,
fields: YearMonthCalendarFields,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<PlainYearMonth> {
// TODO: add a from_partial_year_month method on ResolvedCalendarFields
let resolved_fields = ResolvedCalendarFields::try_from_fields(
Expand Down Expand Up @@ -324,7 +324,7 @@ impl Calendar {
&self,
date: &IsoDate,
duration: &DateDuration,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<PlainDate> {
// 1. If calendar is "iso8601", then
if self.is_iso() {
Expand Down
8 changes: 4 additions & 4 deletions src/builtins/core/calendar/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use tinystr::TinyAsciiStr;

use super::types::month_to_month_code;
use crate::{
error::ErrorMessage, options::ArithmeticOverflow, Calendar, MonthCode, PlainDate,
PlainDateTime, PlainMonthDay, PlainYearMonth, TemporalError, TemporalResult,
error::ErrorMessage, options::Overflow, Calendar, MonthCode, PlainDate, PlainDateTime,
PlainMonthDay, PlainYearMonth, TemporalError, TemporalResult,
};
use core::ops::Range;

Expand Down Expand Up @@ -286,7 +286,7 @@ impl YearMonthCalendarFields {
#[macro_export]
macro_rules! impl_with_fallback_method {
($method_name:ident, $fields_type:ident, ( $(with_day: $day:ident)? ) $component_type:ty) => {
pub(crate) fn $method_name(&self, fallback: &$component_type, calendar: icu_calendar::AnyCalendarKind, overflow: ArithmeticOverflow) -> TemporalResult<Self> {
pub(crate) fn $method_name(&self, fallback: &$component_type, calendar: icu_calendar::AnyCalendarKind, overflow: Overflow) -> TemporalResult<Self> {
let keys_to_ignore = self.field_keys_to_ignore(calendar);
let mut era = self.era;

Expand Down Expand Up @@ -315,7 +315,7 @@ macro_rules! impl_with_fallback_method {
let (month, month_code) = match (self.month, self.month_code) {
(Some(month), Some(mc)) => (Some(month), Some(mc)),
(Some(month), None) => {
let month_maybe_clamped = if overflow == ArithmeticOverflow::Constrain {
let month_maybe_clamped = if overflow == Overflow::Constrain {
// TODO (manishearth) this should be managed by ICU4X
// https://github.com/unicode-org/icu4x/issues/6790
month.clamp(1, 12)
Expand Down
27 changes: 13 additions & 14 deletions src/builtins/core/calendar/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tinystr::TinyAsciiStr;

use crate::fields::CalendarFields;
use crate::iso::{constrain_iso_day, is_valid_iso_day};
use crate::options::ArithmeticOverflow;
use crate::options::Overflow;
use crate::Calendar;
use crate::{TemporalError, TemporalResult};
use icu_calendar::AnyCalendarKind;
Expand All @@ -32,7 +32,7 @@ impl ResolvedCalendarFields {
pub fn try_from_fields(
calendar: &Calendar,
fields: &CalendarFields,
overflow: ArithmeticOverflow,
overflow: Overflow,
resolve_type: ResolutionType,
) -> TemporalResult<Self> {
fields.check_year_in_safe_arithmetical_range()?;
Expand All @@ -46,7 +46,7 @@ impl ResolvedCalendarFields {
month_code,
calendar,
)?;
let day = if overflow == ArithmeticOverflow::Constrain {
let day = if overflow == Overflow::Constrain {
constrain_iso_day(era_year.year, month_code.to_month_integer(), day)
} else {
if !is_valid_iso_day(era_year.year, month_code.to_month_integer(), day) {
Expand Down Expand Up @@ -572,14 +572,14 @@ const fn ascii_digit_to_int(ascii_digit: u8) -> u8 {
fn resolve_iso_month(
calendar: &Calendar,
fields: &CalendarFields,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<MonthCode> {
let month_code = match (fields.month_code, fields.month) {
(None, None) => {
return Err(TemporalError::r#type().with_message("Month or monthCode must be provided."))
}
(None, Some(month)) => {
if overflow == ArithmeticOverflow::Constrain {
if overflow == Overflow::Constrain {
return month_to_month_code(month.clamp(1, 12));
}
if !(1..=12).contains(&month) {
Expand Down Expand Up @@ -613,7 +613,7 @@ mod tests {
calendar::{types::ResolutionType, CalendarFields},
core::{calendar::Calendar, PartialDate, PlainDate},
},
options::ArithmeticOverflow,
options::Overflow,
};

use super::{month_to_month_code, MonthCode, ResolvedCalendarFields};
Expand Down Expand Up @@ -665,9 +665,9 @@ mod tests {

let cal = Calendar::default();

let err = cal.date_from_fields(bad_fields.clone(), ArithmeticOverflow::Reject);
let err = cal.date_from_fields(bad_fields.clone(), Overflow::Reject);
assert!(err.is_err());
let result = cal.date_from_fields(bad_fields, ArithmeticOverflow::Constrain);
let result = cal.date_from_fields(bad_fields, Overflow::Constrain);
assert!(result.is_ok());
}

Expand Down Expand Up @@ -698,8 +698,7 @@ mod tests {
};

let plain_date =
PlainDate::from_partial(partial, Some(ArithmeticOverflow::Constrain))
.expect(&expect_str);
PlainDate::from_partial(partial, Some(Overflow::Constrain)).expect(&expect_str);

assert_eq!(
plain_date.year(),
Expand All @@ -710,7 +709,7 @@ mod tests {

// Get the full partial date.
let full_partial = CalendarFields::default()
.with_fallback_date(&plain_date, *cal, ArithmeticOverflow::Constrain)
.with_fallback_date(&plain_date, *cal, Overflow::Constrain)
.expect(&expect_str);

let era_year = super::EraYear::try_from_fields(
Expand Down Expand Up @@ -748,7 +747,7 @@ mod tests {
let err = ResolvedCalendarFields::try_from_fields(
&Calendar::ISO,
&bad_fields,
ArithmeticOverflow::Reject,
Overflow::Reject,
ResolutionType::Date,
);
assert!(err.is_err());
Expand All @@ -765,7 +764,7 @@ mod tests {
let err = ResolvedCalendarFields::try_from_fields(
&Calendar::ISO,
&bad_fields,
ArithmeticOverflow::Reject,
Overflow::Reject,
ResolutionType::Date,
);
assert!(err.is_err());
Expand All @@ -774,7 +773,7 @@ mod tests {
let err = ResolvedCalendarFields::try_from_fields(
&Calendar::ISO,
&bad_fields,
ArithmeticOverflow::Reject,
Overflow::Reject,
ResolutionType::Date,
);
assert!(err.is_err());
Expand Down
39 changes: 14 additions & 25 deletions src/builtins/core/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
},
iso::{IsoDate, IsoDateTime, IsoTime},
options::{
ArithmeticOverflow, DifferenceOperation, DifferenceSettings, Disambiguation,
DisplayCalendar, ResolvedRoundingOptions, Unit, UnitGroup,
DifferenceOperation, DifferenceSettings, Disambiguation, DisplayCalendar, Overflow,
ResolvedRoundingOptions, Unit, UnitGroup,
},
parsers::IxdtfStringBuilder,
provider::{NeverProvider, TimeZoneProvider},
Expand Down Expand Up @@ -194,15 +194,15 @@ impl PlainDate {
pub(crate) fn add_duration_to_date(
&self,
duration: &Duration,
overflow: Option<ArithmeticOverflow>,
overflow: Option<Overflow>,
) -> TemporalResult<Self> {
// 3. If operation is subtract, set duration to CreateNegatedTemporalDuration(duration).
// 4. Let dateDuration be ToDateDurationRecordWithoutTime(duration).
// TODO: Look into why this is fallible, and make some adjustments
let date_duration = duration.to_date_duration_record_without_time()?;
// 5. Let resolvedOptions be ? GetOptionsObject(options).
// 6. Let overflow be ? GetTemporalOverflowOption(resolvedOptions).
let overflow = overflow.unwrap_or(ArithmeticOverflow::Constrain);
let overflow = overflow.unwrap_or(Overflow::Constrain);
// 7. Let result be ? CalendarDateAdd(calendar, temporalDate.[[ISODate]], dateDuration, overflow).
// 8. Return ! CreateTemporalDate(result, calendar).
self.calendar()
Expand Down Expand Up @@ -318,7 +318,7 @@ impl PlainDate {
/// Creates a new `PlainDate` automatically constraining any values that may be invalid.
#[inline]
pub fn new(year: i32, month: u8, day: u8, calendar: Calendar) -> TemporalResult<Self> {
Self::new_with_overflow(year, month, day, calendar, ArithmeticOverflow::Constrain)
Self::new_with_overflow(year, month, day, calendar, Overflow::Constrain)
}

/// Creates a new `PlainDate` with an ISO 8601 calendar automatically constraining any
Expand All @@ -331,7 +331,7 @@ impl PlainDate {
/// Creates a new `PlainDate` rejecting any date that may be invalid.
#[inline]
pub fn try_new(year: i32, month: u8, day: u8, calendar: Calendar) -> TemporalResult<Self> {
Self::new_with_overflow(year, month, day, calendar, ArithmeticOverflow::Reject)
Self::new_with_overflow(year, month, day, calendar, Overflow::Reject)
}

/// Creates a new `PlainDate` with an ISO 8601 calendar rejecting any date that may be invalid.
Expand All @@ -349,7 +349,7 @@ impl PlainDate {
month: u8,
day: u8,
calendar: Calendar,
overflow: ArithmeticOverflow,
overflow: Overflow,
) -> TemporalResult<Self> {
let iso = IsoDate::new_with_overflow(year, month, day, overflow)?;
Ok(Self::new_unchecked(iso, calendar))
Expand Down Expand Up @@ -377,10 +377,7 @@ impl PlainDate {
///
/// ```
#[inline]
pub fn from_partial(
partial: PartialDate,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
pub fn from_partial(partial: PartialDate, overflow: Option<Overflow>) -> TemporalResult<Self> {
let year_check = partial.calendar_fields.year.is_some()
|| (partial.calendar_fields.era.is_some()
&& partial.calendar_fields.era_year.is_some());
Expand Down Expand Up @@ -413,11 +410,7 @@ impl PlainDate {
}

/// Creates a date time with values from a `PartialDate`.
pub fn with(
&self,
fields: CalendarFields,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
pub fn with(&self, fields: CalendarFields, overflow: Option<Overflow>) -> TemporalResult<Self> {
if fields.is_empty() {
return Err(TemporalError::r#type().with_message("CalendarFields must have a field."));
}
Expand All @@ -426,7 +419,7 @@ impl PlainDate {
// 8. Let fields be ? CalendarMergeFields(calendarRec, fieldsResult.[[Fields]], partialDate).
// 9. Set fields to ? PrepareTemporalFields(fields, fieldsResult.[[FieldNames]], «»).
// 10. Return ? CalendarDateFromFields(calendarRec, fields, resolvedOptions).
let overflow = overflow.unwrap_or(ArithmeticOverflow::Constrain);
let overflow = overflow.unwrap_or(Overflow::Constrain);
self.calendar.date_from_fields(
fields.with_fallback_date(self, self.calendar.kind(), overflow)?,
overflow,
Expand Down Expand Up @@ -490,11 +483,7 @@ impl PlainDate {

#[inline]
/// Adds a `Duration` to the current `Date`
pub fn add(
&self,
duration: &Duration,
overflow: Option<ArithmeticOverflow>,
) -> TemporalResult<Self> {
pub fn add(&self, duration: &Duration, overflow: Option<Overflow>) -> TemporalResult<Self> {
self.add_duration_to_date(duration, overflow)
}

Expand All @@ -503,7 +492,7 @@ impl PlainDate {
pub fn subtract(
&self,
duration: &Duration,
overflow: Option<ArithmeticOverflow>,
overflow: Option<Overflow>,
) -> TemporalResult<Self> {
self.add_duration_to_date(&duration.negated(), overflow)
}
Expand Down Expand Up @@ -630,13 +619,13 @@ impl PlainDate {
.with_month(self.month())
.with_month_code(self.month_code());
self.calendar()
.year_month_from_fields(fields, ArithmeticOverflow::Constrain)
.year_month_from_fields(fields, Overflow::Constrain)
}

/// Converts the current `Date` into a `PlainMonthDay`
#[inline]
pub fn to_plain_month_day(&self) -> TemporalResult<PlainMonthDay> {
let overflow = ArithmeticOverflow::Constrain;
let overflow = Overflow::Constrain;
self.calendar().month_day_from_fields(
CalendarFields::default().with_fallback_date(self, self.calendar.kind(), overflow)?,
overflow,
Expand Down
Loading
Loading