From 83dbd39f8b06bfde1bf3b3e278c89dda316be687 Mon Sep 17 00:00:00 2001 From: ducdetronquito Date: Sun, 24 Dec 2023 11:37:01 +0100 Subject: [PATCH] feat: Display today's birthdays --- src/lib.rs | 12 +++++++++++- src/main.rs | 7 ++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c3d4212..408b44b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use chrono::{NaiveDate, NaiveDateTime}; +use chrono::{Datelike, NaiveDate, NaiveDateTime}; use rusqlite::Connection; fn get_db() -> Result { @@ -59,3 +59,13 @@ pub fn get_all_birthdays() -> Result> { let birthdays: Result, rusqlite::Error> = birthday_iter.collect(); Ok(birthdays.unwrap()) } + +pub fn get_birthdays_for_date(date: NaiveDate) -> Result> { + let birthdays = get_all_birthdays()? + .into_iter() + .filter(|birthday| { + birthday.date.month() == date.month() && birthday.date.day() == date.day() + }) + .collect(); + Ok(birthdays) +} diff --git a/src/main.rs b/src/main.rs index 3d7a673..927c4ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,12 @@ fn main() -> Result<()> { } Command::Next {} => todo!(), Command::Search { .. } => todo!(), - Command::Today {} => todo!(), + Command::Today {} => { + let today = Utc::now().date_naive(); + let birthdays = birthday::get_birthdays_for_date(today)?; + print_birthdays(birthdays); + Ok(()) + } } }