@@ -12,17 +12,21 @@ use core::ops::{Add, AddAssign, Sub, SubAssign};
12
12
#[ allow( unused_imports) ]
13
13
use core_maths:: * ;
14
14
15
- /// The *Rata Die*, or *R.D.*, or `fixed_date` : number of days since January 1, 1 CE.
15
+ /// The *Rata Die*, or *R.D.*: number of days since January 1, 1 CE.
16
16
///
17
17
/// See: <https://en.wikipedia.org/wiki/Rata_Die>
18
18
///
19
- /// It is a logic error to construct a RataDie
20
- /// except from a date that is in range of one of the official calendars .
19
+ /// Typically, one should obtain RataDies from other calendrical code, rather than constructing them from integers.
20
+ /// The valid range for direct construction is deliberately not documented as it may change .
21
21
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
22
22
pub struct RataDie ( i64 ) ;
23
23
24
24
impl RataDie {
25
- /// Create a RataDie
25
+ /// Create a `RataDie`
26
+ ///
27
+ /// Typically, one should obtain `RataDie`s from other calendrical code, rather than
28
+ /// constructing them from integers. The valid range for direct construction is
29
+ /// deliberately not documented as it may change.
26
30
pub const fn new ( fixed_date : i64 ) -> Self {
27
31
let result = Self ( fixed_date) ;
28
32
#[ cfg( debug_assertions) ]
@@ -32,7 +36,7 @@ impl RataDie {
32
36
33
37
/// Check that it is in range
34
38
#[ cfg( debug_assertions) ]
35
- pub const fn check ( & self ) {
39
+ const fn check ( self ) {
36
40
if self . 0 > i64:: MAX / 256 {
37
41
debug_assert ! (
38
42
false ,
@@ -47,34 +51,34 @@ impl RataDie {
47
51
}
48
52
}
49
53
50
- /// A valid RataDie that is intended to be below all dates representable in calendars
51
- #[ doc( hidden) ] // for testing only
54
+ /// A valid ` RataDie` that is intended to be below all dates representable in calendars
55
+ #[ doc( hidden) ]
52
56
pub const fn big_negative ( ) -> Self {
53
57
Self :: new ( i64:: MIN / 256 / 256 )
54
58
}
55
59
56
- /// Convert this to an i64 value representing the RataDie
60
+ /// Convert this to an ` i64` value representing the ` RataDie`
57
61
pub const fn to_i64_date ( self ) -> i64 {
58
62
self . 0
59
63
}
60
64
61
- /// Convert this to an f64 value representing the RataDie
62
- pub const fn to_f64_date ( self ) -> f64 {
65
+ /// Convert this to an ` f64` value representing the ` RataDie`
66
+ pub ( crate ) const fn to_f64_date ( self ) -> f64 {
63
67
self . 0 as f64
64
68
}
65
69
66
- /// Calculate the number of days between two RataDie in a const-friendly way
70
+ /// Calculate the number of days between two ` RataDie` in a const-friendly way
67
71
pub const fn const_diff ( self , rhs : Self ) -> i64 {
68
72
self . 0 - rhs. 0
69
73
}
70
74
71
- /// Adds a number of days to this RataDie in a const-friendly way
75
+ /// Adds a number of days to this ` RataDie` in a const-friendly way
72
76
pub const fn const_add ( self , rhs : i64 ) -> Self {
73
77
Self ( self . 0 + rhs)
74
78
}
75
79
76
80
/// Convert this to a [`Moment`]
77
- pub const fn as_moment ( & self ) -> Moment {
81
+ pub ( crate ) const fn as_moment ( self ) -> Moment {
78
82
Moment :: new ( self . 0 as f64 )
79
83
}
80
84
}
@@ -141,7 +145,7 @@ impl Sub for RataDie {
141
145
/// NOTE: This should not cause overflow errors for most cases, but consider
142
146
/// alternative implementations if necessary.
143
147
#[ derive( Debug , Copy , Clone , PartialEq , PartialOrd ) ]
144
- pub struct Moment ( f64 ) ;
148
+ pub ( crate ) struct Moment ( f64 ) ;
145
149
146
150
/// Add a number of days to a Moment
147
151
impl Add < f64 > for Moment {
@@ -186,12 +190,12 @@ impl Moment {
186
190
}
187
191
188
192
/// Get the inner field of a Moment
189
- pub const fn inner ( & self ) -> f64 {
193
+ pub const fn inner ( self ) -> f64 {
190
194
self . 0
191
195
}
192
196
193
197
/// Get the RataDie of a Moment
194
- pub fn as_rata_die ( & self ) -> RataDie {
198
+ pub fn as_rata_die ( self ) -> RataDie {
195
199
RataDie :: new ( self . 0 . floor ( ) as i64 )
196
200
}
197
201
}
0 commit comments