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 53E4C828DE for ; Tue, 30 Nov 2021 13:12:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A6F7026A40 for ; Tue, 30 Nov 2021 13:12:18 +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 76C3326914 for ; Tue, 30 Nov 2021 13:12:12 +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 50FB344689 for ; Tue, 30 Nov 2021 13:12:12 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 30 Nov 2021 13:12:01 +0100 Message-Id: <20211130121209.216846-8-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 07/14] proxmox-time: daily_duration.rs: rustfmt 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:43 -0000 Signed-off-by: Dominik Csapak --- 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 { 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 { - 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< { - 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< 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