From a5bd54a8e00b4ec074b3cbe772e8648907a19419 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Fri, 19 Jul 2024 09:42:33 +0200 Subject: [PATCH] feat(timebar): add a timestamp that shows when the timer ends --- src/clock/timebar.rs | 6 ++++++ src/clock/ui.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/clock/timebar.rs b/src/clock/timebar.rs index 3d761d2..4be656e 100644 --- a/src/clock/timebar.rs +++ b/src/clock/timebar.rs @@ -24,6 +24,12 @@ impl TimeBarLength { } } +impl From for chrono::Duration { + fn from(value: TimeBarLength) -> Self { + Self::new(value.as_secs(), 0).expect("seconds out of bounds, cannot create duration") + } +} + impl Default for TimeBarLength { fn default() -> Self { Self::Minute diff --git a/src/clock/ui.rs b/src/clock/ui.rs index fe6dc7b..0027ab0 100644 --- a/src/clock/ui.rs +++ b/src/clock/ui.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Local, SubsecRound}; +use chrono::{DateTime, Local, SubsecRound, Timelike}; use libpt::log::{debug, error, trace}; use ratatui::layout::{Alignment, Rect}; use ratatui::style::{Style, Stylize}; @@ -150,7 +150,12 @@ pub fn timebarw_label<'a>( .unwrap(), ), }; - Paragraph::new(format!("{time_now} / {len}")) + let until = last_reset + .checked_add_signed(len.into()) + .expect("could not calculate when the countdown finishes"); + let timestamp_until: String = + format!("{}:{}:{}", until.hour(), until.minute(), until.second()); + Paragraph::new(format!("{time_now} / {len} ({timestamp_until})")) .alignment(Alignment::Center) .block( Block::default().padding(Padding::right(if inner_rect.width > 80 {