Skip to content

Commit a4f581b

Browse files
committed
Fix now datetime override in tests
1 parent 873f478 commit a4f581b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.json.JSONException
4141
import org.json.JSONObject
4242
import java.lang.Exception
4343
import java.nio.charset.Charset
44+
import java.time.Instant
4445
import java.time.OffsetDateTime
4546
import java.util.*
4647

@@ -750,14 +751,14 @@ class AsyncCheckProvider(private val config: ConfigStore, private val dataStore:
750751

751752
if (type != TicketCheckProvider.CheckInType.EXIT) {
752753
val validFrom = position.validFrom
753-
if (validFrom != null && validFrom.isAfter(OffsetDateTime.now())) {
754+
if (validFrom != null && validFrom.isAfter(javaTimeNow())) {
754755
res.type = TicketCheckProvider.CheckResult.Type.INVALID_TIME
755756
res.isCheckinAllowed = false
756757
storeFailedCheckin(eventSlug, list.serverId, "invalid_time", position.secret!!, type, position = position.serverId, item = positionItem.serverId, variation = position.variationServerId, subevent = position.subEventServerId, nonce = nonce)
757758
return res
758759
}
759760
val validUntil = position.validUntil
760-
if (validUntil != null && validUntil.isBefore(OffsetDateTime.now())) {
761+
if (validUntil != null && validUntil.isBefore(javaTimeNow())) {
761762
res.type = TicketCheckProvider.CheckResult.Type.INVALID_TIME
762763
res.isCheckinAllowed = false
763764
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:
12391240
return overrideNow ?: DateTime()
12401241
}
12411242

1243+
private fun javaTimeNow(): OffsetDateTime {
1244+
val jodaNow = now()
1245+
val instant = Instant.ofEpochMilli(jodaNow.millis)
1246+
val zoneId = jodaNow.zone.toTimeZone().toZoneId()
1247+
return OffsetDateTime.ofInstant(instant, zoneId)
1248+
}
1249+
12421250
private val CheckIn.fullDatetime : DateTime
12431251
get() {
12441252
// To avoid Joda Time code in the models, handle the case where we don't have a datetime value from JSON here

0 commit comments

Comments
 (0)