Print dates in a nicer format
This commit is contained in:
parent
531a140c45
commit
3e70b2e2c9
5 changed files with 67 additions and 5 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use chrono::NaiveDate;
|
||||
use std::fmt;
|
||||
|
||||
use chrono::{Duration, NaiveDate};
|
||||
|
||||
use crate::files::commands::DoneDate;
|
||||
use crate::files::primitives::Time;
|
||||
|
|
@ -16,6 +18,25 @@ pub struct Dates {
|
|||
times: Option<Times>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -92,6 +113,14 @@ impl Dates {
|
|||
pub fn end_time(&self) -> Option<Time> {
|
||||
self.start_end_time().map(|times| times.1)
|
||||
}
|
||||
|
||||
pub fn move_by(&self, delta: Duration) -> Self {
|
||||
Self {
|
||||
root: self.root + delta,
|
||||
other: self.other + delta,
|
||||
times: self.times,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DoneDate> for Dates {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue