use super::funejson::Value; use super::dates_day_of_week::day_of_week; use super::dates_days_between::days_between; use super::todo_item::{todo_from_value, Todo}; /// One word for where a todo stands today; done wins, this-week is the rest /// of the ISO week after tomorrow. /// /// # Panics /// Panics on an impossible or malformed date. pub fn due_status(todo: &Todo, today: &str) -> String { match &todo.due { Some(due) => { days_between(today, due); } None => { day_of_week(today); } } if todo.done { return "done".to_string(); } let due = match &todo.due { None => return "none".to_string(), Some(d) => d, }; let days = days_between(today, due); let status = if days < 0 { "overdue" } else if days == 0 { "today" } else if days == 1 { "tomorrow" } else if days <= 7 - day_of_week(today) { "this-week" } else { "later" }; status.to_string() } pub fn fune_vector(args: &[Value]) -> Value { Value::str(&due_status(&todo_from_value(&args[0]), args[1].as_str())) }