Skip to content

Commit f10919f

Browse files
committed
Move limit check to constructor
1 parent 7ee84ff commit f10919f

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/components/date.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,12 +680,6 @@ impl<C: CalendarProtocol> FromStr for Date<C> {
680680
ArithmeticOverflow::Reject,
681681
)?;
682682

683-
if !date.is_within_limits() {
684-
return Err(
685-
TemporalError::range().with_message("Date is not within ISO date time limits.")
686-
);
687-
}
688-
689683
Ok(Self::new_unchecked(date, CalendarSlot::from_str(calendar)?))
690684
}
691685
}

src/iso.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,30 @@ impl IsoDate {
200200
day: i32,
201201
overflow: ArithmeticOverflow,
202202
) -> TemporalResult<Self> {
203-
match overflow {
203+
let id = match overflow {
204204
ArithmeticOverflow::Constrain => {
205205
let month = month.clamp(1, 12);
206206
let days_in_month = utils::iso_days_in_month(year, month);
207207
let d = day.clamp(1, days_in_month);
208208
// NOTE: Values are clamped in a u8 range.
209-
Ok(Self::new_unchecked(year, month as u8, d as u8))
209+
Self::new_unchecked(year, month as u8, d as u8)
210210
}
211211
ArithmeticOverflow::Reject => {
212212
if !is_valid_date(year, month, day) {
213213
return Err(TemporalError::range().with_message("not a valid ISO date."));
214214
}
215215
// NOTE: Values have been verified to be in a u8 range.
216-
Ok(Self::new_unchecked(year, month as u8, day as u8))
216+
Self::new_unchecked(year, month as u8, day as u8)
217217
}
218+
};
219+
220+
if !iso_dt_within_valid_limits(id, &IsoTime::noon()) {
221+
return Err(
222+
TemporalError::range().with_message("Date is not within ISO date time limits.")
223+
);
218224
}
225+
226+
Ok(id)
219227
}
220228

221229
/// Create a balanced `IsoDate`
@@ -369,10 +377,6 @@ impl IsoDate {
369377
// 17. Return ! CreateDateDurationRecord(years, months, weeks, days).
370378
DateDuration::new(years as f64, months as f64, weeks as f64, days as f64)
371379
}
372-
373-
pub(crate) fn is_within_limits(self) -> bool {
374-
IsoDateTime::new_unchecked(self, IsoTime::noon()).is_within_limits()
375-
}
376380
}
377381

378382
impl IsoDate {

src/rounding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<T: Roundable> IncrementRounder<T> {
5757
pub(crate) fn from_positive_parts(number: T, increment: NonZeroU64) -> TemporalResult<Self> {
5858
let increment = <T as NumCast>::from(increment.get()).temporal_unwrap()?;
5959

60-
debug_assert!(number > T::ZERO);
60+
debug_assert!(number >= T::ZERO);
6161

6262
Ok(Self {
6363
sign: true,

0 commit comments

Comments
 (0)