Skip to content

Commit

Permalink
Cron timer api (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeusmz authored Dec 29, 2024
1 parent c00a5c3 commit 686ce86
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions minevnlib-master/src/main/java/net/minevn/libs/CronTimer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.minevn.libs

import java.time.ZonedDateTime

@Suppress("unused", "MemberVisibilityCanBePrivate")
class CronTimer(val expression: String) {
var nextSchedule = parseNextSchedule(); private set

fun parseNextSchedule(time: ZonedDateTime) = getNextSchedule(expression, time)

fun parseNextSchedule() = parseNextSchedule(ZonedDateTime.now())

fun update() {
nextSchedule = parseNextSchedule()
}

fun isTime(): Boolean {
if (ZonedDateTime.now() >= nextSchedule) {
update()
return true
}
return false
}
}

0 comments on commit 686ce86

Please sign in to comment.