Remove EntryMap
This commit is contained in:
parent
b5ef9e8134
commit
d8782fa28a
1 changed files with 3 additions and 45 deletions
|
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crate::files::commands::DoneDate;
|
||||
|
|
@ -15,6 +13,7 @@ pub enum EntryKind {
|
|||
Birthday,
|
||||
}
|
||||
|
||||
/// A single instance of a command.
|
||||
#[derive(Debug)]
|
||||
pub struct Entry {
|
||||
pub kind: EntryKind,
|
||||
|
|
@ -111,49 +110,8 @@ impl Entries {
|
|||
self.entries.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EntryMap {
|
||||
pub range: DateRange,
|
||||
map: HashMap<NaiveDate, Option<Entry>>,
|
||||
undated: Vec<Entry>,
|
||||
}
|
||||
|
||||
impl EntryMap {
|
||||
pub fn new(range: DateRange) -> Self {
|
||||
Self {
|
||||
range,
|
||||
map: HashMap::new(),
|
||||
undated: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn block(&mut self, date: NaiveDate) {
|
||||
if self.range.contains(date) {
|
||||
self.map.entry(date).or_insert(None);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, entry: Entry) {
|
||||
if let Some(date) = entry.root {
|
||||
let date = date.root();
|
||||
if self.range.contains(date) {
|
||||
self.map.entry(date).or_insert(Some(entry));
|
||||
} else if let EntryKind::TaskDone(done_date) = entry.kind {
|
||||
if self.range.contains(done_date) {
|
||||
self.map.entry(date).or_insert(Some(entry));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.undated.push(entry);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn drain(&mut self) -> Vec<Entry> {
|
||||
self.map
|
||||
.drain()
|
||||
.filter_map(|(_, entry)| entry)
|
||||
.chain(self.undated.drain(..))
|
||||
.collect()
|
||||
pub fn entries(self) -> Vec<Entry> {
|
||||
self.entries
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue