mirror of
https://git.proxmox.com/git/proxmox
synced 2025-06-23 20:33:32 +00:00
proxmox-time: daily_duration.rs: rustfmt
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
78e1e8ce09
commit
83cf350f04
@ -39,10 +39,8 @@ pub struct DailyDuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DailyDuration {
|
impl DailyDuration {
|
||||||
|
|
||||||
/// Test it time is within this frame
|
/// Test it time is within this frame
|
||||||
pub fn time_match(&self, epoch: i64, utc: bool) -> Result<bool, Error> {
|
pub fn time_match(&self, epoch: i64, utc: bool) -> Result<bool, Error> {
|
||||||
|
|
||||||
let t = TmEditor::with_epoch(epoch, utc)?;
|
let t = TmEditor::with_epoch(epoch, utc)?;
|
||||||
|
|
||||||
Ok(self.time_match_with_tm_editor(&t))
|
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 {
|
pub fn time_match_with_tm_editor(&self, t: &TmEditor) -> bool {
|
||||||
let all_days = self.days.is_empty() || self.days.is_all();
|
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()) {
|
match u32::try_from(t.day_num()) {
|
||||||
Ok(day_num) => {
|
Ok(day_num) => match WeekDays::from_bits(1 << day_num) {
|
||||||
match WeekDays::from_bits(1<<day_num) {
|
|
||||||
Some(day) => {
|
Some(day) => {
|
||||||
if !self.days.contains(day) {
|
if !self.days.contains(day) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => return false,
|
None => return false,
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Err(_) => return false,
|
Err(_) => return false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,31 +133,51 @@ mod test {
|
|||||||
|
|
||||||
fn test_parse(
|
fn test_parse(
|
||||||
duration_str: &str,
|
duration_str: &str,
|
||||||
start_h: u32, start_m: u32,
|
start_h: u32,
|
||||||
end_h: u32, end_m: u32,
|
start_m: u32,
|
||||||
|
end_h: u32,
|
||||||
|
end_m: u32,
|
||||||
days: &[usize],
|
days: &[usize],
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut day_bits = 0;
|
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 expected_days = WeekDays::from_bits(day_bits).unwrap();
|
||||||
|
|
||||||
let duration = parse_daily_duration(duration_str)?;
|
let duration = parse_daily_duration(duration_str)?;
|
||||||
|
|
||||||
if duration.start.hour != start_h {
|
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 {
|
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 {
|
if duration.end.hour != end_h {
|
||||||
bail!("end hour missmatch, extected {}, got {:?}", end_h, duration);
|
bail!("end hour missmatch, extected {}, got {:?}", end_h, duration);
|
||||||
}
|
}
|
||||||
if duration.end.minute != end_m {
|
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 {
|
if duration.days != expected_days {
|
||||||
bail!("weekday missmatch, extected {:?}, got {:?}", expected_days, duration);
|
bail!(
|
||||||
|
"weekday missmatch, extected {:?}, got {:?}",
|
||||||
|
expected_days,
|
||||||
|
duration
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -172,7 +189,6 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_daily_duration_parser() -> Result<(), Error> {
|
fn test_daily_duration_parser() -> Result<(), Error> {
|
||||||
|
|
||||||
assert!(parse_daily_duration("").is_err());
|
assert!(parse_daily_duration("").is_err());
|
||||||
assert!(parse_daily_duration(" 8-12").is_err());
|
assert!(parse_daily_duration(" 8-12").is_err());
|
||||||
assert!(parse_daily_duration("8:60-12").is_err());
|
assert!(parse_daily_duration("8:60-12").is_err());
|
||||||
|
Loading…
Reference in New Issue
Block a user