@@ -91,7 +91,7 @@ impl IsoDateTime {
9191 // 3. Let epochMilliseconds be 𝔽((epochNanoseconds - remainderNs) / 10^6).
9292 let epoch_millis = ( mathematical_nanos - remainder_nanos) / 1_000_000 ;
9393
94- let ( year, month, day) = utils:: ymd_from_epoch_milliseconds ( epoch_millis) ;
94+ let ( year, month, day) = utils:: Epoch :: new ( epoch_millis) . ymd ( ) ;
9595
9696 // 7. Let hour be ℝ(! HourFromTime(epochMilliseconds)).
9797 let hour = epoch_millis. div_euclid ( 3_600_000 ) . rem_euclid ( 24 ) ;
@@ -344,8 +344,7 @@ impl IsoDate {
344344 /// Equivalent to `BalanceISODate`.
345345 pub ( crate ) fn balance ( year : i32 , month : i32 , day : i32 ) -> Self {
346346 let epoch_days = iso_date_to_epoch_days ( year, month, day) ;
347- let ms = utils:: epoch_days_to_epoch_ms ( epoch_days, 0 ) ;
348- let ( year, month, day) = utils:: ymd_from_epoch_milliseconds ( ms) ;
347+ let ( year, month, day) = utils:: Epoch :: from_days ( epoch_days) . ymd ( ) ;
349348 Self :: new_unchecked ( year, month, day)
350349 }
351350
@@ -367,7 +366,7 @@ impl IsoDate {
367366 /// Equivalent to `IsoDateToEpochDays`
368367 #[ inline]
369368 pub ( crate ) fn to_epoch_days ( self ) -> i32 {
370- utils:: epoch_days_from_gregorian_date ( self . year , self . month , self . day )
369+ utils:: Epoch :: from_gregorian_date ( self . year , self . month , self . day ) . days ( )
371370 }
372371
373372 /// Returns if the current `IsoDate` is valid.
@@ -488,12 +487,13 @@ impl IsoDate {
488487
489488 // NOTE: Below is adapted from the polyfill. Preferring this as it avoids looping.
490489 // 11. Let weeks be 0.
491- let days = utils:: epoch_days_from_gregorian_date ( other. year , other. month , other. day )
492- - utils:: epoch_days_from_gregorian_date (
490+ let days = utils:: Epoch :: from_gregorian_date ( other. year , other. month , other. day ) . days ( )
491+ - utils:: Epoch :: from_gregorian_date (
493492 constrained. year ,
494493 constrained. month ,
495494 constrained. day ,
496- ) ;
495+ )
496+ . days ( ) ;
497497
498498 let ( weeks, days) = if largest_unit == TemporalUnit :: Week {
499499 ( days / 7 , days % 7 )
@@ -905,8 +905,7 @@ const MAX_EPOCH_DAYS: i32 = 10i32.pow(8) + 1;
905905#[ inline]
906906/// Utility function to determine if a `DateTime`'s components create a `DateTime` within valid limits
907907fn iso_dt_within_valid_limits ( date : IsoDate , time : & IsoTime ) -> bool {
908- if utils:: epoch_days_from_gregorian_date ( date. year , date. month , date. day ) . abs ( ) > MAX_EPOCH_DAYS
909- {
908+ if utils:: Epoch :: from_gregorian_date ( date. year , date. month , date. day ) . days ( ) > MAX_EPOCH_DAYS {
910909 return false ;
911910 }
912911
@@ -927,7 +926,7 @@ fn utc_epoch_nanos(date: IsoDate, time: &IsoTime) -> TemporalResult<EpochNanosec
927926#[ inline]
928927fn to_unchecked_epoch_nanoseconds ( date : IsoDate , time : & IsoTime ) -> i128 {
929928 let ms = time. to_epoch_ms ( ) ;
930- let epoch_ms = utils:: epoch_days_to_epoch_ms ( date. to_epoch_days ( ) , ms ) ;
929+ let epoch_ms = utils:: Epoch :: from_days ( date. to_epoch_days ( ) ) . millis ( ) + ms ;
931930 epoch_ms as i128 * 1_000_000 + time. microsecond as i128 * 1_000 + time. nanosecond as i128
932931}
933932
@@ -943,10 +942,10 @@ pub(crate) fn iso_date_to_epoch_days(year: i32, month: i32, day: i32) -> i32 {
943942 let resolved_month = month. rem_euclid ( 12 ) as u8 ;
944943 // 3. Find a time t such that EpochTimeToEpochYear(t) is resolvedYear,
945944 // EpochTimeToMonthInYear(t) is resolvedMonth, and EpochTimeToDate(t) is 1.
946- let epoch_days = utils:: epoch_days_from_gregorian_date ( resolved_year, resolved_month, 1 ) ;
945+ let epoch_days = utils:: Epoch :: from_gregorian_date ( resolved_year, resolved_month, 1 ) ;
947946
948947 // 4. Return EpochTimeToDayNumber(t) + date - 1.
949- epoch_days + day - 1
948+ epoch_days. days ( ) + day - 1
950949}
951950
952951#[ inline]
@@ -997,13 +996,13 @@ fn balance_iso_year_month(year: i32, month: i32) -> (i32, u8) {
997996/// Note: month is 1 based.
998997#[ inline]
999998pub ( crate ) fn constrain_iso_day ( year : i32 , month : u8 , day : u8 ) -> u8 {
1000- let days_in_month = utils:: iso_days_in_month ( year, month) ;
999+ let days_in_month = utils:: Epoch :: from_gregorian_date ( year, month, 1 ) . days_in_month ( ) ;
10011000 day. clamp ( 1 , days_in_month)
10021001}
10031002
10041003#[ inline]
10051004pub ( crate ) fn is_valid_iso_day ( year : i32 , month : u8 , day : u8 ) -> bool {
1006- let days_in_month = utils:: iso_days_in_month ( year, month) ;
1005+ let days_in_month = utils:: Epoch :: from_gregorian_date ( year, month, 1 ) . days_in_month ( ) ;
10071006 ( 1 ..=days_in_month) . contains ( & day)
10081007}
10091008
0 commit comments