From a4f581b162ff4ac5e3d63d73b286f83cbc930d8e Mon Sep 17 00:00:00 2001 From: Anton Weber Date: Fri, 18 Oct 2024 12:08:08 +0200 Subject: [PATCH] Fix now datetime override in tests --- .../pretix/libpretixsync/check/AsyncCheckProvider.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt index babeffaf..14944c31 100644 --- a/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt @@ -41,6 +41,7 @@ import org.json.JSONException import org.json.JSONObject import java.lang.Exception import java.nio.charset.Charset +import java.time.Instant import java.time.OffsetDateTime import java.util.* @@ -750,14 +751,14 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore: if (type != TicketCheckProvider.CheckInType.EXIT) { val validFrom = position.validFrom - if (validFrom != null && validFrom.isAfter(OffsetDateTime.now())) { + if (validFrom != null && validFrom.isAfter(javaTimeNow())) { res.type = TicketCheckProvider.CheckResult.Type.INVALID_TIME res.isCheckinAllowed = false storeFailedCheckin(eventSlug, list.serverId, "invalid_time", position.secret!!, type, position = position.serverId, item = positionItem.serverId, variation = position.variationServerId, subevent = position.subEventServerId, nonce = nonce) return res } val validUntil = position.validUntil - if (validUntil != null && validUntil.isBefore(OffsetDateTime.now())) { + if (validUntil != null && validUntil.isBefore(javaTimeNow())) { res.type = TicketCheckProvider.CheckResult.Type.INVALID_TIME res.isCheckinAllowed = false storeFailedCheckin(eventSlug, list.serverId, "invalid_time", position.secret!!, type, position = position.serverId, item = positionItem.serverId, variation = position.variationServerId, subevent = position.subEventServerId, nonce = nonce) @@ -1239,6 +1240,13 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore: return overrideNow ?: DateTime() } + private fun javaTimeNow(): OffsetDateTime { + val jodaNow = now() + val instant = Instant.ofEpochMilli(jodaNow.millis) + val zoneId = jodaNow.zone.toTimeZone().toZoneId() + return OffsetDateTime.ofInstant(instant, zoneId) + } + private val CheckIn.fullDatetime : DateTime get() { // To avoid Joda Time code in the models, handle the case where we don't have a datetime value from JSON here