@@ -14,6 +14,8 @@ use core_maths::*;
14
14
15
15
/// The *Rata Die*, or *R.D.*: number of days since January 1, 1 CE.
16
16
///
17
+ /// **The primary definition of this type is in the [`calendrical_calculations`](https://docs.rs/calendrical_calculations) crate.**
18
+ ///
17
19
/// See: <https://en.wikipedia.org/wiki/Rata_Die>
18
20
///
19
21
/// Typically, one should obtain RataDies from other calendrical code, rather than constructing them from integers.
@@ -52,7 +54,7 @@ impl RataDie {
52
54
}
53
55
54
56
/// A valid `RataDie` that is intended to be below all dates representable in calendars
55
- #[ doc( hidden) ]
57
+ #[ doc( hidden) ] // for testing only
56
58
pub const fn big_negative ( ) -> Self {
57
59
Self :: new ( i64:: MIN / 256 / 256 )
58
60
}
@@ -68,13 +70,16 @@ impl RataDie {
68
70
}
69
71
70
72
/// 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 {
72
74
self . 0 - rhs. 0
73
75
}
74
76
75
77
/// 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
78
83
}
79
84
80
85
/// Convert this to a [`Moment`]
@@ -98,18 +103,13 @@ impl fmt::Debug for RataDie {
98
103
impl Add < i64 > for RataDie {
99
104
type Output = Self ;
100
105
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)
105
107
}
106
108
}
107
109
108
110
impl AddAssign < i64 > for RataDie {
109
111
fn add_assign ( & mut self , rhs : i64 ) {
110
112
self . 0 += rhs;
111
- #[ cfg( debug_assertions) ]
112
- self . check ( ) ;
113
113
}
114
114
}
115
115
@@ -127,16 +127,14 @@ impl Sub<i64> for RataDie {
127
127
impl SubAssign < i64 > for RataDie {
128
128
fn sub_assign ( & mut self , rhs : i64 ) {
129
129
self . 0 -= rhs;
130
- #[ cfg( debug_assertions) ]
131
- self . check ( ) ;
132
130
}
133
131
}
134
132
135
133
/// Calculate the number of days between two RataDie
136
134
impl Sub for RataDie {
137
135
type Output = i64 ;
138
136
fn sub ( self , rhs : Self ) -> Self :: Output {
139
- self . 0 - rhs. 0
137
+ self . until ( rhs)
140
138
}
141
139
}
142
140
0 commit comments