Add functionality to create entry at a certain time
This commit is contained in:
parent
851db4abe4
commit
22d63f0946
2 changed files with 11 additions and 4 deletions
|
@ -18,9 +18,10 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
use chrono::Local;
|
||||||
|
|
||||||
use libimagdiary::diary::Diary;
|
use libimagdiary::diary::Diary;
|
||||||
use libimagdiary::diaryid::DiaryId;
|
|
||||||
use libimagdiary::error::DiaryErrorKind as DEK;
|
use libimagdiary::error::DiaryErrorKind as DEK;
|
||||||
use libimagdiary::error::ResultExt;
|
use libimagdiary::error::ResultExt;
|
||||||
use libimagentryedit::edit::Edit;
|
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))
|
.map_err(|_| warn!("Could not parse minute: '{}'", s))
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
.unwrap_or(time.minute());
|
.unwrap_or(ndt.minute());
|
||||||
|
|
||||||
time.with_minute(min)
|
time.with_minute(min)
|
||||||
.with_second(0)
|
.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))
|
.map_err(|_| warn!("Could not parse minute: '{}'", s))
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
.unwrap_or(time.minute());
|
.unwrap_or(ndt.minute());
|
||||||
|
|
||||||
let sec = create
|
let sec = create
|
||||||
.value_of("second")
|
.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))
|
.map_err(|_| warn!("Could not parse second: '{}'", s))
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
.unwrap_or(time.second());
|
.unwrap_or(ndt.second());
|
||||||
|
|
||||||
time.with_minute(min).with_second(sec)
|
time.with_minute(min).with_second(sec)
|
||||||
},
|
},
|
||||||
|
|
|
@ -47,6 +47,8 @@ pub trait Diary {
|
||||||
// create or get a new entry for now
|
// create or get a new entry for now
|
||||||
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry>;
|
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
|
// Get an iterator for iterating over all entries of a Diary
|
||||||
fn entries(&self, diary_name: &str) -> Result<DiaryEntryIterator>;
|
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> {
|
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
|
||||||
let dt = Local::now();
|
let dt = Local::now();
|
||||||
let ndt = dt.naive_local();
|
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),
|
let id = DiaryId::new(String::from(diary_name),
|
||||||
ndt.year(),
|
ndt.year(),
|
||||||
ndt.month(),
|
ndt.month(),
|
||||||
|
|
Loading…
Reference in a new issue