File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ impl Date {
20
20
let self_chrono = Utc . ymd ( self . year . try_into ( ) . unwrap ( ) , self . month , 1 ) ;
21
21
let other_chrono = Utc . ymd ( other. year . try_into ( ) . unwrap ( ) , other. month , 1 ) ;
22
22
let duration_since = self_chrono. signed_duration_since ( other_chrono) ;
23
- let days_since = duration_since. num_days ( ) ;
24
- if days_since < 0 {
23
+ let months_since = duration_since. num_days ( ) / 30 ;
24
+ if months_since < 0 {
25
25
None
26
26
} else {
27
- Some ( days_since . try_into ( ) . unwrap ( ) )
27
+ Some ( months_since . try_into ( ) . unwrap ( ) )
28
28
}
29
29
}
30
30
}
@@ -165,6 +165,13 @@ fn main() {
165
165
mod tests {
166
166
use super :: * ;
167
167
168
+ #[ test]
169
+ fn test_months_since ( ) {
170
+ let date1 = Date { year : 2020 , month : 3 } ;
171
+ let date2 = Date { year : 2021 , month : 1 } ;
172
+ assert_eq ! ( date2. months_since( date1) , Some ( 10 ) ) ;
173
+ }
174
+
168
175
#[ test]
169
176
fn test_date_regex ( ) {
170
177
let regex = make_date_regex ( ) ;
You can’t perform that action at this time.
0 commit comments