aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorJason Rodney Hansen2021-11-30 01:19:51 +0000
committerIvan Tham2021-12-05 08:22:58 +0000
commit584a31cd9047ce8f93b9eab9233c1b62a9278054 (patch)
tree765a3ca3bfc077987c571fbfe16a9be6b97d9a83 /helix-core/src
parentc74cd48f38863b3004eaf2b52336ed0597337044 (diff)
Used checked_add for years and months
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/increment/date_time.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/helix-core/src/increment/date_time.rs b/helix-core/src/increment/date_time.rs
index 39646a17..e4227386 100644
--- a/helix-core/src/increment/date_time.rs
+++ b/helix-core/src/increment/date_time.rs
@@ -340,7 +340,7 @@ fn ndays_in_month(year: i32, month: u32) -> u32 {
}
fn add_months(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> {
- let month = date_time.month0() as i64 + amount;
+ let month = (date_time.month0() as i64).checked_add(amount)?;
let year = date_time.year() + i32::try_from(month / 12).ok()?;
let year = if month.is_negative() { year - 1 } else { year };
@@ -359,7 +359,7 @@ fn add_months(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> {
}
fn add_years(date_time: NaiveDateTime, amount: i64) -> Option<NaiveDateTime> {
- let year = i32::try_from(date_time.year() as i64 + amount).ok()?;
+ let year = i32::try_from((date_time.year() as i64).checked_add(amount)?).ok()?;
let ndays = ndays_in_month(year, date_time.month());
if date_time.day() > ndays {