Add functionality to create entry at a certain time

This commit is contained in:
Matthias Beyer 2018-06-08 02:19:55 +02:00
parent 851db4abe4
commit 22d63f0946
2 changed files with 11 additions and 4 deletions

View File

@ -18,9 +18,10 @@
//
use clap::ArgMatches;
use chrono::NaiveDateTime;
use chrono::Local;
use libimagdiary::diary::Diary;
use libimagdiary::diaryid::DiaryId;
use libimagdiary::error::DiaryErrorKind as DEK;
use libimagdiary::error::ResultExt;
use libimagentryedit::edit::Edit;
@ -130,7 +131,7 @@ fn create_id_from_clispec(create: &ArgMatches, diaryname: &str, timed_type: Time
.map_err(|_| warn!("Could not parse minute: '{}'", s))
.ok()
})
.unwrap_or(time.minute());
.unwrap_or(ndt.minute());
time.with_minute(min)
.with_second(0)
@ -146,7 +147,7 @@ fn create_id_from_clispec(create: &ArgMatches, diaryname: &str, timed_type: Time
.map_err(|_| warn!("Could not parse minute: '{}'", s))
.ok()
})
.unwrap_or(time.minute());
.unwrap_or(ndt.minute());
let sec = create
.value_of("second")
@ -156,7 +157,7 @@ fn create_id_from_clispec(create: &ArgMatches, diaryname: &str, timed_type: Time
.map_err(|_| warn!("Could not parse second: '{}'", s))
.ok()
})
.unwrap_or(time.second());
.unwrap_or(ndt.second());
time.with_minute(min).with_second(sec)
},

View File

@ -47,6 +47,8 @@ pub trait Diary {
// create or get a new entry for now
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry>;
fn new_entry_at(&self, diary_name: &str, ndt: &NaiveDateTime) -> Result<FileLockEntry>;
// Get an iterator for iterating over all entries of a Diary
fn entries(&self, diary_name: &str) -> Result<DiaryEntryIterator>;
@ -73,6 +75,10 @@ impl Diary for Store {
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
let dt = Local::now();
let ndt = dt.naive_local();
self.new_entry_at(diary_name, &ndt)
}
fn new_entry_at(&self, diary_name: &str, ndt: &NaiveDateTime) -> Result<FileLockEntry> {
let id = DiaryId::new(String::from(diary_name),
ndt.year(),
ndt.month(),