Skip to content

Commit

Permalink
Fix now datetime override in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antweb committed Oct 18, 2024
1 parent 873f478 commit a4f581b
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4f581b

Please sign in to comment.