about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-17 03:14:45 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-17 03:14:45 -0700
commit01f5b773ab89b809059e2212feb8547f8b073e91 (patch)
treea5b497571f3f260a81b0cbdd34dbcae533a17869
parent0a3ceb20be3c174641f3e1fb9eee600edbfcd90d (diff)
the delays are now synced to the seconds roll-over
Force-Push: yes
Change-Id: I6c9ea0a8dff7774f066783bca765d68189dfbb1d
-rw-r--r--src/modules/time.rs20
1 files changed, 18 insertions, 2 deletions
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<OffsetDateTime>,
 }
 
 
@@ -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<Duration> {
-    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))
+    }
   }
 }