aboutsummaryrefslogtreecommitdiff
path: root/src/cli/mod.rs
blob: 88726cac4bb1cb9418b36605f93a80152a3f258f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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_recurring_between(conn, today, today)?;
    let recurring_events = db::list_recurring(conn)?;
    let repetitions = event::repetitions_between(&recurring_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"))
}