about summary refs log tree commit diff
path: root/src/modules/time.rs
blob: 8f6f41784d84619c3efb819afbac1271f41cf481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::time::Duration;

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(&mut self) -> String {
    let time = OffsetDateTime::now_local().unwrap();

    time.format(&self.time_format).unwrap()
  }

  pub fn sleep_duration(&self) -> Option<Duration> {
    Some(Duration::from_millis(1000))
  }
}