diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt index de7b221f..66715694 100644 --- a/libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt @@ -3,9 +3,9 @@ package eu.pretix.libpretixsync.api import eu.pretix.libpretixsync.DummySentryImplementation import eu.pretix.libpretixsync.SentryInterface import eu.pretix.libpretixsync.config.ConfigStore -import eu.pretix.libpretixsync.db.AbstractQueuedCheckIn import eu.pretix.libpretixsync.db.Answer import eu.pretix.libpretixsync.models.Question +import eu.pretix.libpretixsync.models.QueuedCheckIn import eu.pretix.libpretixsync.utils.NetUtils import eu.pretix.libpretixsync.utils.URLFragmentEncoder import okhttp3.MediaType @@ -46,7 +46,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse { var dt: String? = null if (datetime != null) { - dt = AbstractQueuedCheckIn.formatDatetime(datetime) + dt = QueuedCheckIn.formatDatetime(datetime) } return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported) } @@ -93,7 +93,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h fun redeem(lists: List, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse { var dt: String? = null if (datetime != null) { - dt = AbstractQueuedCheckIn.formatDatetime(datetime) + dt = QueuedCheckIn.formatDatetime(datetime) } return redeem(lists, secret, dt, force, nonce, answers, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported) } 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 a2dc317d..3c02b637 100644 --- a/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/check/AsyncCheckProvider.kt @@ -7,7 +7,6 @@ import eu.pretix.libpretixsync.config.ConfigStore import eu.pretix.libpretixsync.crypto.isValidSignature import eu.pretix.libpretixsync.crypto.readPubkeyFromPem import eu.pretix.libpretixsync.crypto.sig1.TicketProtos -import eu.pretix.libpretixsync.db.AbstractQueuedCheckIn import eu.pretix.libpretixsync.db.Answer import eu.pretix.libpretixsync.db.NonceGenerator import eu.pretix.libpretixsync.db.QuestionLike @@ -66,7 +65,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa val dt = now() val jdoc = JSONObject() - jdoc.put("datetime", AbstractQueuedCheckIn.formatDatetime(dt.toDate())) + jdoc.put("datetime", QueuedCheckIn.formatDatetime(dt.toDate())) if (raw_barcode.contains(Regex("[\\p{C}]"))) { jdoc.put("raw_barcode", "binary:" + Base64.encodeBase64(raw_barcode.toByteArray(Charset.defaultCharset())).toString(Charset.defaultCharset())) } else { @@ -521,7 +520,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa answers = givenAnswers.toString(), checkinListId = listId, datetime = dt.toDate(), - datetime_string = AbstractQueuedCheckIn.formatDatetime(dt.toDate()), + datetime_string = QueuedCheckIn.formatDatetime(dt.toDate()), event_slug = eventSlug, nonce = nonce ?: NonceGenerator.nextNonce(), secret = ticketid, @@ -929,7 +928,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa answers = givenAnswers.toString(), checkinListId = listId, datetime = dt.toDate(), - datetime_string = AbstractQueuedCheckIn.formatDatetime(dt.toDate()), + datetime_string = QueuedCheckIn.formatDatetime(dt.toDate()), event_slug = eventSlug, nonce = nonce ?: NonceGenerator.nextNonce(), secret = position.secret, @@ -943,7 +942,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa position = position.id, type = type.toString().lowercase(Locale.getDefault()), datetime = dt.toDate(), - json_data = "{\"local\": true, \"type\": \"${type.toString().lowercase(Locale.getDefault())}\", \"datetime\": \"${AbstractQueuedCheckIn.formatDatetime(dt.toDate())}\"}", + json_data = "{\"local\": true, \"type\": \"${type.toString().lowercase(Locale.getDefault())}\", \"datetime\": \"${QueuedCheckIn.formatDatetime(dt.toDate())}\"}", ) } } diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/QueuedCheckIn.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/QueuedCheckIn.kt index 6e23f145..b451ef68 100644 --- a/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/QueuedCheckIn.kt +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/QueuedCheckIn.kt @@ -1,6 +1,11 @@ package eu.pretix.libpretixsync.models +import java.text.DateFormat +import java.text.SimpleDateFormat import java.time.OffsetDateTime +import java.util.Date +import java.util.Locale +import java.util.TimeZone data class QueuedCheckIn( val id: Long, @@ -12,4 +17,18 @@ data class QueuedCheckIn( val secret: String?, val sourceType: String?, val type: String?, -) +) { + companion object { + // Migrated from AbstractQueuedCheckIn + // TODO: Find a better place for this? + fun formatDatetime(date: Date): String { + val tz = TimeZone.getTimeZone("UTC") + val df: DateFormat = SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss'Z'", + Locale.ENGLISH + ) // Quoted "Z" to indicate UTC, no timezone offset + df.timeZone = tz + return df.format(date) + } + } +}