diff options
author | Joris | 2022-02-26 23:18:13 +0100 |
---|---|---|
committer | Joris | 2022-02-26 23:18:13 +0100 |
commit | 5f1f9065476a46ccced3f1b0e31a90d3a00eccef (patch) | |
tree | eef7608e7dc9e0134719bc6c9d8e3676f958fa3c /src/cli | |
parent | 68285db2c187b350bb2b1707071382bd9fbaa2a5 (diff) |
Add --list-today CLI param to list today’s events
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cli/mod.rs b/src/cli/mod.rs new file mode 100644 index 0000000..862bcbe --- /dev/null +++ b/src/cli/mod.rs @@ -0,0 +1,21 @@ +use anyhow::Result; +use chrono::Local; +use rusqlite::Connection; + +use crate::{db, model::event, model::event::Event}; + +pub fn today(conn: &Connection) -> Result<String> { + let today = Local::today().naive_local(); + let mut events = db::list_non_repeated_between(conn, today, today)?; + let repeated_events = db::list_repeated(conn)?; + let repetitions = event::repetitions_between(&repeated_events, today, today); + for repetition in repetitions.values().flatten() { + events.push(repetition.clone()); + } + events.sort_by_key(|e| e.start); + Ok(events + .iter() + .map(Event::pprint) + .collect::<Vec<String>>() + .join("\n")) +} |