diff options
author | Joris Guyonvarch | 2025-05-02 11:22:40 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2025-05-02 11:22:40 +0200 |
commit | 7e56ec0f49ff30c750f5c44b65fb13442352ca89 (patch) | |
tree | 81c2c03ba4bab9e22210d4fee426f1352a742acb /src/cli | |
parent | 99f483927b1b8dd96be5846f338d37a37ab667ec (diff) |
Replace --list-today by --date today
Allow also using:
- --date yesterday
- --date tomorrow
- --date YYYY-MM-DD
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/mod.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 3674a08..aa54c08 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,13 +1,22 @@ use anyhow::Result; -use chrono::{Local, NaiveDate, NaiveDateTime, TimeZone}; +use chrono::{Local, NaiveDate, NaiveDateTime, TimeDelta, TimeZone}; use rusqlite::Connection; +use std::ops::{Add, Sub}; use crate::model::event::Event; use crate::{db, model::event}; -pub fn today(conn: &Connection) -> Result<String> { - let today = Local::now().date_naive(); - let events = between_inclusive(conn, today, today)?; +pub fn parse_date(s: String) -> Option<NaiveDate> { + match s.as_str() { + "yesterday" => Some(Local::now().sub(TimeDelta::days(1)).date_naive()), + "today" => Some(Local::now().date_naive()), + "tomorrow" => Some(Local::now().add(TimeDelta::days(1)).date_naive()), + _ => NaiveDate::parse_from_str(&s, "%Y-%m-%d").ok(), + } +} + +pub fn started_at_date(conn: &Connection, date: NaiveDate) -> Result<String> { + let events = between_inclusive(conn, date, date)?; Ok(format_events(events)) } |