From 113b81762788c48b10428d43677d396d8459f409 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 8 Sep 2024 20:31:12 +0200 Subject: [PATCH] Extracted Instant.nowExt() --- .../kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt | 4 ++-- .../codinux/banking/fints/extensions/InstantExtensions.kt | 8 ++++++++ .../banking/fints/extensions/LocalDateTimeExtensions.kt | 2 +- .../codinux/banking/fints/extensions/RandomExtensions.kt | 4 ++-- .../net/codinux/banking/fints/model/MessageLogEntry.kt | 4 ++-- .../net/codinux/banking/fints/model/TanChallenge.kt | 4 ++-- 6 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/InstantExtensions.kt diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt index 02fa5a97..23519f9a 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt @@ -1,7 +1,7 @@ package net.codinux.banking.fints import kotlinx.coroutines.delay -import kotlinx.datetime.Clock +import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate import net.codinux.log.logger import net.codinux.banking.fints.messages.MessageBuilder @@ -231,7 +231,7 @@ open class FinTsJobExecutor( } } - val startTime = Clock.System.now() + val startTime = Instant.now() val response = getAndHandleResponseForMessage(context, message) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/InstantExtensions.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/InstantExtensions.kt new file mode 100644 index 00000000..a9b7d258 --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/InstantExtensions.kt @@ -0,0 +1,8 @@ +package net.codinux.banking.fints.extensions + +import kotlinx.datetime.Clock +import kotlinx.datetime.Instant + + +// should actually be named `now()`, but that name is already shadowed by deprecated Instant.Companion.now() method +fun Instant.Companion.nowExt(): Instant = Clock.System.now() \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/LocalDateTimeExtensions.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/LocalDateTimeExtensions.kt index 742be4b1..c4e9962f 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/LocalDateTimeExtensions.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/LocalDateTimeExtensions.kt @@ -13,5 +13,5 @@ fun LocalDateTime.Companion.nowAtEuropeBerlin(): LocalDateTime { } fun LocalDateTime.Companion.nowAt(timeZone: TimeZone): LocalDateTime { - return Clock.System.now().toLocalDateTime(timeZone) + return Instant.nowExt().toLocalDateTime(timeZone) } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/RandomExtensions.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/RandomExtensions.kt index 63b1c610..525b1c1e 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/RandomExtensions.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/extensions/RandomExtensions.kt @@ -1,11 +1,11 @@ package net.codinux.banking.fints.extensions -import kotlinx.datetime.Clock +import kotlinx.datetime.Instant import kotlin.random.Random fun randomWithSeed(): Random = Random(randomSeed()) fun randomSeed(): Long { - return Clock.System.now().nanosecondsOfSecond.toLong() + Clock.System.now().toEpochMilliseconds() + return Instant.nowExt().nanosecondsOfSecond.toLong() + Instant.nowExt().toEpochMilliseconds() } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt index 28531144..efb3191e 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/MessageLogEntry.kt @@ -1,7 +1,7 @@ package net.codinux.banking.fints.model -import kotlinx.datetime.Clock import kotlinx.datetime.Instant +import net.codinux.banking.fints.extensions.nowExt import net.codinux.banking.fints.log.MessageContext import net.codinux.banking.fints.response.segments.ReceivedSegment @@ -18,7 +18,7 @@ open class MessageLogEntry( * Is only set if [type] is set to [MessageLogEntryType.Received] and response parsing was successful. */ open val parsedSegments: List = emptyList(), - open val time: Instant = Clock.System.now() + open val time: Instant = Instant.nowExt() ) { val messageIncludingMessageTrace: String diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt index f617df45..9e1a37a4 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/TanChallenge.kt @@ -1,7 +1,7 @@ package net.codinux.banking.fints.model -import kotlinx.datetime.Clock import kotlinx.datetime.Instant +import net.codinux.banking.fints.extensions.nowExt import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMedium import net.codinux.banking.fints.response.BankResponse import net.codinux.banking.fints.response.client.FinTsClientResponse @@ -15,7 +15,7 @@ open class TanChallenge( val tanMediaIdentifier: String?, val bank: BankData, val account: AccountData? = null, - val timestamp: Instant = Clock.System.now() + val timestamp: Instant = Instant.nowExt() ) { var enterTanResult: EnterTanResult? = null