refactor: added CronExpression.next_n function

This commit is contained in:
Jef Roosens 2022-05-26 13:34:57 +02:00
parent bd4bb9a9fb
commit 768da5b790
Signed by untrusted user: Jef Roosens
GPG key ID: B75D4F293C7052DB
2 changed files with 18 additions and 8 deletions

View file

@ -121,6 +121,20 @@ pub fn (ce &CronExpression) next_from_now() ?time.Time {
return ce.next(time.now())
}
// next_n returns the n next occurences of the expression, given a starting
// time.
pub fn (ce &CronExpression) next_n(ref time.Time, n int) ?[]time.Time {
mut times := []time.Time{cap: n}
times << ce.next(ref)?
for i in 1 .. n {
times << ce.next(times[i - 1])?
}
return times
}
// parse_range parses a given string into a range of sorted integers, if
// possible.
fn parse_range(s string, min int, max int, mut bitv []bool) ? {