Skip to content

Commit 4a8a864

Browse files
committed
Fix bug
1 parent ca4fcbd commit 4a8a864

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ci/date-check/src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ impl Date {
2020
let self_chrono = Utc.ymd(self.year.try_into().unwrap(), self.month, 1);
2121
let other_chrono = Utc.ymd(other.year.try_into().unwrap(), other.month, 1);
2222
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 {
2525
None
2626
} else {
27-
Some(days_since.try_into().unwrap())
27+
Some(months_since.try_into().unwrap())
2828
}
2929
}
3030
}
@@ -165,6 +165,13 @@ fn main() {
165165
mod tests {
166166
use super::*;
167167

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+
168175
#[test]
169176
fn test_date_regex() {
170177
let regex = make_date_regex();

0 commit comments

Comments
 (0)