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:
parent
7c50dd88b5
commit
ecba4e670f
1 changed files with 6 additions and 5 deletions
|
@ -34,13 +34,14 @@ impl<'a> Diary<'a> {
|
||||||
|
|
||||||
// create or get a new entry for today
|
// create or get a new entry for today
|
||||||
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();
|
||||||
|
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
|
pub fn new_entry_by_id(&self, id: DiaryId) -> Result<Entry> {
|
||||||
let id = DiaryId::new(String::from(self.name), ndt.year(), ndt.month(), ndt.day(), 0, 0);
|
self.retrieve(id.with_diary_name(String::from(self.name)))
|
||||||
|
|
||||||
self.retrieve(id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve(&self, id: DiaryId) -> Result<Entry> {
|
pub fn retrieve(&self, id: DiaryId) -> Result<Entry> {
|
||||||
|
|
Loading…
Reference in a new issue