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 B36348286F for ; Tue, 30 Nov 2021 13:12:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 120D626A3C for ; Tue, 30 Nov 2021 13:12:17 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C5D1B2690F for ; Tue, 30 Nov 2021 13:12:11 +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 9CE6E45BBA for ; Tue, 30 Nov 2021 13:12:11 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 30 Nov 2021 13:12:00 +0100 Message-Id: <20211130121209.216846-7-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.184 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 Subject: [pbs-devel] [PATCH proxmox 06/14] proxmox-time: move parse_daily_duration to daily_duration.rs 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:48 -0000 Signed-off-by: Dominik Csapak --- proxmox-time/src/daily_duration.rs | 54 ++++++++++++++++++++++++++++-- proxmox-time/src/parse_time.rs | 43 ------------------------ 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/proxmox-time/src/daily_duration.rs b/proxmox-time/src/daily_duration.rs index 2f4b03d..d5e0d90 100644 --- a/proxmox-time/src/daily_duration.rs +++ b/proxmox-time/src/daily_duration.rs @@ -2,10 +2,15 @@ use std::cmp::{Ordering, PartialOrd}; use std::convert::{TryFrom, TryInto}; use anyhow::Error; +use nom::{ + bytes::complete::tag, + character::complete::space0, + error::context, + multi::separated_nonempty_list, +}; -use crate::{TmEditor, WeekDays}; - -pub use super::parse_time::parse_daily_duration; +use crate::parse_helpers::{parse_complete_line, parse_error, parse_hm_time, IResult}; +use crate::{parse_weekdays_range, TmEditor, WeekDays}; /// Time of Day (hour with minute) #[derive(Default, PartialEq, Clone, Debug)] @@ -79,6 +84,49 @@ impl DailyDuration { } } +/// Parse a [DailyDuration] +pub fn parse_daily_duration(i: &str) -> Result { + parse_complete_line("daily duration", i, parse_daily_duration_incomplete) +} + +fn parse_daily_duration_incomplete(mut i: &str) -> IResult<&str, DailyDuration> { + let mut duration = DailyDuration::default(); + + if i.starts_with(|c: char| char::is_ascii_alphabetic(&c)) { + let (n, range_list) = context( + "weekday range list", + separated_nonempty_list(tag(","), parse_weekdays_range), + )(i)?; + + i = space0(n)?.0; + + for range in range_list { + duration.days.insert(range); + } + } + + let (i, start) = parse_hm_time(i)?; + + let i = space0(i)?.0; + + let (i, _) = tag("-")(i)?; + + let i = space0(i)?.0; + + let end_time_start = i; + + let (i, end) = parse_hm_time(i)?; + + if start > end { + return Err(parse_error(end_time_start, "end time before start time")); + } + + duration.start = start; + duration.end = end; + + Ok((i, duration)) +} + #[cfg(test)] mod test { diff --git a/proxmox-time/src/parse_time.rs b/proxmox-time/src/parse_time.rs index 00a9241..adaf7ac 100644 --- a/proxmox-time/src/parse_time.rs +++ b/proxmox-time/src/parse_time.rs @@ -375,46 +375,3 @@ fn parse_time_span_incomplete(mut i: &str) -> IResult<&str, TimeSpan> { Ok((i, ts)) } - -/// Parse a [DailyDuration] -pub fn parse_daily_duration(i: &str) -> Result { - parse_complete_line("daily duration", i, parse_daily_duration_incomplete) -} - -fn parse_daily_duration_incomplete(mut i: &str) -> IResult<&str, DailyDuration> { - - let mut duration = DailyDuration::default(); - - if i.starts_with(|c: char| char::is_ascii_alphabetic(&c)) { - - let (n, range_list) = context( - "weekday range list", - separated_nonempty_list(tag(","), parse_weekdays_range) - )(i)?; - - i = space0(n)?.0; - - for range in range_list { duration.days.insert(range); } - } - - let (i, start) = parse_hm_time(i)?; - - let i = space0(i)?.0; - - let (i, _) = tag("-")(i)?; - - let i = space0(i)?.0; - - let end_time_start = i; - - let (i, end) = parse_hm_time(i)?; - - if start > end { - return Err(parse_error(end_time_start, "end time before start time")); - } - - duration.start = start; - duration.end = end; - - Ok((i, duration)) -} -- 2.30.2