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 datatypes
import time
import rand
struct ScheduledBuild {
repo git.GitRepo
@ -14,42 +15,19 @@ fn (r1 ScheduledBuild) < (r2 ScheduledBuild) bool {
}
pub fn cron(conf Config) ? {
// mut queue := datatypes.MinHeap<ScheduledBuild>{}
// repos_map := git.get_repos(conf.address, conf.api_key) ?
mut queue := datatypes.MinHeap<time.Time>{}
// for _, repo in repos_map {
// scheduled := ScheduledBuild{
// repo: repo
// timestamp: 25
// }
for _ in 0..5000 {
minute := rand.int_in_range(0, 60) ?
hour := rand.int_in_range(0, 23) ?
ce := parse_expression('$minute $hour') ?
// queue.insert(scheduled)
// }
// 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
t := ce.next_from_now() ?
// println(t)
queue.insert(t)
}
// mut t := time.now()
println(t)
for _ in 1 .. 25 {
t = ce.next(t) ?
println(t)
for queue.len() > 0 {
println(queue.pop() ?)
}
}

View File

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