diff --git a/src/backup/mod.rs b/src/backup/mod.rs index ea7f2f9..f569697 100644 --- a/src/backup/mod.rs +++ b/src/backup/mod.rs @@ -33,8 +33,6 @@ 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, @@ -119,7 +117,6 @@ impl Backup { Ok(Backup { type_: BackupType::Full, start_time, - end_time: chrono::Utc::now(), size: tar_gz.bytes_written(), delta, metadata: None, @@ -177,7 +174,6 @@ impl Backup { Ok(Backup { type_: BackupType::Incremental, start_time, - end_time: chrono::Utc::now(), size: tar_gz.bytes_written(), delta, metadata: None, @@ -239,17 +235,19 @@ impl fmt::Display for Backup { // Pretty-print size // If your backup is a petabyte or larger, this will crash and you need to re-evaluate your // 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; + let mut index = 0; + let mut size = self.size as f64; + + while size >= 1024.0 { + index += 1; + size /= 1024.0; + } write!( f, - "{} ({}, {}m{}s, {:.2}{}, {})", + "{} ({}, {:.2}{}, {})", self.start_time.format(Backup::FILENAME_FORMAT), letter, - duration.num_seconds() / 60, - duration.num_seconds() % 60, size, BYTE_SUFFIXES[index], self.delta