summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-06-08 02:19:55 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-07-20 01:37:36 +0200
commit22d63f0946026aaad93daff370e1910b50f0e8c0 (patch)
treeef8a59c6b5f7e52fab72a73bd39984aacbf36cd8
parent851db4abe4d8d0aebafe35ef41c5594213b1be6b (diff)
downloadimag-22d63f0946026aaad93daff370e1910b50f0e8c0.zip
imag-22d63f0946026aaad93daff370e1910b50f0e8c0.tar.gz
Add functionality to create entry at a certain time
-rw-r--r--bin/domain/imag-diary/src/create.rs9
-rw-r--r--lib/domain/libimagdiary/src/diary.rs6
2 files changed, 11 insertions, 4 deletions
diff --git a/bin/domain/imag-diary/src/create.rs b/bin/domain/imag-diary/src/create.rs
index 148c4b5..bc39765 100644
--- a/bin/domain/imag-diary/src/create.rs
+++ b/bin/domain/imag-diary/src/create.rs
@@ -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)
},
diff --git a/lib/domain/libimagdiary/src/diary.rs b/lib/domain/libimagdiary/src/diary.rs
index ea4b249..779c7d5 100644
--- a/lib/domain/libimagdiary/src/diary.rs
+++ b/lib/domain/libimagdiary/src/diary.rs
@@ -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(),