use super::funejson::Value; use super::todo_item::Todo; use super::todo_item_validate_todo::{todos_from_value, todos_to_value}; use super::todo_list_add_todo::require_utc_now; use super::todo_list_toggle_todo::{complete_todo, require_today}; /// Complete every open todo as toggle_todo would (repeating ones roll forward /// and stay open), or reopen all once none is open. /// /// # Panics /// On a `now` that is not a UTC timestamp or a `today` that is not a date. pub fn toggle_all(todos: &[Todo], now: &str, today: &str) -> Vec { require_utc_now(now); require_today(today); if todos.iter().any(|t| !t.done) { return todos.iter().map(|t| if t.done { t.clone() } else { complete_todo(t, now, today) }).collect(); } todos .iter() .map(|t| { let mut open = t.clone(); open.done = false; open.completed_at = None; open }) .collect() } pub fn fune_vector(args: &[Value]) -> Value { todos_to_value(&toggle_all(&todos_from_value(&args[0]), args[1].as_str(), args[2].as_str())) }