Skip to content

Commit 6a0f09e

Browse files
Followup #6440 (#6461)
Fixes #6386
1 parent fe0a82d commit 6a0f09e

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

components/calendar/src/provider/hijri.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl PackedHijriYearInfo {
7575
month_lengths: [bool; 12],
7676
start_day: RataDie,
7777
) -> Self {
78-
let start_offset = start_day.const_diff(Self::mean_synodic_start_day(extended_year));
78+
let start_offset = start_day.until(Self::mean_synodic_start_day(extended_year));
7979

8080
debug_assert!(
8181
-8 < start_offset && start_offset < 8,
@@ -117,7 +117,7 @@ impl PackedHijriYearInfo {
117117
const fn mean_synodic_start_day(extended_year: i32) -> RataDie {
118118
// -1 because the epoch is new year of year 1
119119
// truncating instead of flooring does not matter, as this is used for positive years only
120-
calendrical_calculations::islamic::ISLAMIC_EPOCH_FRIDAY.const_add(
120+
calendrical_calculations::islamic::ISLAMIC_EPOCH_FRIDAY.add(
121121
((extended_year - 1) as f64 * calendrical_calculations::islamic::MEAN_YEAR_LENGTH)
122122
as i64,
123123
)

utils/calendrical_calculations/src/ethiopian.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::helpers::I32CastError;
1111
use crate::rata_die::RataDie;
1212

1313
const ETHIOPIC_TO_COPTIC_OFFSET: i64 =
14-
super::coptic::COPTIC_EPOCH.const_diff(crate::julian::fixed_from_julian(8, 8, 29));
14+
super::coptic::COPTIC_EPOCH.until(crate::julian::fixed_from_julian(8, 8, 29));
1515

1616
/// Lisp code reference: <https://github.com/EdReingold/calendar-code2/blob/1ee51ecfaae6f856b0d7de3e36e9042100b4f424/calendar.l#L2017>
1717
pub fn fixed_from_ethiopian(year: i32, month: u8, day: u8) -> RataDie {

utils/calendrical_calculations/src/iso.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn fixed_from_iso(year: i32, month: u8, day: u8) -> RataDie {
5353
/// Lisp code reference: <https://github.com/EdReingold/calendar-code2/blob/1ee51ecfaae6f856b0d7de3e36e9042100b4f424/calendar.l#L1191-L1217>
5454
pub(crate) const fn iso_year_from_fixed(date: RataDie) -> i64 {
5555
// Shouldn't overflow because it's not possbile to construct extreme values of RataDie
56-
let date = date.const_diff(EPOCH);
56+
let date = date.until(EPOCH);
5757

5858
// 400 year cycles have 146097 days
5959
let (n_400, date) = (date.div_euclid(146097), date.rem_euclid(146097));

utils/calendrical_calculations/src/rata_die.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use core_maths::*;
1414

1515
/// The *Rata Die*, or *R.D.*: number of days since January 1, 1 CE.
1616
///
17+
/// **The primary definition of this type is in the [`calendrical_calculations`](https://docs.rs/calendrical_calculations) crate.**
18+
///
1719
/// See: <https://en.wikipedia.org/wiki/Rata_Die>
1820
///
1921
/// Typically, one should obtain RataDies from other calendrical code, rather than constructing them from integers.
@@ -52,7 +54,7 @@ impl RataDie {
5254
}
5355

5456
/// A valid `RataDie` that is intended to be below all dates representable in calendars
55-
#[doc(hidden)]
57+
#[doc(hidden)] // for testing only
5658
pub const fn big_negative() -> Self {
5759
Self::new(i64::MIN / 256 / 256)
5860
}
@@ -68,13 +70,16 @@ impl RataDie {
6870
}
6971

7072
/// Calculate the number of days between two `RataDie` in a const-friendly way
71-
pub const fn const_diff(self, rhs: Self) -> i64 {
73+
pub const fn until(self, rhs: Self) -> i64 {
7274
self.0 - rhs.0
7375
}
7476

7577
/// Adds a number of days to this `RataDie` in a const-friendly way
76-
pub const fn const_add(self, rhs: i64) -> Self {
77-
Self(self.0 + rhs)
78+
pub const fn add(self, rhs: i64) -> Self {
79+
let result = Self(self.0 + rhs);
80+
#[cfg(debug_assertions)]
81+
result.check();
82+
result
7883
}
7984

8085
/// Convert this to a [`Moment`]
@@ -98,18 +103,13 @@ impl fmt::Debug for RataDie {
98103
impl Add<i64> for RataDie {
99104
type Output = Self;
100105
fn add(self, rhs: i64) -> Self::Output {
101-
let result = Self(self.0 + rhs);
102-
#[cfg(debug_assertions)]
103-
result.check();
104-
result
106+
self.add(rhs)
105107
}
106108
}
107109

108110
impl AddAssign<i64> for RataDie {
109111
fn add_assign(&mut self, rhs: i64) {
110112
self.0 += rhs;
111-
#[cfg(debug_assertions)]
112-
self.check();
113113
}
114114
}
115115

@@ -127,16 +127,14 @@ impl Sub<i64> for RataDie {
127127
impl SubAssign<i64> for RataDie {
128128
fn sub_assign(&mut self, rhs: i64) {
129129
self.0 -= rhs;
130-
#[cfg(debug_assertions)]
131-
self.check();
132130
}
133131
}
134132

135133
/// Calculate the number of days between two RataDie
136134
impl Sub for RataDie {
137135
type Output = i64;
138136
fn sub(self, rhs: Self) -> Self::Output {
139-
self.0 - rhs.0
137+
self.until(rhs)
140138
}
141139
}
142140

0 commit comments

Comments
 (0)