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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F3A4B6AF9B for ; Mon, 25 Jan 2021 14:43:57 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EAA1DAD17 for ; Mon, 25 Jan 2021 14:43:27 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 61F62AD0D for ; Mon, 25 Jan 2021 14:43:27 +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 301D145717 for ; Mon, 25 Jan 2021 14:43:27 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Mon, 25 Jan 2021 14:42:51 +0100 Message-Id: <20210125134302.3394328-7-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210125134302.3394328-1-f.gruenbichler@proxmox.com> References: <20210125134302.3394328-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 06/15] systemd/time: extract Time/DateSpec structs 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: Mon, 25 Jan 2021 13:43:58 -0000 could be pulled up into CalendarEvent if desired.. Signed-off-by: Fabian Grünbichler --- src/tools/systemd/parse_time.rs | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) 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 { -- 2.20.1