libimagtimetrack: Replace read with typed read
This commit is contained in:
parent
cb0cb21220
commit
397f79b238
1 changed files with 7 additions and 14 deletions
|
@ -38,7 +38,7 @@ use constants::*;
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use toml_query::delete::TomlValueDeleteExt;
|
use toml_query::delete::TomlValueDeleteExt;
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
||||||
pub trait TimeTracking {
|
pub trait TimeTracking {
|
||||||
|
|
||||||
|
@ -64,15 +64,10 @@ impl TimeTracking for Entry {
|
||||||
|
|
||||||
fn get_timetrack_tag(&self) -> Result<TTT> {
|
fn get_timetrack_tag(&self) -> Result<TTT> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read(DATE_TIME_TAG_HEADER_PATH)
|
.read_string(DATE_TIME_TAG_HEADER_PATH)
|
||||||
.chain_err(|| TTEK::HeaderReadError)?
|
.chain_err(|| TTEK::HeaderReadError)?
|
||||||
.ok_or(TTE::from_kind(TTEK::HeaderReadError))
|
.ok_or(TTE::from_kind(TTEK::HeaderReadError))
|
||||||
.and_then(|v| {
|
|
||||||
v.as_str()
|
|
||||||
.map(String::from)
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.ok_or(TTE::from_kind(TTEK::HeaderFieldTypeError))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> {
|
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> {
|
||||||
|
@ -86,7 +81,7 @@ impl TimeTracking for Entry {
|
||||||
|
|
||||||
fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> {
|
fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read(DATE_TIME_START_HEADER_PATH)
|
.read_string(DATE_TIME_START_HEADER_PATH)
|
||||||
.chain_err(|| TTEK::HeaderReadError)
|
.chain_err(|| TTEK::HeaderReadError)
|
||||||
.and_then(header_value_to_dt)
|
.and_then(header_value_to_dt)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +104,7 @@ impl TimeTracking for Entry {
|
||||||
|
|
||||||
fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> {
|
fn get_end_datetime(&self) -> Result<Option<NaiveDateTime>> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read(DATE_TIME_END_HEADER_PATH)
|
.read_string(DATE_TIME_END_HEADER_PATH)
|
||||||
.chain_err(|| TTEK::HeaderReadError)
|
.chain_err(|| TTEK::HeaderReadError)
|
||||||
.and_then(header_value_to_dt)
|
.and_then(header_value_to_dt)
|
||||||
}
|
}
|
||||||
|
@ -139,15 +134,13 @@ impl TimeTracking for Entry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header_value_to_dt(val: Option<&Value>) -> Result<Option<NaiveDateTime>> {
|
fn header_value_to_dt(val: Option<String>) -> Result<Option<NaiveDateTime>> {
|
||||||
match val {
|
match val {
|
||||||
Some(&Value::String(ref s)) => {
|
Some(ref s) => {
|
||||||
NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT)
|
NaiveDateTime::parse_from_str(s, DATE_TIME_FORMAT)
|
||||||
.chain_err(|| TTEK::DateTimeParserError)
|
.chain_err(|| TTEK::DateTimeParserError)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
|
|
||||||
},
|
},
|
||||||
Some(_) => Err(TTE::from_kind(TTEK::HeaderFieldTypeError)),
|
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue