[pbs-devel] [PATCH proxmox 06/14] proxmox-time: move parse_daily_duration to daily_duration.rs

Dominik Csapak d.csapak at proxmox.com
Tue Nov 30 13:12:00 CET 2021


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 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<DailyDuration, Error> {
+    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<DailyDuration, Error> {
-    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






More information about the pbs-devel mailing list