Sort all entries after evaluation
This commit is contained in:
parent
3e70b2e2c9
commit
efa9b7de03
3 changed files with 19 additions and 12 deletions
14
src/eval.rs
14
src/eval.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::files::Files;
|
use crate::files::Files;
|
||||||
|
|
||||||
use self::command::CommandState;
|
use self::command::CommandState;
|
||||||
|
use self::date::Dates;
|
||||||
use self::entry::Entries;
|
use self::entry::Entries;
|
||||||
pub use self::entry::{Entry, EntryKind, EntryMode};
|
pub use self::entry::{Entry, EntryKind, EntryMode};
|
||||||
pub use self::error::{Error, Result};
|
pub use self::error::{Error, Result};
|
||||||
|
|
@ -22,6 +23,17 @@ impl Files {
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(entries.entries())
|
let mut entries = entries.entries();
|
||||||
|
entries.sort_by_key(|e| {
|
||||||
|
e.dates.map(|d| {
|
||||||
|
let (start, end) = d.start_end();
|
||||||
|
if let Some((start_time, end_time)) = d.start_end_time() {
|
||||||
|
(start, Some(start_time), end, Some(end_time))
|
||||||
|
} else {
|
||||||
|
(start, None, end, None)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
Ok(entries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,11 @@ impl<'a> CommandState<'a> {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn entries(mut self) -> Vec<Entry> {
|
pub fn entries(self) -> Vec<Entry> {
|
||||||
let mut keys = self.dated.keys().copied().collect::<Vec<_>>();
|
self.undated
|
||||||
keys.sort();
|
.into_iter()
|
||||||
|
.chain(self.dated.into_values())
|
||||||
let mut entries = self.undated;
|
.collect()
|
||||||
for key in keys {
|
|
||||||
entries.push(self.dated.remove(&key).unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
entries
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ impl Dates {
|
||||||
self.times.map(|times| times.other)
|
self.times.map(|times| times.other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_end(&self) -> (NaiveDate, NaiveDate) {
|
pub fn start_end(&self) -> (NaiveDate, NaiveDate) {
|
||||||
if self.root <= self.other {
|
if self.root <= self.other {
|
||||||
(self.root, self.other)
|
(self.root, self.other)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue