Skip to content

Commit 95e03ae

Browse files
committed
Expand valid range
1 parent f4e879b commit 95e03ae

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

components/calendar/src/calendar_arithmetic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ use core::convert::TryInto;
1111
use core::fmt::Debug;
1212
use core::hash::{Hash, Hasher};
1313
use core::marker::PhantomData;
14+
use core::ops::RangeInclusive;
1415
use tinystr::tinystr;
1516

17+
/// The range ±2²⁷. We use i32::MIN since it is -2³¹
18+
const VALID_YEAR_RANGE: RangeInclusive<i32> = (i32::MIN / 16)..=-(i32::MIN / 16);
19+
1620
#[derive(Debug)]
1721
#[allow(clippy::exhaustive_structs)] // this type is stable
1822
pub(crate) struct ArithmeticDate<C: CalendarArithmetic> {
@@ -492,7 +496,7 @@ where
492496
},
493497
},
494498
(Some(era), Some(era_year)) => {
495-
range_check(era_year, "year", -1_000_000..=1_000_000)?;
499+
range_check(era_year, "year", VALID_YEAR_RANGE)?;
496500
let era_year_as_year_info = cal.year_info_from_era(era, era_year)?;
497501
if let Some(extended_year) = fields.extended_year {
498502
if era_year_as_year_info != extended_year_as_year_info(extended_year, cal)?

components/calendar/src/date.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<A: AsCalendar> Date<A> {
125125
///
126126
/// The year is `extended_year` if no era is provided.
127127
///
128-
/// This function will not accept year/extended_year values that are outside of the range `[-1_000_000, 1_000_000]`,
128+
/// This function will not accept year/extended_year values that are outside of the range `[-2²⁷, 2²⁷]`,
129129
/// regardless of the calendar, instead returning a [`DateError::Range`]. See [`Date::try_from_fields()`] for more
130130
/// information.
131131
#[inline]
@@ -148,7 +148,7 @@ impl<A: AsCalendar> Date<A> {
148148
/// and the month as either ordinal or month code. It can constrain out-of-bounds values
149149
/// and fill in missing fields. See [`DateFromFieldsOptions`] for more information.
150150
///
151-
/// This function will not accept year/extended_year values that are outside of the range `[-1_000_000, 1_000_000]`,
151+
/// This function will not accept year/extended_year values that are outside of the range `[-2²⁷, 2²⁷]`,
152152
/// regardless of the calendar, instead returning a [`DateError::Range`]. This is to protect clients
153153
/// from bugs due to arithmetic overflow. Currently, calendar-specific `Date::try_new_calendarname()` constructors
154154
/// do not do this, though we may change that behavior in the future.

0 commit comments

Comments
 (0)