From f71db90922a8eaa3758e569e763d8f999caec53d Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Mon, 3 Jul 2023 12:59:50 +0200 Subject: [PATCH] feat: store end time as metadata --- src/backup/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backup/mod.rs b/src/backup/mod.rs index cb9aa16..ea7f2f9 100644 --- a/src/backup/mod.rs +++ b/src/backup/mod.rs @@ -33,6 +33,8 @@ pub enum BackupType { pub struct Backup { /// When the backup was started (also corresponds to the name) pub start_time: chrono::DateTime, + /// When the backup finished + pub end_time: chrono::DateTime, pub size: usize, /// Type of the backup pub type_: BackupType, @@ -117,6 +119,7 @@ impl Backup { Ok(Backup { type_: BackupType::Full, start_time, + end_time: chrono::Utc::now(), size: tar_gz.bytes_written(), delta, metadata: None, @@ -174,6 +177,7 @@ impl Backup { Ok(Backup { type_: BackupType::Incremental, start_time, + end_time: chrono::Utc::now(), size: tar_gz.bytes_written(), delta, metadata: None, @@ -237,12 +241,15 @@ impl fmt::Display for Backup { // life choices let index = self.size.ilog(1024) as usize; let size = self.size as f64 / (1024.0_f64.powi(index as i32)); + let duration = self.end_time - self.start_time; write!( f, - "{} ({}, {:.2}{}, {})", + "{} ({}, {}m{}s, {:.2}{}, {})", self.start_time.format(Backup::FILENAME_FORMAT), letter, + duration.num_seconds() / 60, + duration.num_seconds() % 60, size, BYTE_SUFFIXES[index], self.delta