[pbs-devel] [PATCH proxmox 02/14] proxmox-time: calendar-events: make hour optional
Dominik Csapak
d.csapak at proxmox.com
Tue Nov 30 13:11:56 CET 2021
to be compatible with our perl calendar events, we have to make hour optional
in that case we select every hour, so 'X' is the same as writing '*:X'
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
proxmox-time/src/parse_time.rs | 17 ++++++++---------
proxmox-time/src/time.rs | 4 ++++
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/proxmox-time/src/parse_time.rs b/proxmox-time/src/parse_time.rs
index 8159a1a..aa1c58e 100644
--- a/proxmox-time/src/parse_time.rs
+++ b/proxmox-time/src/parse_time.rs
@@ -10,7 +10,7 @@ use nom::{
error::{context, ParseError, VerboseError},
bytes::complete::{tag, take_while1},
combinator::{map_res, all_consuming, opt, recognize},
- sequence::{pair, preceded, tuple},
+ sequence::{pair, preceded, terminated, tuple},
character::complete::{alpha1, space0, digit1},
multi::separated_nonempty_list,
};
@@ -225,17 +225,16 @@ fn parse_date_time_comp_list(start: u32, max: usize) -> impl Fn(&str) -> IResult
fn parse_time_spec(i: &str) -> IResult<&str, TimeSpec> {
- let (i, (hour, minute, opt_second)) = tuple((
- parse_date_time_comp_list(0, 24),
- preceded(tag(":"), parse_date_time_comp_list(0, 60)),
+ let (i, (opt_hour, minute, opt_second)) = tuple((
+ opt(terminated(parse_date_time_comp_list(0, 24), tag(":"))),
+ parse_date_time_comp_list(0, 60),
opt(preceded(tag(":"), parse_date_time_comp_list(0, 60))),
))(i)?;
- if let Some(second) = opt_second {
- Ok((i, TimeSpec { hour, minute, second }))
- } else {
- Ok((i, TimeSpec { hour, minute, second: vec![DateTimeValue::Single(0)] }))
- }
+ let hour = opt_hour.unwrap_or_else(Vec::new);
+ let second = opt_second.unwrap_or_else(|| vec![DateTimeValue::Single(0)]);
+
+ Ok((i, TimeSpec { hour, minute, second }))
}
fn parse_date_spec(i: &str) -> IResult<&str, DateSpec> {
diff --git a/proxmox-time/src/time.rs b/proxmox-time/src/time.rs
index 2dfe425..fb18949 100644
--- a/proxmox-time/src/time.rs
+++ b/proxmox-time/src/time.rs
@@ -451,6 +451,10 @@ mod test {
const JUL_31_2020: i64 = 1596153600; // Friday, 2020-07-31 00:00:00
const DEC_31_2020: i64 = 1609372800; // Thursday, 2020-12-31 00:00:00
+ // minute only syntax
+ test_value("0", THURSDAY_00_00, THURSDAY_00_00 + HOUR)?;
+ test_value("*", THURSDAY_00_00, THURSDAY_00_00 + MIN)?;
+
test_value("*:0", THURSDAY_00_00, THURSDAY_00_00 + HOUR)?;
test_value("*:*", THURSDAY_00_00, THURSDAY_00_00 + MIN)?;
test_value("*:*:*", THURSDAY_00_00, THURSDAY_00_00 + 1)?;
--
2.30.2
More information about the pbs-devel
mailing list