Skip to content

Commit

Permalink
Fixes chrono deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpii committed Nov 21, 2022
1 parent bfa4e8d commit 32173e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions src/agenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Widget {

let list = crate::application::tasks();
let (y, m, d) = self.widgets.calendar.date();
let date = chrono::naive::NaiveDate::from_ymd(y as i32, m + 1, d);
let date = chrono::naive::NaiveDate::from_ymd_opt(y as i32, m + 1, d);

update!(self, past_exp, past, get_past_tasks, list, date);
update!(self, today_exp, today, get_today_tasks, list, date);
Expand All @@ -42,52 +42,52 @@ impl Widget {
fn get_past_tasks(
&self,
list: &crate::tasks::List,
date: chrono::naive::NaiveDate,
date: Option<chrono::naive::NaiveDate>,
) -> Vec<crate::tasks::Task> {
self.get_tasks(list, None, Some(date))
self.get_tasks(list, None, date)
}

fn get_today_tasks(
&self,
list: &crate::tasks::List,
date: chrono::naive::NaiveDate,
date: Option<chrono::naive::NaiveDate>,
) -> Vec<crate::tasks::Task> {
self.get_tasks(list, Some(date), Some(date.succ()))
self.get_tasks(list, date, date.and_then(|x| x.succ_opt()))
}

fn get_tomorrow_tasks(
&self,
list: &crate::tasks::List,
date: chrono::naive::NaiveDate,
date: Option<chrono::naive::NaiveDate>,
) -> Vec<crate::tasks::Task> {
self.get_tasks(
list,
Some(date.succ()),
Some(date + chrono::Duration::days(2)),
date.and_then(|x| x.succ_opt()),
date.map(|x| x + chrono::Duration::days(2)),
)
}

fn get_week_tasks(
&self,
list: &crate::tasks::List,
date: chrono::naive::NaiveDate,
date: Option<chrono::naive::NaiveDate>,
) -> Vec<crate::tasks::Task> {
self.get_tasks(
list,
Some(date + chrono::Duration::days(2)),
Some(date + chrono::Duration::weeks(1)),
date.map(|x| x + chrono::Duration::days(2)),
date.map(|x| x + chrono::Duration::weeks(1)),
)
}

fn get_month_tasks(
&self,
list: &crate::tasks::List,
date: chrono::naive::NaiveDate,
date: Option<chrono::naive::NaiveDate>,
) -> Vec<crate::tasks::Task> {
self.get_tasks(
list,
Some(date + chrono::Duration::weeks(1)),
Some(date + chrono::Duration::weeks(4)),
date.map(|x| x + chrono::Duration::weeks(1)),
date.map(|x| x + chrono::Duration::weeks(4)),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/date.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn today() -> chrono::naive::NaiveDate {
chrono::Local::now().date().naive_local()
chrono::Local::now().date_naive()
}
4 changes: 2 additions & 2 deletions src/widgets/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl relm::Widget for Task {

if date == today {
String::from("today")
} else if date == today.pred() {
} else if Some(date) == today.pred_opt() {
String::from("yesterday")
} else if date == today.succ() {
} else if Some(date) == today.succ_opt() {
String::from("tomorrow")
} else {
date.format("%Y-%m-%d").to_string()
Expand Down

0 comments on commit 32173e0

Please sign in to comment.