use std::fmt; use chrono::{Duration, NaiveDate}; use crate::files::commands::DoneDate; use crate::files::primitives::Time; #[derive(Debug, Clone, Copy)] struct Times { root: Time, other: Time, } #[derive(Debug, Clone, Copy)] pub struct Dates { root: NaiveDate, other: NaiveDate, times: Option, } impl fmt::Display for Dates { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (start, end) = self.start_end(); match self.start_end_time() { Some((start_time, end_time)) if start == end && start_time == end_time => { write!(f, "{} {}", start, start_time) } Some((start_time, end_time)) if start == end => { write!(f, "{} {} -- {}", start, start_time, end_time) } Some((start_time, end_time)) => { write!(f, "{} {} -- {} {}", start, start_time, end, end_time) } None if start == end => write!(f, "{}", start), None => write!(f, "{} -- {}", start, end), } } } impl Dates { pub fn new(root: NaiveDate, other: NaiveDate) -> Self { Self { root, other, times: None, } } pub fn new_with_time( root: NaiveDate, root_time: Time, other: NaiveDate, other_time: Time, ) -> Self { Self { root, other, times: Some(Times { root: root_time, other: other_time, }), } } pub fn root(&self) -> NaiveDate { self.root } pub fn other(&self) -> NaiveDate { self.other } pub fn root_time(&self) -> Option