about summary refs log tree commit diff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/time.rs27
1 files changed, 27 insertions, 0 deletions
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()
+  }
+}
+