diff --git a/src/tools/systemd/parse_time.rs b/src/tools/systemd/parse_time.rs index 88f5c92d..c0f58b04 100644 --- a/src/tools/systemd/parse_time.rs +++ b/src/tools/systemd/parse_time.rs @@ -86,6 +86,19 @@ lazy_static! { map }; } + +struct TimeSpec { + hour: Vec, + minute: Vec, + second: Vec, +} + +struct DateSpec { + year: Vec, + month: Vec, + day: Vec, +} + fn parse_time_comp(max: usize) -> impl Fn(&str) -> IResult<&str, u32> { move |i: &str| { let (i, v) = map_res(recognize(digit1), str::parse)(i)?; @@ -176,7 +189,7 @@ fn parse_date_time_comp_list(start: u32, max: usize) -> impl Fn(&str) -> IResult } } -fn parse_time_spec(i: &str) -> IResult<&str, (Vec, Vec, Vec)> { +fn parse_time_spec(i: &str) -> IResult<&str, TimeSpec> { let (i, (hour, minute, opt_second)) = tuple(( parse_date_time_comp_list(0, 24), @@ -185,13 +198,13 @@ fn parse_time_spec(i: &str) -> IResult<&str, (Vec, Vec IResult<&str, (Vec, Vec, Vec)> { +fn parse_date_spec(i: &str) -> IResult<&str, DateSpec> { // TODO: implement ~ for days (man systemd.time) if let Ok((i, (year, month, day))) = tuple(( @@ -199,12 +212,12 @@ fn parse_date_spec(i: &str) -> IResult<&str, (Vec, Vec IResult<&str, CalendarEvent> for range in range_list { event.days.insert(range); } } - if let (n, Some((year, month, day))) = opt(parse_date_spec)(i)? { - event.year = year; - event.month = month; - event.day = day; + if let (n, Some(date)) = opt(parse_date_spec)(i)? { + event.year = date.year; + event.month = date.month; + event.day = date.day; has_datespec = true; i = space0(n)?.0; } - if let (n, Some((hour, minute, second))) = opt(parse_time_spec)(i)? { - event.hour = hour; - event.minute = minute; - event.second = second; + if let (n, Some(time)) = opt(parse_time_spec)(i)? { + event.hour = time.hour; + event.minute = time.minute; + event.second = time.second; has_timespec = true; i = n; } else {