From 01f5b773ab89b809059e2212feb8547f8b073e91 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Tue, 17 Nov 2026 03:14:45 -0700 Subject: the delays are now synced to the seconds roll-over Force-Push: yes Change-Id: I6c9ea0a8dff7774f066783bca765d68189dfbb1d --- src/modules/time.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/modules/time.rs') diff --git a/src/modules/time.rs b/src/modules/time.rs index f8ef95c..25c5864 100644 --- a/src/modules/time.rs +++ b/src/modules/time.rs @@ -7,6 +7,7 @@ use time::format_description::{ FormatDescriptionV3, parse_owned }; pub struct TimeModule { time_format: FormatDescriptionV3<'static>, + most_recent_report: Option, } @@ -18,17 +19,32 @@ impl TimeModule { let time_format = parse_owned::<3>(&format_string).unwrap(); - Arc::new(Mutex::new(TimeModule { time_format })) + Arc::new(Mutex::new(TimeModule { + time_format, + most_recent_report: None, + })) } pub fn format(&mut self) -> String { let time = OffsetDateTime::now_local().unwrap(); + self.most_recent_report = Some(time); + time.format(&self.time_format).unwrap() } pub fn sleep_duration(&self) -> Option { - Some(Duration::from_millis(1000)) + if let Some(most_recent_report) = self.most_recent_report { + let (_, _, _, millis) = most_recent_report.to_hms_milli(); + + /* An easy way to check whether this behavior is correct is to open + * several copies of the dock atop each other, and check whether they're + * in sync. + */ + Some(Duration::from_millis(1001 - millis as u64)) + } else { + Some(Duration::from_millis(1000)) + } } } -- cgit 1.4.1