From 19c1939cfb60b90923d522dbb386f669ab86cf96 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 19 Jul 2024 10:26:45 +0200 Subject: [PATCH] fix(modeshow): fix #17 by conditionally setting the seconds to 0 --- src/clock/ui.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/clock/ui.rs b/src/clock/ui.rs index 3fd8480..5d2d1db 100644 --- a/src/clock/ui.rs +++ b/src/clock/ui.rs @@ -150,18 +150,20 @@ pub fn timebarw_label<'a>( .unwrap(), ), }; - let until = last_reset - // BUG: seconds are sometimes a little too much, for - // example with `-o` #17 - .checked_add_signed(len.into()) - .expect("could not calculate when the countdown finishes"); - let timestamp_until: String = format!( - "{:02}:{:02}:{:02}", - until.hour(), - until.minute(), - until.second() - ); - Paragraph::new(format!("{time_now} / {len} ({timestamp_until})")) + let until = { + // we need to cut off the seconds if we're not in custom and countup mode, otherwise, + // the timestamp will not be correct. This fixes #17 + match len { + TimeBarLength::Custom(_) | TimeBarLength::Countup(_) => last_reset, + _ => last_reset.with_second(0).unwrap(), + } + } + // BUG: seconds are sometimes a little too much, for + // example with `-o` #17 + .checked_add_signed(len.into()) + .expect("could not calculate when the countdown finishes") + .format("%H:%M:%S"); + Paragraph::new(format!("{time_now} / {len} ({until})")) .alignment(Alignment::Center) .block( Block::default().padding(Padding::right(if inner_rect.width > 80 {