about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-11-14 00:23:24 -0700
committerIrene Knapp <ireneista@irenes.space>2026-11-14 00:23:24 -0700
commitd0c5a0eeec74de59a4919a42412d41fafb2593e3 (patch)
tree33fb09766da85df073d807d7102f65160134a63e
parent1869866eb174e3a796e7ff16ab51535d8201ab95 (diff)
move the time code into a module
also, there is now a concept of modules

and they're called "modules" because, really, what else would they be called :)

Force-Push: yes
Change-Id: I6b63fa19f5126dafc2de6184150365f5719333bf
-rw-r--r--src/main.rs18
-rw-r--r--src/modules.rs4
-rw-r--r--src/modules/time.rs27
3 files changed, 39 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 0276a45..60b6648 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,9 @@
 use crate::geometry::*;
+use crate::modules::*;
 use crate::x::*;
 
 use std::sync::Arc;
 
-use time::OffsetDateTime;
-use time::format_description::{ FormatDescriptionV3, parse_owned };
 use xcb::{ Xid };
 use xcb::x::{
   ClientMessageData,
@@ -18,6 +17,7 @@ use xcb::x::{
 };
 
 mod geometry;
+mod modules;
 mod x;
 
 
@@ -38,7 +38,7 @@ struct Dock {
   bounds: Arc<Rectangle<u16>>,
   font: Arc<Font>,
   baseline_position: i16,
-  time_format: FormatDescriptionV3<'static>,
+  time_module: TimeModule,
 }
 
 impl HasWindow for Dock {
@@ -125,17 +125,14 @@ impl Dock {
                             + vertical_padding as i16
                             + configuration.baseline_offset as i16;
 
-    let time_format_string = 
-        "[weekday repr:short] [year]-[month]-[day] ".to_owned()
-        + "[hour repr:24]:[minute]:[second]";
-    let time_format = parse_owned::<3>(&time_format_string).unwrap();
+    let time_module = TimeModule::new();
 
     let dock = Dock {
       window, configuration,
       bounds: Arc::new(dock_bounds),
       font,
       baseline_position,
-      time_format,
+      time_module,
     };
 
     dock.set_string_property(&xcb::x::ATOM_WM_NAME, b"sandbar")?;
@@ -242,8 +239,9 @@ impl Dock {
     }
 
     self.draw_text("playful cool fic tech nonfic", Alignment::Left)?;
-    let time = OffsetDateTime::now_local().unwrap();
-    self.draw_text(&time.format(&self.time_format).unwrap(), Alignment::Right)?;
+
+    let time = self.time_module.format();
+    self.draw_text(&time, Alignment::Right)?;
 
     Ok(())
   }
diff --git a/src/modules.rs b/src/modules.rs
new file mode 100644
index 0000000..0aeda34
--- /dev/null
+++ b/src/modules.rs
@@ -0,0 +1,4 @@
+pub use time::TimeModule;
+
+pub mod time;
+
diff --git a/src/modules/time.rs b/src/modules/time.rs
new file mode 100644
index 0000000..61a0cf8
--- /dev/null
+++ b/src/modules/time.rs
@@ -0,0 +1,27 @@
+use time::OffsetDateTime;
+use time::format_description::{ FormatDescriptionV3, parse_owned };
+
+
+pub struct TimeModule {
+  time_format: FormatDescriptionV3<'static>,
+}
+
+
+impl TimeModule {
+  pub fn new() -> TimeModule {
+    let format_string = 
+        "[weekday repr:short] [year]-[month]-[day] ".to_owned()
+        + "[hour repr:24]:[minute]:[second]";
+
+    let time_format = parse_owned::<3>(&format_string).unwrap();
+
+    TimeModule { time_format }
+  }
+
+  pub fn format(&self) -> String {
+    let time = OffsetDateTime::now_local().unwrap();
+
+    time.format(&self.time_format).unwrap()
+  }
+}
+