Add "daily" support
This commit is contained in:
parent
776e1dac91
commit
cedbaf1b5c
2 changed files with 12 additions and 2 deletions
|
@ -106,6 +106,13 @@ fn create_id_from_clispec(create: &ArgMatches, diaryname: &str, timed_type: Time
|
||||||
};
|
};
|
||||||
|
|
||||||
match timed_type {
|
match timed_type {
|
||||||
|
Timed::Daily => {
|
||||||
|
debug!("Creating daily-timed entry");
|
||||||
|
get_hourly_id(create)
|
||||||
|
.with_hour(0)
|
||||||
|
.with_minute(0)
|
||||||
|
.with_second(0)
|
||||||
|
},
|
||||||
Timed::Hourly => {
|
Timed::Hourly => {
|
||||||
debug!("Creating hourly-timed entry");
|
debug!("Creating hourly-timed entry");
|
||||||
get_hourly_id(create)
|
get_hourly_id(create)
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub fn get_diary_name(rt: &Runtime) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Timed {
|
pub enum Timed {
|
||||||
|
Daily,
|
||||||
Hourly,
|
Hourly,
|
||||||
Minutely,
|
Minutely,
|
||||||
Secondly,
|
Secondly,
|
||||||
|
@ -63,7 +64,7 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
|
||||||
Ok(Some(&Value::String(ref s))) => parse_timed_string(s, diary_name).map(Some),
|
Ok(Some(&Value::String(ref s))) => parse_timed_string(s, diary_name).map(Some),
|
||||||
|
|
||||||
Ok(Some(_)) => {
|
Ok(Some(_)) => {
|
||||||
let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'h'/'hourly' or 'm'/'minutely'", diary_name);
|
let s = format!("Type error at 'diary.diaryies.{}.timed': should be either 'd'/'daily', 'h'/'hourly', 'm'/'minutely' or 's'/'secondly'", diary_name);
|
||||||
Err(s).map_err(From::from)
|
Err(s).map_err(From::from)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -75,7 +76,9 @@ pub fn get_diary_timed_config(rt: &Runtime, diary_name: &str) -> Result<Option<T
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_timed_string(s: &str, diary_name: &str) -> Result<Timed> {
|
pub fn parse_timed_string(s: &str, diary_name: &str) -> Result<Timed> {
|
||||||
if s == "h" || s == "hourly" {
|
if s == "d" || s == "daily" {
|
||||||
|
Ok(Timed::Daily)
|
||||||
|
} else if s == "h" || s == "hourly" {
|
||||||
Ok(Timed::Hourly)
|
Ok(Timed::Hourly)
|
||||||
} else if s == "m" || s == "minutely" {
|
} else if s == "m" || s == "minutely" {
|
||||||
Ok(Timed::Minutely)
|
Ok(Timed::Minutely)
|
||||||
|
|
Loading…
Reference in a new issue