@@ -91,7 +91,7 @@ impl IsoDateTime {
91
91
// 3. Let epochMilliseconds be 𝔽((epochNanoseconds - remainderNs) / 10^6).
92
92
let epoch_millis = ( mathematical_nanos - remainder_nanos) / 1_000_000 ;
93
93
94
- let ( year, month, day) = utils:: ymd_from_epoch_milliseconds ( epoch_millis) ;
94
+ let ( year, month, day) = utils:: Epoch :: new ( epoch_millis) . ymd ( ) ;
95
95
96
96
// 7. Let hour be ℝ(! HourFromTime(epochMilliseconds)).
97
97
let hour = epoch_millis. div_euclid ( 3_600_000 ) . rem_euclid ( 24 ) ;
@@ -344,8 +344,7 @@ impl IsoDate {
344
344
/// Equivalent to `BalanceISODate`.
345
345
pub ( crate ) fn balance ( year : i32 , month : i32 , day : i32 ) -> Self {
346
346
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 ( ) ;
349
348
Self :: new_unchecked ( year, month, day)
350
349
}
351
350
@@ -367,7 +366,7 @@ impl IsoDate {
367
366
/// Equivalent to `IsoDateToEpochDays`
368
367
#[ inline]
369
368
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 ( )
371
370
}
372
371
373
372
/// Returns if the current `IsoDate` is valid.
@@ -488,12 +487,13 @@ impl IsoDate {
488
487
489
488
// NOTE: Below is adapted from the polyfill. Preferring this as it avoids looping.
490
489
// 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 (
493
492
constrained. year ,
494
493
constrained. month ,
495
494
constrained. day ,
496
- ) ;
495
+ )
496
+ . days ( ) ;
497
497
498
498
let ( weeks, days) = if largest_unit == TemporalUnit :: Week {
499
499
( days / 7 , days % 7 )
@@ -905,8 +905,7 @@ const MAX_EPOCH_DAYS: i32 = 10i32.pow(8) + 1;
905
905
#[ inline]
906
906
/// Utility function to determine if a `DateTime`'s components create a `DateTime` within valid limits
907
907
fn 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 {
910
909
return false ;
911
910
}
912
911
@@ -927,7 +926,7 @@ fn utc_epoch_nanos(date: IsoDate, time: &IsoTime) -> TemporalResult<EpochNanosec
927
926
#[ inline]
928
927
fn to_unchecked_epoch_nanoseconds ( date : IsoDate , time : & IsoTime ) -> i128 {
929
928
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 ;
931
930
epoch_ms as i128 * 1_000_000 + time. microsecond as i128 * 1_000 + time. nanosecond as i128
932
931
}
933
932
@@ -943,10 +942,10 @@ pub(crate) fn iso_date_to_epoch_days(year: i32, month: i32, day: i32) -> i32 {
943
942
let resolved_month = month. rem_euclid ( 12 ) as u8 ;
944
943
// 3. Find a time t such that EpochTimeToEpochYear(t) is resolvedYear,
945
944
// 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 ) ;
947
946
948
947
// 4. Return EpochTimeToDayNumber(t) + date - 1.
949
- epoch_days + day - 1
948
+ epoch_days. days ( ) + day - 1
950
949
}
951
950
952
951
#[ inline]
@@ -997,13 +996,13 @@ fn balance_iso_year_month(year: i32, month: i32) -> (i32, u8) {
997
996
/// Note: month is 1 based.
998
997
#[ inline]
999
998
pub ( 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 ( ) ;
1001
1000
day. clamp ( 1 , days_in_month)
1002
1001
}
1003
1002
1004
1003
#[ inline]
1005
1004
pub ( 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 ( ) ;
1007
1006
( 1 ..=days_in_month) . contains ( & day)
1008
1007
}
1009
1008
0 commit comments