Fix serious issue with adding days. Origin chrono v4.23

This commit is contained in:
jude 2023-06-20 15:30:44 +01:00
parent bb1c61d0b9
commit e025d945cf
3 changed files with 777 additions and 677 deletions

1405
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package] [package]
name = "reminder-rs" name = "reminder-rs"
version = "1.6.14" version = "1.6.16"
authors = ["Jude Southworth <judesouthworth@pm.me>"] authors = ["Jude Southworth <judesouthworth@pm.me>"]
edition = "2021" edition = "2021"
license = "AGPL-3.0 only" license = "AGPL-3.0 only"

View File

@ -309,6 +309,7 @@ WHERE
AND ( AND (
reminders.`interval_seconds` IS NOT NULL reminders.`interval_seconds` IS NOT NULL
OR reminders.`interval_months` IS NOT NULL OR reminders.`interval_months` IS NOT NULL
OR reminders.`interval_days` IS NOT NULL
OR reminders.enabled OR reminders.enabled
) )
GROUP BY channel_id GROUP BY channel_id
@ -349,36 +350,48 @@ WHERE
|| self.interval_months.is_some() || self.interval_months.is_some()
|| self.interval_days.is_some() || self.interval_days.is_some()
{ {
// If all intervals are zero then dont care
if self.interval_seconds == Some(0)
&& self.interval_days == Some(0)
&& self.interval_months == Some(0)
{
self.force_delete(pool).await;
}
let now = Utc::now(); let now = Utc::now();
let mut updated_reminder_time = let mut updated_reminder_time =
self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC)); self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC));
while updated_reminder_time < now { while updated_reminder_time < now {
if let Some(interval) = self.interval_months { if let Some(interval) = self.interval_months {
if interval != 0 {
updated_reminder_time = updated_reminder_time updated_reminder_time = updated_reminder_time
.checked_add_months(Months::new(interval)) .checked_add_months(Months::new(interval))
.unwrap_or_else(|| { .unwrap_or_else(|| {
warn!("Could not add months to a reminder"); warn!(
"{}: Could not add {} months to a reminder",
interval, self.id
);
updated_reminder_time updated_reminder_time
}); });
} }
}
if let Some(interval) = self.interval_days { if let Some(interval) = self.interval_days {
updated_reminder_time = updated_reminder_time if interval != 0 {
.checked_add_days(Days::new(interval as u64)) if let Some(new_time) =
.unwrap_or_else(|| { updated_reminder_time.checked_add_days(Days::new(interval as u64))
warn!( {
"Could not add days to a reminder. Falling back to naive addition" updated_reminder_time = new_time
); } else {
warn!("{}: Could not add {} days to a reminder", self.id, interval);
updated_reminder_time + 86400 * interval }
}); }
} }
if let Some(interval) = self.interval_seconds { if let Some(interval) = self.interval_seconds {
updated_reminder_time = updated_reminder_time += Duration::seconds(interval as i64);
updated_reminder_time + Duration::seconds(interval as i64);
} }
} }