CalendarEvent: speedup/simplify repetition tests

This commit is contained in:
Dietmar Maurer 2020-05-16 07:09:53 +02:00
parent e05b637c73
commit fed270bf3f

View File

@ -32,18 +32,16 @@ impl DateTimeValue {
DateTimeValue::Single(v) => *v == value,
DateTimeValue::Range(start, end) => value >= *start && value <= *end,
DateTimeValue::Repeated(start, repetition) => {
if value >= *start {
if *repetition > 0 {
let mut found = false;
let mut v = *start;
loop {
if v == value { found = true; break; }
v += *repetition;
if v > value { break; }
}
found
let offset = value - start;
offset % repetition == 0
} else {
*start == value
}
} else {
false
}
}
}
}
@ -77,12 +75,7 @@ impl DateTimeValue {
if value < *start {
set_next(*start);
} else if *repetition > 0 {
let mut v = *start;
loop {
if v > value { set_next(v); break; }
v += *repetition;
if v > value { break; }
}
set_next(((value - start + repetition) / repetition) * repetition);
}
}
}