Using my time for UTC

This commit is contained in:
Brage Skjønborg 2026-01-22 18:32:18 +01:00
parent 746dc2dc67
commit 23f6afb483
4 changed files with 18 additions and 4 deletions

View File

@ -0,0 +1,12 @@
package no.iktdev.eventi
import java.time.Clock
import java.time.LocalDateTime
object MyTime {
private val clock: Clock = Clock.systemUTC()
@JvmStatic
fun UtcNow(): LocalDateTime =
LocalDateTime.now(clock)
}

View File

@ -21,7 +21,7 @@ import java.time.format.DateTimeFormatter
object ZDS { object ZDS {
val gson = WGson.gson val gson = WGson.gson
fun Event.toPersisted(id: Long, persistedAt: LocalDateTime = LocalDateTime.now()): PersistedEvent? { fun Event.toPersisted(id: Long, persistedAt: LocalDateTime = MyTime.UtcNow()): PersistedEvent? {
val payloadJson = gson.toJson(this) val payloadJson = gson.toJson(this)
val eventName = this::class.simpleName ?: run { val eventName = this::class.simpleName ?: run {
throw IllegalStateException("Missing class name for event: $this") throw IllegalStateException("Missing class name for event: $this")
@ -47,7 +47,7 @@ object ZDS {
return gson.fromJson(data, clazz) return gson.fromJson(data, clazz)
} }
fun Task.toPersisted(id: Long, status: TaskStatus = TaskStatus.Pending, persistedAt: LocalDateTime = LocalDateTime.now()): PersistedTask? { fun Task.toPersisted(id: Long, status: TaskStatus = TaskStatus.Pending, persistedAt: LocalDateTime = MyTime.UtcNow()): PersistedTask? {
val payloadJson = gson.toJson(this) val payloadJson = gson.toJson(this)
val taskName = this::class.simpleName ?: run { val taskName = this::class.simpleName ?: run {
throw IllegalStateException("Missing class name for task: $this") throw IllegalStateException("Missing class name for task: $this")

View File

@ -2,6 +2,7 @@ package no.iktdev.eventi.events
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import mu.KotlinLogging import mu.KotlinLogging
import no.iktdev.eventi.MyTime
import no.iktdev.eventi.ZDS.toEvent import no.iktdev.eventi.ZDS.toEvent
import no.iktdev.eventi.stores.EventStore import no.iktdev.eventi.stores.EventStore
import java.time.Duration import java.time.Duration
@ -33,7 +34,7 @@ abstract class EventPollerImplementation(
} }
suspend fun pollOnce() { suspend fun pollOnce() {
val pollStartedAt = LocalDateTime.now() val pollStartedAt = MyTime.UtcNow()
log.debug { "Polling for new events" } log.debug { "Polling for new events" }
val newPersisted = eventStore.getPersistedEventsAfter(lastSeenTime) val newPersisted = eventStore.getPersistedEventsAfter(lastSeenTime)

View File

@ -1,10 +1,11 @@
package no.iktdev.eventi.models package no.iktdev.eventi.models
import no.iktdev.eventi.MyTime
import java.time.LocalDateTime import java.time.LocalDateTime
import java.util.UUID import java.util.UUID
class Metadata { class Metadata {
val created: LocalDateTime = LocalDateTime.now() val created: LocalDateTime = MyTime.UtcNow()
var derivedFromId: Set<UUID>? = null var derivedFromId: Set<UUID>? = null
private set private set
fun derivedFromEventId(vararg id: UUID) = apply { fun derivedFromEventId(vararg id: UUID) = apply {