CalendarEvent: speedup/simplify repetition tests
This commit is contained in:
parent
e05b637c73
commit
fed270bf3f
@ -32,18 +32,16 @@ impl DateTimeValue {
|
|||||||
DateTimeValue::Single(v) => *v == value,
|
DateTimeValue::Single(v) => *v == value,
|
||||||
DateTimeValue::Range(start, end) => value >= *start && value <= *end,
|
DateTimeValue::Range(start, end) => value >= *start && value <= *end,
|
||||||
DateTimeValue::Repeated(start, repetition) => {
|
DateTimeValue::Repeated(start, repetition) => {
|
||||||
|
if value >= *start {
|
||||||
if *repetition > 0 {
|
if *repetition > 0 {
|
||||||
let mut found = false;
|
let offset = value - start;
|
||||||
let mut v = *start;
|
offset % repetition == 0
|
||||||
loop {
|
|
||||||
if v == value { found = true; break; }
|
|
||||||
v += *repetition;
|
|
||||||
if v > value { break; }
|
|
||||||
}
|
|
||||||
found
|
|
||||||
} else {
|
} else {
|
||||||
*start == value
|
*start == value
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,12 +75,7 @@ impl DateTimeValue {
|
|||||||
if value < *start {
|
if value < *start {
|
||||||
set_next(*start);
|
set_next(*start);
|
||||||
} else if *repetition > 0 {
|
} else if *repetition > 0 {
|
||||||
let mut v = *start;
|
set_next(((value - start + repetition) / repetition) * repetition);
|
||||||
loop {
|
|
||||||
if v > value { set_next(v); break; }
|
|
||||||
v += *repetition;
|
|
||||||
if v > value { break; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user