Skip to content

Commit

Permalink
feat: Display today's birthdays
Browse files Browse the repository at this point in the history
  • Loading branch information
ducdetronquito committed Dec 24, 2023
1 parent d48e2d0 commit 83dbd39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use chrono::{NaiveDate, NaiveDateTime};
use chrono::{Datelike, NaiveDate, NaiveDateTime};
use rusqlite::Connection;

fn get_db() -> Result<Connection> {
Expand Down Expand Up @@ -59,3 +59,13 @@ pub fn get_all_birthdays() -> Result<Vec<Birthday>> {
let birthdays: Result<Vec<Birthday>, rusqlite::Error> = birthday_iter.collect();
Ok(birthdays.unwrap())
}

pub fn get_birthdays_for_date(date: NaiveDate) -> Result<Vec<Birthday>> {
let birthdays = get_all_birthdays()?
.into_iter()
.filter(|birthday| {
birthday.date.month() == date.month() && birthday.date.day() == date.day()
})
.collect();
Ok(birthdays)
}
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
}

Expand Down

0 comments on commit 83dbd39

Please sign in to comment.