From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B344C8283D for ; Tue, 30 Nov 2021 13:12:12 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A5B6326917 for ; Tue, 30 Nov 2021 13:12:12 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 63C6E268E0 for ; Tue, 30 Nov 2021 13:12:10 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 28AC244F19 for ; Tue, 30 Nov 2021 13:12:10 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 30 Nov 2021 13:11:56 +0100 Message-Id: <20211130121209.216846-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211130121209.216846-1-d.csapak@proxmox.com> References: <20211130121209.216846-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.185 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [time.rs] Subject: [pbs-devel] [PATCH proxmox 02/14] proxmox-time: calendar-events: make hour optional X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2021 12:12:12 -0000 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 --- 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