From 32d923e64bcb7150d7a76780ea5840d3c72f82a6 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 8 Jul 2023 13:53:18 +0200 Subject: [PATCH] refactor: this is fun --- src/backup/manager/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/backup/manager/mod.rs b/src/backup/manager/mod.rs index db53ad8..6a43f9f 100644 --- a/src/backup/manager/mod.rs +++ b/src/backup/manager/mod.rs @@ -153,13 +153,11 @@ where /// Calculate the next time a backup should be created. If no backup has been created yet, it /// will return now. pub fn next_scheduled_time(&self) -> chrono::DateTime { - if let Some(last_chain) = self.chains.last() { - if let Some(last_backup) = last_chain.last() { - return last_backup.start_time + self.frequency; - } - } - - chrono::offset::Utc::now() + self.chains + .last() + .and_then(|last_chain| last_chain.last()) + .map(|last_backup| last_backup.start_time + self.frequency) + .unwrap_or_else(chrono::offset::Utc::now) } /// Search for a chain containing a backup with the specified start time.