From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 07/14] proxmox-time: daily_duration.rs: rustfmt
Date: Tue, 30 Nov 2021 13:12:01 +0100 [thread overview]
Message-ID: <20211130121209.216846-8-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 | 76 ++++++++++++++++++------------
1 file changed, 46 insertions(+), 30 deletions(-)
diff --git a/proxmox-time/src/daily_duration.rs b/proxmox-time/src/daily_duration.rs
index d5e0d90..54037ba 100644
--- a/proxmox-time/src/daily_duration.rs
+++ b/proxmox-time/src/daily_duration.rs
@@ -23,7 +23,7 @@ impl PartialOrd for HmTime {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let mut order = self.hour.cmp(&other.hour);
if order == Ordering::Equal {
- order = self.minute.cmp(&other.minute);
+ order = self.minute.cmp(&other.minute);
}
Some(order)
}
@@ -39,10 +39,8 @@ pub struct DailyDuration {
}
impl DailyDuration {
-
/// Test it time is within this frame
pub fn time_match(&self, epoch: i64, utc: bool) -> Result<bool, Error> {
-
let t = TmEditor::with_epoch(epoch, utc)?;
Ok(self.time_match_with_tm_editor(&t))
@@ -55,18 +53,17 @@ impl DailyDuration {
pub fn time_match_with_tm_editor(&self, t: &TmEditor) -> bool {
let all_days = self.days.is_empty() || self.days.is_all();
- if !all_days { // match day first
+ if !all_days {
+ // match day first
match u32::try_from(t.day_num()) {
- Ok(day_num) => {
- match WeekDays::from_bits(1<<day_num) {
- Some(day) => {
- if !self.days.contains(day) {
- return false;
- }
+ Ok(day_num) => match WeekDays::from_bits(1 << day_num) {
+ Some(day) => {
+ if !self.days.contains(day) {
+ return false;
}
- None => return false,
}
- }
+ None => return false,
+ },
Err(_) => return false,
}
}
@@ -136,43 +133,62 @@ mod test {
fn test_parse(
duration_str: &str,
- start_h: u32, start_m: u32,
- end_h: u32, end_m: u32,
+ start_h: u32,
+ start_m: u32,
+ end_h: u32,
+ end_m: u32,
days: &[usize],
) -> Result<(), Error> {
let mut day_bits = 0;
- for day in days { day_bits |= 1<<day; }
+ for day in days {
+ day_bits |= 1 << day;
+ }
let expected_days = WeekDays::from_bits(day_bits).unwrap();
let duration = parse_daily_duration(duration_str)?;
if duration.start.hour != start_h {
- bail!("start hour missmatch, extected {}, got {:?}", start_h, duration);
+ bail!(
+ "start hour missmatch, extected {}, got {:?}",
+ start_h,
+ duration
+ );
}
if duration.start.minute != start_m {
- bail!("start minute missmatch, extected {}, got {:?}", start_m, duration);
+ bail!(
+ "start minute missmatch, extected {}, got {:?}",
+ start_m,
+ duration
+ );
}
if duration.end.hour != end_h {
bail!("end hour missmatch, extected {}, got {:?}", end_h, duration);
}
if duration.end.minute != end_m {
- bail!("end minute missmatch, extected {}, got {:?}", end_m, duration);
+ bail!(
+ "end minute missmatch, extected {}, got {:?}",
+ end_m,
+ duration
+ );
}
if duration.days != expected_days {
- bail!("weekday missmatch, extected {:?}, got {:?}", expected_days, duration);
+ bail!(
+ "weekday missmatch, extected {:?}, got {:?}",
+ expected_days,
+ duration
+ );
}
Ok(())
}
const fn make_test_time(mday: i32, hour: i32, min: i32) -> i64 {
- (mday*3600*24 + hour*3600 + min*60) as i64
+ (mday * 3600 * 24 + hour * 3600 + min * 60) as i64
}
#[test]
fn test_daily_duration_parser() -> Result<(), Error> {
-
assert!(parse_daily_duration("").is_err());
assert!(parse_daily_duration(" 8-12").is_err());
assert!(parse_daily_duration("8:60-12").is_err());
@@ -186,8 +202,8 @@ mod test {
test_parse("8:05 - 12:20", 8, 5, 12, 20, &[])?;
test_parse("mon 8-12", 8, 0, 12, 0, &[0])?;
- test_parse("tue..fri 8-12", 8, 0, 12, 0, &[1,2,3,4])?;
- test_parse("sat,tue..thu,fri 8-12", 8, 0, 12, 0, &[1,2,3,4,5])?;
+ test_parse("tue..fri 8-12", 8, 0, 12, 0, &[1, 2, 3, 4])?;
+ test_parse("sat,tue..thu,fri 8-12", 8, 0, 12, 0, &[1, 2, 3, 4, 5])?;
Ok(())
}
@@ -196,25 +212,25 @@ mod test {
fn test_time_match() -> Result<(), Error> {
const THURSDAY_80_00: i64 = make_test_time(0, 8, 0);
const THURSDAY_12_00: i64 = make_test_time(0, 12, 0);
- const DAY: i64 = 3600*24;
+ const DAY: i64 = 3600 * 24;
let duration = parse_daily_duration("thu..fri 8:05-12")?;
assert!(!duration.time_match(THURSDAY_80_00, true)?);
assert!(!duration.time_match(THURSDAY_80_00 + DAY, true)?);
- assert!(!duration.time_match(THURSDAY_80_00 + 2*DAY, true)?);
+ assert!(!duration.time_match(THURSDAY_80_00 + 2 * DAY, true)?);
- assert!(duration.time_match(THURSDAY_80_00 + 5*60, true)?);
- assert!(duration.time_match(THURSDAY_80_00 + 5*60 + DAY, true)?);
- assert!(!duration.time_match(THURSDAY_80_00 + 5*60 + 2*DAY, true)?);
+ assert!(duration.time_match(THURSDAY_80_00 + 5 * 60, true)?);
+ assert!(duration.time_match(THURSDAY_80_00 + 5 * 60 + DAY, true)?);
+ assert!(!duration.time_match(THURSDAY_80_00 + 5 * 60 + 2 * DAY, true)?);
assert!(duration.time_match(THURSDAY_12_00 - 1, true)?);
assert!(duration.time_match(THURSDAY_12_00 - 1 + DAY, true)?);
- assert!(!duration.time_match(THURSDAY_12_00 - 1 + 2*DAY, true)?);
+ assert!(!duration.time_match(THURSDAY_12_00 - 1 + 2 * DAY, true)?);
assert!(!duration.time_match(THURSDAY_12_00, true)?);
assert!(!duration.time_match(THURSDAY_12_00 + DAY, true)?);
- assert!(!duration.time_match(THURSDAY_12_00 + 2*DAY, true)?);
+ assert!(!duration.time_match(THURSDAY_12_00 + 2 * DAY, true)?);
Ok(())
}
--
2.30.2
next prev 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 ` [pbs-devel] [PATCH proxmox 06/14] proxmox-time: move parse_daily_duration to daily_duration.rs Dominik Csapak
2021-11-30 12:12 ` Dominik Csapak [this message]
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-8-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