Add TimeTracking::get_timetrack_tag()

This commit is contained in:
Matthias Beyer 2017-07-15 15:02:00 +02:00
parent 58047d319a
commit b88e95f881
1 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,7 @@ use chrono::naive::datetime::NaiveDateTime;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
use tag::TimeTrackingTag as TTT;
use error::TimeTrackErrorKind as TTEK;
use error::MapErrInto;
use result::Result;
@ -41,6 +42,8 @@ use toml_query::read::TomlValueReadExt;
pub trait TimeTracking {
fn get_timetrack_tag(&self) -> Result<TTT>;
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()>;
fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>>;
@ -59,6 +62,16 @@ pub trait TimeTracking {
impl TimeTracking for Entry {
fn get_timetrack_tag(&self) -> Result<TTT> {
self.get_header()
.read(DATE_TIME_TAG_HEADER_PATH)
.map_err_into(TTEK::HeaderReadError)
.map(|value| match value {
Some(&Value::String(ref s)) => s.clone().into(),
_ => unimplemented!(),
})
}
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> {
let s = dt.format(DATE_TIME_FORMAT).to_string();