Add Diary::new_entry_by_id()

to generate a new entry from a DiaryId object.

Rewrite Diary::new_entry_today() to use this new functionality for more
DRY code.
This commit is contained in:
Matthias Beyer 2016-06-07 20:20:27 +02:00
parent 7c50dd88b5
commit ecba4e670f

View file

@ -36,11 +36,12 @@ impl<'a> Diary<'a> {
pub fn new_entry_today(&self) -> Result<Entry> { pub fn new_entry_today(&self) -> Result<Entry> {
let dt = Local::now(); let dt = Local::now();
let ndt = dt.naive_local(); let ndt = dt.naive_local();
// Currenty we only have support for per-day entries
let id = DiaryId::new(String::from(self.name), ndt.year(), ndt.month(), ndt.day(), 0, 0); let id = DiaryId::new(String::from(self.name), ndt.year(), ndt.month(), ndt.day(), 0, 0);
self.new_entry_by_id(id)
}
self.retrieve(id) pub fn new_entry_by_id(&self, id: DiaryId) -> Result<Entry> {
self.retrieve(id.with_diary_name(String::from(self.name)))
} }
pub fn retrieve(&self, id: DiaryId) -> Result<Entry> { pub fn retrieve(&self, id: DiaryId) -> Result<Entry> {