diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-06-07 20:20:27 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-06-08 13:59:41 +0200 |
commit | ecba4e670fff317b319b072cce7c1a50bf2802f9 (patch) | |
tree | a59c6b1665b66b06134222d852355fa59cd06ea9 /libimagdiary | |
parent | 7c50dd88b5b9c209b58d44194400ee4cff00fcaf (diff) |
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.
Diffstat (limited to 'libimagdiary')
-rw-r--r-- | libimagdiary/src/diary.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libimagdiary/src/diary.rs b/libimagdiary/src/diary.rs index 952c9900..a9939d56 100644 --- a/libimagdiary/src/diary.rs +++ b/libimagdiary/src/diary.rs @@ -34,13 +34,14 @@ impl<'a> Diary<'a> { // create or get a new entry for today pub fn new_entry_today(&self) -> Result<Entry> { - let dt = Local::now(); + let dt = Local::now(); let ndt = dt.naive_local(); + let id = DiaryId::new(String::from(self.name), ndt.year(), ndt.month(), ndt.day(), 0, 0); + self.new_entry_by_id(id) + } - // 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); - - 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> { |