public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 06/14] proxmox-time: move parse_daily_duration to daily_duration.rs
Date: Tue, 30 Nov 2021 13:12:00 +0100	[thread overview]
Message-ID: <20211130121209.216846-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211130121209.216846-1-d.csapak@proxmox.com>

Signed-off-by: Dominik Csapak <d.csapak@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





  parent reply	other threads:[~2021-11-30 12:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 12:11 [pbs-devel] [PATCH proxmox/proxmox-backup 00/14] improve & cleanup proxmox-time Dominik Csapak
2021-11-30 12:11 ` [pbs-devel] [PATCH proxmox 01/14] proxmox-time: calendar-events: implement repeated ranges Dominik Csapak
2021-11-30 12:11 ` [pbs-devel] [PATCH proxmox 02/14] proxmox-time: calendar-events: make hour optional Dominik Csapak
2021-11-30 12:11 ` [pbs-devel] [PATCH proxmox 03/14] proxmox-time: move common parse functions to parse_helpers Dominik Csapak
2021-11-30 12:11 ` [pbs-devel] [PATCH proxmox 04/14] proxmox-time: move WeekDays into own file Dominik Csapak
2021-11-30 12:11 ` [pbs-devel] [PATCH proxmox 05/14] proxmox-time: split DateTimeValue " Dominik Csapak
2021-11-30 12:12 ` Dominik Csapak [this message]
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 07/14] proxmox-time: daily_duration.rs: rustfmt Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 08/14] proxmox-time: move CalendarEvent into calendar_events.rs Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 09/14] proxmox-time: move TimeSpan into time_span.rs Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 10/14] proxmox-time: move tests from time.rs to test.rs Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 11/14] proxmox-time: lib.rs: rustfmt Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 12/14] proxmox-time: calendar-events: make compute_next_event a method Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 13/14] proxmox-time: calendar_events: implement FromStr Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox 14/14] proxmox-time: time-span: " Dominik Csapak
2021-11-30 12:12 ` [pbs-devel] [PATCH proxmox-backup 1/1] remove use of deprecated functions from proxmox-time Dominik Csapak
2021-12-01  6:26   ` [pbs-devel] applied: " Dietmar Maurer
2021-12-01  6:20 ` [pbs-devel] applied: [PATCH proxmox/proxmox-backup 00/14] improve & cleanup proxmox-time Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211130121209.216846-7-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal