Made sure unix value is calculated

main
Jef Roosens 2022-04-12 11:10:49 +02:00
parent 2942793f40
commit 65d6aae701
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 13 additions and 35 deletions

View File

@ -3,6 +3,7 @@ module cron
import git import git
import datatypes import datatypes
import time import time
import rand
struct ScheduledBuild { struct ScheduledBuild {
repo git.GitRepo repo git.GitRepo
@ -14,42 +15,19 @@ fn (r1 ScheduledBuild) < (r2 ScheduledBuild) bool {
} }
pub fn cron(conf Config) ? { pub fn cron(conf Config) ? {
// mut queue := datatypes.MinHeap<ScheduledBuild>{} mut queue := datatypes.MinHeap<time.Time>{}
// repos_map := git.get_repos(conf.address, conf.api_key) ?
// for _, repo in repos_map { for _ in 0..5000 {
// scheduled := ScheduledBuild{ minute := rand.int_in_range(0, 60) ?
// repo: repo hour := rand.int_in_range(0, 23) ?
// timestamp: 25 ce := parse_expression('$minute $hour') ?
// }
// queue.insert(scheduled) t := ce.next_from_now() ?
// } // println(t)
queue.insert(t)
// println(queue)
// exp := '10/2 5 *'
// println(parse_expression(exp) ?)
ce := parse_expression('0 35 */2') ?
println(ce)
// ce := CronExpression{
// minutes: [0]
// hours: [3]
// days: [1, 2, 3, 4, 5, 6]
// months: [1, 2]
// }
mut t := time.Time{
year: 2022
month: 12
minute: 9
hour: 13
day: 12
} }
// mut t := time.now() for queue.len() > 0 {
println(t) println(queue.pop() ?)
for _ in 1 .. 25 {
t = ce.next(t) ?
println(t)
} }
} }

View File

@ -101,13 +101,13 @@ pub fn (ce &CronExpression) next(ref time.Time) ?time.Time {
year++ year++
} }
return time.Time{ return time.new_time(time.Time{
year: year year: year
month: month month: month
day: day day: day
minute: minute minute: minute
hour: hour hour: hour
} })
} }
fn (ce &CronExpression) next_from_now() ?time.Time { fn (ce &CronExpression) next_from_now() ?time.Time {