From 19c8e4ea8ed794f29f743e087de4ad97f1d67a9b Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 12 Jul 2020 12:14:56 +0200 Subject: [PATCH] Using now Date and UUID from common in fints4k. Could therefore remove klock --- build.gradle | 6 ------ .../net/dankito/utils/multiplatform/Date.kt | 8 +++++++ fints4k/build.gradle | 9 -------- .../net/dankito/banking/fints/FinTsClient.kt | 14 ++++++------- .../banking/fints/messages/MessageBuilder.kt | 4 ++-- .../datenelemente/abgeleiteteformate/Datum.kt | 11 +++++----- .../abgeleiteteformate/Uhrzeit.kt | 15 ++++++------- .../tan/TanGeneratorTanMedium.kt | 2 +- .../implementierte/sepa/SepaMessageCreator.kt | 10 ++++----- .../banking/fints/model/AccountTransaction.kt | 5 ++--- .../fints/model/GetTransactionsParameter.kt | 2 +- .../banking/fints/model/MessageLogEntry.kt | 4 ++-- .../banking/fints/response/ResponseParser.kt | 12 +++++------ .../fints/response/segments/Balance.kt | 5 ++--- .../fints/response/segments/BalanceSegment.kt | 2 +- .../fints/response/segments/TanResponse.kt | 4 ++-- .../fints/transactions/mt940/Mt940Parser.kt | 11 ++++++---- .../fints/transactions/mt940/model/Balance.kt | 5 ++--- .../transactions/mt940/model/StatementLine.kt | 2 +- .../dankito/banking/fints/util/FinTsUtils.kt | 12 +++++------ .../banking/fints/FinTsClientTestBase.kt | 10 ++++----- .../dankito/banking/fints/FinTsTestBase.kt | 6 +++--- .../fints/messages/MessageBuilderTest.kt | 7 +++---- .../fints/response/ResponseParserTest.kt | 7 ++++--- .../fints/transactions/Mt940ParserTest.kt | 11 ++++++---- .../dankito/banking/fints/util/Base64Test.kt | 4 ++-- .../banking/fints/util/FinTsUtilsTest.kt | 11 +++++----- fints4k/src/iosMain/kotlin/Extensions.kt | 16 -------------- .../src/iosMain/kotlin/FinTsClientSwift.kt | 1 + .../persistence/LuceneBankingPersistence.kt | 2 +- settings.gradle | 2 +- .../banking/extensions/AmountExtensions.kt | 8 +++---- .../banking/extensions/DateExtensions.kt | 21 ------------------- .../net/dankito/banking/HbciCallback.kt | 2 +- .../dankito/banking/hbci4jBankingClient.kt | 14 +++++++------ .../banking/hbci4jBankingClientCreator.kt | 2 +- .../dankito/banking/util/hbci4jModelMapper.kt | 7 ++++--- 37 files changed, 116 insertions(+), 158 deletions(-) rename ui/fints4kBankingClient/src/{main => commonMain}/kotlin/net/dankito/banking/extensions/AmountExtensions.kt (66%) delete mode 100644 ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/DateExtensions.kt diff --git a/build.gradle b/build.gradle index 256826c7..6054328a 100644 --- a/build.gradle +++ b/build.gradle @@ -13,12 +13,6 @@ ext { ktorVersion = "1.3.2" - klockVersion = "1.11.12" - - bigNumVersion = "0.1.5" - - uuidVersion = "0.1.0" - javaUtilsVersion = '1.0.16' diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt index 7d61e7a4..dce65c42 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -7,6 +7,14 @@ fun NSTimeInterval.toMillis(): Long { return this.toLong() * 1000 } +fun NSDate?.toDate(): Date? { + return this?.toDate() +} + +fun NSDate.toDate(): Date { + return Date(this) +} + actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class cluster diff --git a/fints4k/build.gradle b/fints4k/build.gradle index cb484374..33dd2790 100644 --- a/fints4k/build.gradle +++ b/fints4k/build.gradle @@ -62,10 +62,6 @@ kotlin { api project(":common") implementation "io.ktor:ktor-client-core:$ktorVersion" - - api "com.soywiz.korlibs.klock:klock:$klockVersion" - - implementation "com.benasher44:uuid:$uuidVersion" } } @@ -84,8 +80,6 @@ kotlin { // implementation "io.ktor:ktor-client-cio:$ktorVersion" implementation "io.ktor:ktor-client-okhttp:$ktorVersion" - api "com.soywiz.korlibs.klock:klock-jvm:$klockVersion" - implementation "org.slf4j:slf4j-api:$slf4jVersion" } } @@ -143,9 +137,6 @@ kotlin { implementation "io.ktor:ktor-client-js:$ktorVersion" implementation "io.ktor:ktor-client-encoding-js:$ktorVersion" implementation "io.ktor:ktor-client-js-kotlinMultiplatform:$ktorVersion" - - - implementation "com.soywiz.korlibs.klock:klock-js:$klockVersion" } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index 9f680ce9..c731a569 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -1,8 +1,5 @@ package net.dankito.banking.fints -import com.soywiz.klock.DateTime -import com.soywiz.klock.DateTimeSpan -import com.soywiz.klock.DateTimeTz import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import net.dankito.banking.fints.callback.FinTsClientCallback @@ -35,6 +32,7 @@ import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.banking.fints.webclient.IWebClient import net.dankito.banking.fints.webclient.KtorWebClient import net.dankito.banking.fints.webclient.WebClientResponse +import net.dankito.utils.multiplatform.Date open class FinTsClient( @@ -51,6 +49,8 @@ open class FinTsClient( val FindAccountTransactionsStartRegex = Regex("^HIKAZ:\\d:\\d:\\d\\+@\\d+@", RegexOption.MULTILINE) val FindAccountTransactionsEndRegex = Regex("^-'", RegexOption.MULTILINE) + const val NinetyDaysMillis = 90 * 24 * 60 * 60 * 1000L + private val log = LoggerFactory.getLogger(FinTsClient::class) } @@ -285,10 +285,10 @@ open class FinTsClient( protected open fun tryGetTransactionsOfLast90DaysWithoutTan(bank: BankData, customer: CustomerData, account: AccountData, hasRetrievedTransactionsWithTanJustBefore: Boolean): GetTransactionsResponse { - val now = DateTimeTz.nowLocal() - val ninetyDaysAgo = now.minus(DateTimeSpan(days = 90)) + val now = Date() + val ninetyDaysAgo = Date(now.millisSinceEpoch - NinetyDaysMillis) - val response = getTransactions(GetTransactionsParameter(account.supportsFeature(AccountFeature.RetrieveBalance), ninetyDaysAgo.local.date, abortIfTanIsRequired = true), bank, customer, account) + val response = getTransactions(GetTransactionsParameter(account.supportsFeature(AccountFeature.RetrieveBalance), ninetyDaysAgo, abortIfTanIsRequired = true), bank, customer, account) account.triedToRetrieveTransactionsOfLast90DaysWithoutTan = true @@ -669,7 +669,7 @@ open class FinTsClient( protected open fun addMessageLog(message: String, type: MessageLogEntryType, dialogContext: DialogContext) { - val timeStamp = DateTime.now() + val timeStamp = Date() val messagePrefix = "${if (type == MessageLogEntryType.Sent) "Sending" else "Received"} message:\r\n" // currently no need to translate val prettyPrintMessage = prettyPrintHbciMessage(message) val prettyPrintMessageWithPrefix = "$messagePrefix$prettyPrintMessage" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt index 7f20a27a..269b7df5 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt @@ -1,6 +1,5 @@ package net.dankito.banking.fints.messages -import com.soywiz.klock.DateTime import net.dankito.banking.fints.messages.datenelemente.implementierte.Aufsetzpunkt import net.dankito.banking.fints.messages.datenelemente.implementierte.KundensystemID import net.dankito.banking.fints.messages.datenelemente.implementierte.Synchronisierungsmodus @@ -23,6 +22,7 @@ import net.dankito.banking.fints.response.segments.JobParameters import net.dankito.banking.fints.response.segments.SepaAccountInfoParameters import net.dankito.banking.fints.response.segments.TanResponse import net.dankito.banking.fints.util.FinTsUtils +import net.dankito.utils.multiplatform.Date import kotlin.math.absoluteValue import kotlin.random.Random @@ -357,7 +357,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg } protected open fun createControlReference(): String { - return Random(DateTime.nowUnixLong()).nextInt().absoluteValue.toString() + return Random(Date().millisSinceEpoch).nextInt().absoluteValue.toString() } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Datum.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Datum.kt index c29a6842..d16a7d3a 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Datum.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Datum.kt @@ -1,10 +1,9 @@ package net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate -import com.soywiz.klock.Date -import com.soywiz.klock.DateFormat -import com.soywiz.klock.parse import net.dankito.banking.fints.messages.Existenzstatus import net.dankito.banking.fints.messages.datenelemente.basisformate.NumerischesDatenelement +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter /** @@ -17,15 +16,15 @@ open class Datum(date: Int?, existenzstatus: Existenzstatus) : NumerischesDatene companion object { const val HbciDateFormatString = "yyyyMMdd" - val HbciDateFormat = DateFormat(HbciDateFormatString) + val HbciDateFormat = DateFormatter(HbciDateFormatString) fun format(date: Date): String { - return HbciDateFormat.format(date.dateTimeDayStart.localUnadjusted) // TODO: is this correct? + return HbciDateFormat.format(date) // TODO: is this correct? } fun parse(dateString: String): Date { - return HbciDateFormat.parse(dateString).utc.date // TODO: really use UTC? + return HbciDateFormat.parse(dateString) !! } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Uhrzeit.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Uhrzeit.kt index 2dfea695..a0f0ca88 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Uhrzeit.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/abgeleiteteformate/Uhrzeit.kt @@ -1,8 +1,9 @@ package net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate -import com.soywiz.klock.* import net.dankito.banking.fints.messages.Existenzstatus import net.dankito.banking.fints.messages.datenelemente.basisformate.ZiffernDatenelement +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter /** @@ -16,20 +17,20 @@ open class Uhrzeit(time: Int?, existenzstatus: Existenzstatus) : ZiffernDatenele companion object { const val HbciTimeFormatString = "HHmmss" - val HbciTimeFormat = DateFormat(HbciTimeFormatString) + val HbciTimeFormat = DateFormatter(HbciTimeFormatString) - fun format(time: Time): String { - return HbciTimeFormat.format(DateTimeTz.Companion.fromUnixLocal(time.encoded.milliseconds)) // TODO: is this correct? + fun format(time: Date): String { + return HbciTimeFormat.format(time) // TODO: is this correct? } - fun parse(dateString: String): Time { - return HbciTimeFormat.parse(dateString).utc.time // TODO: is this correct? + fun parse(dateString: String): Date { + return HbciTimeFormat.parse(dateString) !! } } - constructor(time: Time?, existenzstatus: Existenzstatus) + constructor(time: Date?, existenzstatus: Existenzstatus) : this(time?.let { format(time).toInt() }, existenzstatus) } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/implementierte/tan/TanGeneratorTanMedium.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/implementierte/tan/TanGeneratorTanMedium.kt index e7c2f71c..0aad0163 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/implementierte/tan/TanGeneratorTanMedium.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/datenelemente/implementierte/tan/TanGeneratorTanMedium.kt @@ -1,6 +1,6 @@ package net.dankito.banking.fints.messages.datenelemente.implementierte.tan -import com.soywiz.klock.Date +import net.dankito.utils.multiplatform.Date open class TanGeneratorTanMedium( diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt index 5f65d1de..57af60d8 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt @@ -1,7 +1,7 @@ package net.dankito.banking.fints.messages.segmente.implementierte.sepa -import com.soywiz.klock.DateFormat -import com.soywiz.klock.DateTime +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter /** @@ -28,7 +28,7 @@ open class SepaMessageCreator : ISepaMessageCreator { const val NumberOfTransactionsKey = "NumberOfTransactions" - val IsoDateFormat = DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS") + val IsoDateFormat = DateFormatter("yyyy-MM-dd'T'HH:mm:ss.SSS") } @@ -85,8 +85,8 @@ open class SepaMessageCreator : ISepaMessageCreator { override fun createXmlFile(messageTemplate: PaymentInformationMessages, replacementStrings: Map): String { var xmlFile = messageTemplate.xmlTemplate - val now = DateTime.now() - val nowInIsoDate = IsoDateFormat.format(now.localUnadjusted) + val now = Date() + val nowInIsoDate = IsoDateFormat.format(now) if (replacementStrings.containsKey(MessageIdKey) == false) { xmlFile = replacePlaceholderWithValue(xmlFile, MessageIdKey, nowInIsoDate) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountTransaction.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountTransaction.kt index 4a9d8c41..d88c32be 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountTransaction.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AccountTransaction.kt @@ -1,7 +1,6 @@ package net.dankito.banking.fints.model -import com.soywiz.klock.Date -import com.soywiz.klock.DateTime +import net.dankito.utils.multiplatform.Date open class AccountTransaction( @@ -45,7 +44,7 @@ open class AccountTransaction( ) { // for object deserializers - internal constructor() : this(AccountData(), Money(Amount.Zero, ""), false, "", DateTime.EPOCH.date, null, null, null, null, DateTime.EPOCH.date, 0, null, null, null, + internal constructor() : this(AccountData(), Money(Amount.Zero, ""), false, "", Date(0), null, null, null, null, Date(0), 0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "", "", null, null, "", null) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/GetTransactionsParameter.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/GetTransactionsParameter.kt index 1bed95c9..a560bca8 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/GetTransactionsParameter.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/GetTransactionsParameter.kt @@ -1,6 +1,6 @@ package net.dankito.banking.fints.model -import com.soywiz.klock.Date +import net.dankito.utils.multiplatform.Date open class GetTransactionsParameter( diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageLogEntry.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageLogEntry.kt index 4b68c48a..d13baa51 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageLogEntry.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/MessageLogEntry.kt @@ -1,11 +1,11 @@ package net.dankito.banking.fints.model -import com.soywiz.klock.DateTime +import net.dankito.utils.multiplatform.Date open class MessageLogEntry( val message: String, - val time: DateTime, + val time: Date, val customer: CustomerData ) { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index b016d1f1..8d05482d 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -1,8 +1,5 @@ package net.dankito.banking.fints.response -import com.soywiz.klock.Date -import com.soywiz.klock.DateTime -import com.soywiz.klock.Time import net.dankito.banking.fints.messages.Separators import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Datum import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Uhrzeit @@ -20,6 +17,7 @@ import net.dankito.banking.fints.messages.segmente.id.MessageSegmentId import net.dankito.banking.fints.model.Amount import net.dankito.banking.fints.response.segments.* import net.dankito.banking.fints.util.MessageUtils +import net.dankito.utils.multiplatform.Date import net.dankito.utils.multiplatform.log.LoggerFactory @@ -837,13 +835,13 @@ open class ResponseParser( return Amount(adjustedAmountString) } - protected open fun parseNullableDateTime(dataElementGroup: String): DateTime? { + protected open fun parseNullableDateTime(dataElementGroup: String): Date? { val dataElements = getDataElements(dataElementGroup) if (dataElements.size >= 2) { parseNullableDate(dataElements[0])?.let { date -> parseNullableTime(dataElements[1])?.let { time -> - return DateTime.Companion.invoke(date, time) + return Date(date.millisSinceEpoch + time.millisSinceEpoch) // TODO: is this correct? } } } @@ -863,11 +861,11 @@ open class ResponseParser( return null } - protected open fun parseTime(timeString: String): Time { + protected open fun parseTime(timeString: String): Date { return Uhrzeit.parse(timeString) } - protected open fun parseNullableTime(timeString: String): Time? { + protected open fun parseNullableTime(timeString: String): Date? { try { return parseTime(timeString) } catch (ignored: Exception) { } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/Balance.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/Balance.kt index 47dfc9b5..e154fe42 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/Balance.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/Balance.kt @@ -1,14 +1,13 @@ package net.dankito.banking.fints.response.segments -import com.soywiz.klock.Date -import com.soywiz.klock.Time import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date open class Balance( val amount: Amount, val date: Date, - val time: Time? + val time: Date? ) { override fun toString(): String { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/BalanceSegment.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/BalanceSegment.kt index 45dffe68..a97bc766 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/BalanceSegment.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/BalanceSegment.kt @@ -1,7 +1,7 @@ package net.dankito.banking.fints.response.segments -import com.soywiz.klock.Date import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date open class BalanceSegment( diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/TanResponse.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/TanResponse.kt index 2a7d7161..ab1c0da8 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/TanResponse.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/segments/TanResponse.kt @@ -1,7 +1,7 @@ package net.dankito.banking.fints.response.segments -import com.soywiz.klock.DateTime import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanProcess +import net.dankito.utils.multiplatform.Date open class TanResponse( @@ -31,7 +31,7 @@ open class TanResponse( val challenge: String?, // M: bei TAN-Prozess=1, 3, 4. O: bei TAN-Prozess=2 val challengeHHD_UC: String?, - val validityDateTimeForChallenge: DateTime?, + val validityDateTimeForChallenge: Date?, val tanMediaIdentifier: String? = null, // M: bei TAN-Prozess=1, 3, 4 und „Anzahl unterstützter aktiver TAN-Medien“ nicht vorhanden. O: sonst segmentString: String diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt index 8e03fe16..127164e0 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/Mt940Parser.kt @@ -1,8 +1,10 @@ package net.dankito.banking.fints.transactions.mt940 -import com.soywiz.klock.* import net.dankito.banking.fints.model.Amount import net.dankito.banking.fints.transactions.mt940.model.* +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter +import net.dankito.utils.multiplatform.Month import net.dankito.utils.multiplatform.log.LoggerFactory @@ -442,7 +444,7 @@ open class Mt940Parser : IMt940Parser { } } - return DateFormat.parse(dateString).utc.date // fallback to not thread-safe SimpleDateFormat. Works in most cases but not all + return DateFormatter.parse(dateString)!! // fallback to not thread-safe SimpleDateFormat. Works in most cases but not all } /** @@ -452,8 +454,9 @@ open class Mt940Parser : IMt940Parser { val bookingDate = parseMt940Date(valueDateString.substring(0, 2) + bookingDateString) // there are rare cases that booking date is e.g. on 31.12.2019 and value date on 01.01.2020 -> booking date would be on 31.12.2020 (and therefore in the future) - if (bookingDate.month != valueDate.month && bookingDate.month == Month.December) { - return parseMt940Date("" + (valueDate.year - 1 - 2000) + bookingDateString) + val bookingDateMonth = bookingDate.month() + if (bookingDateMonth != valueDate.month() && bookingDateMonth == Month.December) { + return parseMt940Date("" + (valueDate.year() - 1 - 2000) + bookingDateString) } return bookingDate diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/Balance.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/Balance.kt index b833cdd5..4415721b 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/Balance.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/Balance.kt @@ -1,8 +1,7 @@ package net.dankito.banking.fints.transactions.mt940.model -import com.soywiz.klock.Date -import com.soywiz.klock.DateTime import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date open class Balance( @@ -42,7 +41,7 @@ open class Balance( ) { - internal constructor() : this(false, false, DateTime.EPOCH.date, "", Amount.Zero) // for object deserializers + internal constructor() : this(false, false, Date(0), "", Amount.Zero) // for object deserializers override fun toString(): String { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/StatementLine.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/StatementLine.kt index e6b39a16..78ec592c 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/StatementLine.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/transactions/mt940/model/StatementLine.kt @@ -1,7 +1,7 @@ package net.dankito.banking.fints.transactions.mt940.model -import com.soywiz.klock.Date import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date open class StatementLine( diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/FinTsUtils.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/FinTsUtils.kt index 3961f7ae..280335a7 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/FinTsUtils.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/util/FinTsUtils.kt @@ -1,17 +1,15 @@ package net.dankito.banking.fints.util -import com.soywiz.klock.Date -import com.soywiz.klock.DateTime -import com.soywiz.klock.Time import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Datum import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Uhrzeit +import net.dankito.utils.multiplatform.Date open class FinTsUtils { open fun formatDateToday(): String { - return formatDate(DateTime.now().date) + return formatDate(Date()) } open fun formatDate(date: Date): String { @@ -28,10 +26,10 @@ open class FinTsUtils { open fun formatTimeNow(): String { - return formatTime(DateTime.now().time) + return formatTime(Date()) } - open fun formatTime(time: Time): String { + open fun formatTime(time: Date): String { return Uhrzeit.format(time) } @@ -39,7 +37,7 @@ open class FinTsUtils { return convertToInt(formatTimeNow()) } - open fun formatTimeAsInt(time: Time): Int { + open fun formatTimeAsInt(time: Date): Int { return convertToInt(formatTime(time)) } diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt index 85d380f1..b23d031c 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt @@ -2,9 +2,6 @@ package net.dankito.banking.fints import ch.tutteli.atrium.api.fluent.en_GB.* import ch.tutteli.atrium.api.verbs.expect -import com.benasher44.uuid.uuid4 -import com.soywiz.klock.DateFormat -import com.soywiz.klock.DateTimeTz import net.dankito.banking.bankfinder.InMemoryBankFinder import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.extensions.isTrue @@ -26,6 +23,9 @@ import net.dankito.banking.fints.util.IBase64Service import net.dankito.banking.fints.util.IThreadPool import net.dankito.banking.fints.util.PureKotlinBase64Service import net.dankito.banking.fints.webclient.KtorWebClient +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter +import net.dankito.utils.multiplatform.UUID import kotlin.test.DefaultAsserter.fail import kotlin.test.Ignore import kotlin.test.Test @@ -35,7 +35,7 @@ import kotlin.test.Test open class FinTsClientTestBase { companion object { - val DateTimeFormatForUniqueBankTransferUsage = DateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS") + val DateTimeFormatForUniqueBankTransferUsage = DateFormatter("yyyy-MM-dd'T'HH:mm:ss.SSS") } @@ -222,7 +222,7 @@ open class FinTsClientTestBase { // transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2 val BankTransferData = BankTransferData(Customer.name, account?.iban!!, Bank.bic, Money(Amount("0,01"), "EUR"), - "${DateTimeFormatForUniqueBankTransferUsage.format(DateTimeTz.nowLocal())} Test transaction ${uuid4()}") + "${DateTimeFormatForUniqueBankTransferUsage.format(Date())} Test transaction ${UUID.random()}") // when diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsTestBase.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsTestBase.kt index 297fb9cd..9e3bc62f 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsTestBase.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/FinTsTestBase.kt @@ -1,7 +1,5 @@ package net.dankito.banking.fints -import com.benasher44.uuid.uuid4 -import com.soywiz.klock.Date import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Datum import net.dankito.banking.fints.messages.datenelemente.abgeleiteteformate.Laenderkennzeichen import net.dankito.banking.fints.messages.datenelemente.implementierte.Dialogsprache @@ -10,6 +8,8 @@ import net.dankito.banking.fints.model.* import net.dankito.banking.fints.response.segments.AccountType import net.dankito.banking.fints.response.segments.ChangeTanMediaParameters import net.dankito.banking.fints.response.segments.JobParameters +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.UUID abstract class FinTsTestBase { @@ -64,7 +64,7 @@ abstract class FinTsTestBase { protected open fun createDialogId(): String { - return uuid4().toString().replace("-", "") + return UUID.random().replace("-", "") } protected open fun convertDate(date: Date): String { diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/messages/MessageBuilderTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/messages/MessageBuilderTest.kt index ea74a722..534373fe 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/messages/MessageBuilderTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/messages/MessageBuilderTest.kt @@ -3,14 +3,13 @@ package net.dankito.banking.fints.messages import ch.tutteli.atrium.api.fluent.en_GB.notToBeNull import ch.tutteli.atrium.api.fluent.en_GB.toBe import ch.tutteli.atrium.api.verbs.expect -import com.soywiz.klock.Date -import com.soywiz.klock.Month -import com.soywiz.klock.Time import net.dankito.banking.fints.FinTsTestBase import net.dankito.banking.fints.model.* import net.dankito.banking.fints.response.segments.AccountType import net.dankito.banking.fints.response.segments.JobParameters import net.dankito.banking.fints.util.FinTsUtils +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.Month import kotlin.test.AfterTest import kotlin.test.Test @@ -22,7 +21,7 @@ class MessageBuilderTest : FinTsTestBase() { return Date.toString() } - override fun formatTime(time: Time): String { + override fun formatTime(time: Date): String { return Time.toString() } }) { diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt index 857f97f0..0efd2764 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt @@ -16,6 +16,7 @@ import ch.tutteli.atrium.api.verbs.expect import net.dankito.banking.fints.extensions.isFalse import net.dankito.banking.fints.extensions.isTrue import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date import kotlin.test.Test import kotlin.test.fail @@ -965,7 +966,7 @@ class ResponseParserTest : FinTsTestBase() { // given val balance = "1234,56" - val date = com.soywiz.klock.Date(1988, 3, 27) + val date = Date(1988, 3, 27) val bankCode = "12345678" val accountId = "0987654321" val accountProductName = "Sichteinlagen" @@ -992,7 +993,7 @@ class ResponseParserTest : FinTsTestBase() { // given val balance = Amount.Zero - val date = com.soywiz.klock.Date(2020, 6, 11) + val date = Date(2020, 6, 11) val bankCode = "12345678" val accountId = "0987654321" val accountProductName = "Girokonto" @@ -1019,7 +1020,7 @@ class ResponseParserTest : FinTsTestBase() { // given val balance = Amount.Zero - val date = com.soywiz.klock.Date(2020, 6, 11) + val date = Date(2020, 6, 11) val bankCode = "12345678" val accountId = "0987654321" val accountProductName = "Girokonto" diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/transactions/Mt940ParserTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/transactions/Mt940ParserTest.kt index c9e4a88f..0f5f87ff 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/transactions/Mt940ParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/transactions/Mt940ParserTest.kt @@ -10,10 +10,10 @@ import net.dankito.banking.fints.transactions.mt940.model.InformationToAccountOw import net.dankito.banking.fints.transactions.mt940.model.StatementLine import ch.tutteli.atrium.api.verbs.expect import kotlin.test.Test -import com.soywiz.klock.Date -import com.soywiz.klock.DateFormat import net.dankito.banking.fints.extensions.isFalse import net.dankito.banking.fints.model.Amount +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.DateFormatter class Mt940ParserTest : FinTsTestBase() { @@ -39,6 +39,9 @@ class Mt940ParserTest : FinTsTestBase() { val AccountStatement1ClosingBalanceAmount = Amount("13580,23") val AccountStatement1With2TransactionsClosingBalanceAmount = Amount("13148,13") + + val Mt940DateFormatter = DateFormatter("yyMMdd") + val BookingDateFormatter = DateFormatter("MMdd") } private val underTest = Mt940Parser() @@ -348,11 +351,11 @@ class Mt940ParserTest : FinTsTestBase() { private fun convertMt940Date(date: Date): String { - return Mt940Parser.DateFormat.format(date.dateTimeDayStart.localUnadjusted) + return Mt940DateFormatter.format(date) } private fun convertToShortBookingDate(date: Date): String { - return DateFormat("MMdd").format(date.dateTimeDayStart.localUnadjusted) + return BookingDateFormatter.format(date) } } \ No newline at end of file diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/Base64Test.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/Base64Test.kt index 6cf5ae13..816229aa 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/Base64Test.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/Base64Test.kt @@ -4,7 +4,7 @@ import ch.tutteli.atrium.api.fluent.en_GB.ExperimentalWithOptions import ch.tutteli.atrium.api.fluent.en_GB.toBe import ch.tutteli.atrium.api.fluent.en_GB.withRepresentation import ch.tutteli.atrium.api.verbs.expect -import com.soywiz.klock.DateTime +import net.dankito.utils.multiplatform.Date import kotlin.random.Random import kotlin.test.Test @@ -60,7 +60,7 @@ class Base64Test { @ExperimentalWithOptions fun testRandomStrings() { val steps = 1000000 - val random = Random(DateTime.nowUnixLong()) + val random = Random(Date().millisSinceEpoch) for (count in 0 until steps) { // given diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/FinTsUtilsTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/FinTsUtilsTest.kt index 200639ac..5ae71b8f 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/FinTsUtilsTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/util/FinTsUtilsTest.kt @@ -2,8 +2,7 @@ package net.dankito.banking.fints.util import ch.tutteli.atrium.api.fluent.en_GB.toBe import ch.tutteli.atrium.api.verbs.expect -import com.soywiz.klock.Date -import com.soywiz.klock.Time +import net.dankito.utils.multiplatform.Date import kotlin.test.Test class FinTsUtilsTest { @@ -42,7 +41,7 @@ class FinTsUtilsTest { fun formatTime_AM() { // given - val time = Time(8, 2, 1) + val time = Date(8, 2, 1) // when val result = underTest.formatTime(time) @@ -55,7 +54,7 @@ class FinTsUtilsTest { fun formatTime_PM() { // given - val time = Time(18, 22, 51) + val time = Date(18, 22, 51) // when val result = underTest.formatTime(time) @@ -68,7 +67,7 @@ class FinTsUtilsTest { fun formatTimeAsInt_AM() { // given - val time = Time(8, 2, 1) + val time = Date(8, 2, 1) // when val result = underTest.formatTimeAsInt(time) @@ -81,7 +80,7 @@ class FinTsUtilsTest { fun formatTimeAsInt_PM() { // given - val time = Time(18, 22, 51) + val time = Date(18, 22, 51) // when val result = underTest.formatTimeAsInt(time) diff --git a/fints4k/src/iosMain/kotlin/Extensions.kt b/fints4k/src/iosMain/kotlin/Extensions.kt index 9dcc30de..d93c8f7b 100644 --- a/fints4k/src/iosMain/kotlin/Extensions.kt +++ b/fints4k/src/iosMain/kotlin/Extensions.kt @@ -1,4 +1,3 @@ -import com.soywiz.klock.Date import kotlinx.cinterop.addressOf import kotlinx.cinterop.convert import kotlinx.cinterop.usePinned @@ -14,19 +13,4 @@ fun ByteArray.toNSData(): NSData = NSMutableData().apply { this@toNSData.usePinned { appendBytes(it.addressOf(0), size.convert()) } -} - - -fun NSDate?.toDate(): Date? { - return this?.toDate() -} - -fun NSDate.toDate(): Date { - val calendar = NSCalendar.currentCalendar() - - return Date.invoke( - calendar.component(NSCalendarUnitYear, this).toInt(), - calendar.component(NSCalendarUnitMonth, this).toInt(), - calendar.component(NSCalendarUnitDay, this).toInt() - ) } \ No newline at end of file diff --git a/fints4k/src/iosMain/kotlin/FinTsClientSwift.kt b/fints4k/src/iosMain/kotlin/FinTsClientSwift.kt index f456b2b0..3b3d1889 100644 --- a/fints4k/src/iosMain/kotlin/FinTsClientSwift.kt +++ b/fints4k/src/iosMain/kotlin/FinTsClientSwift.kt @@ -8,6 +8,7 @@ import net.dankito.banking.fints.response.client.AddAccountResponse import net.dankito.banking.fints.response.client.FinTsClientResponse import net.dankito.banking.fints.response.client.GetTransactionsResponse import net.dankito.banking.fints.webclient.IWebClient +import net.dankito.utils.multiplatform.toDate import kotlin.native.concurrent.TransferMode import kotlin.native.concurrent.Worker import kotlin.native.concurrent.freeze diff --git a/persistence/LuceneBankingPersistence/src/main/kotlin/net/dankito/banking/persistence/LuceneBankingPersistence.kt b/persistence/LuceneBankingPersistence/src/main/kotlin/net/dankito/banking/persistence/LuceneBankingPersistence.kt index d03d67d8..2a873d71 100644 --- a/persistence/LuceneBankingPersistence/src/main/kotlin/net/dankito/banking/persistence/LuceneBankingPersistence.kt +++ b/persistence/LuceneBankingPersistence/src/main/kotlin/net/dankito/banking/persistence/LuceneBankingPersistence.kt @@ -1,5 +1,6 @@ package net.dankito.banking.persistence +import net.dankito.utils.multiplatform.File import net.dankito.banking.LuceneConfig import net.dankito.banking.LuceneConfig.Companion.AmountFieldName import net.dankito.banking.LuceneConfig.Companion.BalanceFieldName @@ -22,7 +23,6 @@ import net.dankito.utils.lucene.index.DocumentsWriter import net.dankito.utils.lucene.index.FieldBuilder import org.apache.lucene.index.IndexableField import org.slf4j.LoggerFactory -import java.io.File open class LuceneBankingPersistence( diff --git a/settings.gradle b/settings.gradle index 8f4e4707..54d0864e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ rootProject.name = 'fints4kProject' -enableFeaturePreview('GRADLE_METADATA') // for klock +enableFeaturePreview('GRADLE_METADATA') include ':fints4k' diff --git a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/AmountExtensions.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/extensions/AmountExtensions.kt similarity index 66% rename from ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/AmountExtensions.kt rename to ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/extensions/AmountExtensions.kt index 61c2a180..94ddab8c 100644 --- a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/AmountExtensions.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/extensions/AmountExtensions.kt @@ -2,7 +2,7 @@ package net.dankito.banking.extensions import net.dankito.banking.fints.model.Amount import net.dankito.banking.fints.model.Money -import java.math.BigDecimal +import net.dankito.utils.multiplatform.BigDecimal fun BigDecimal.toAmount(): Amount { @@ -13,10 +13,10 @@ fun BigDecimal.toMoney(): Money { return Money(this.toAmount(), "EUR") } -fun Amount.toJavaBigDecimal(): BigDecimal { +fun Amount.toBigDecimal(): BigDecimal { return BigDecimal(this.string.replace(',', '.')) } -fun Money.toJavaBigDecimal(): BigDecimal { - return this.amount.toJavaBigDecimal() +fun Money.toBigDecimal(): BigDecimal { + return this.amount.toBigDecimal() } \ No newline at end of file diff --git a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/DateExtensions.kt b/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/DateExtensions.kt deleted file mode 100644 index 1f0ff829..00000000 --- a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/extensions/DateExtensions.kt +++ /dev/null @@ -1,21 +0,0 @@ -package net.dankito.banking.extensions - -import com.soywiz.klock.jvm.toDate -import com.soywiz.klock.jvm.toDateTime -import java.text.SimpleDateFormat -import java.util.* - - -fun Date.toKlockDate(): com.soywiz.klock.Date { - return this.toDateTime().date -} - -fun com.soywiz.klock.Date.toJavaUtilDate(): Date { - try { - // there's a bug that some banks like Sparkasse return as date '190229' (= 29.02.2019), which simply doesn't exist - return this.dateTimeDayStart.toDate() - } catch (e: Exception) { // -> catch it and parse it manually, java.util.Date knows how to handle this - return SimpleDateFormat("yyyy-MM-dd").parse(String.format("%04d-%02d-%02d", this.year, this.month1, this.day)) - } - -} \ No newline at end of file diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/HbciCallback.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/HbciCallback.kt index 88d07697..60e7bde3 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/HbciCallback.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/HbciCallback.kt @@ -8,6 +8,7 @@ import net.dankito.banking.ui.model.tan.ImageTanChallenge import net.dankito.banking.ui.model.tan.TanChallenge import net.dankito.banking.ui.model.tan.TanImage import net.dankito.banking.util.hbci4jModelMapper +import net.dankito.utils.multiplatform.Date import org.kapott.hbci.callback.AbstractHBCICallback import org.kapott.hbci.callback.HBCICallback import org.kapott.hbci.manager.HBCIUtils @@ -15,7 +16,6 @@ import org.kapott.hbci.manager.MatrixCode import org.kapott.hbci.manager.QRCode import org.kapott.hbci.passport.HBCIPassport import org.slf4j.LoggerFactory -import java.util.* /** diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt index b7780315..daa9fe6c 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt @@ -15,6 +15,10 @@ import net.dankito.banking.util.hbci4jModelMapper import net.dankito.banking.bankfinder.BankInfo import net.dankito.banking.util.* import net.dankito.utils.ThreadPool +import net.dankito.utils.multiplatform.BigDecimal +import net.dankito.utils.multiplatform.Date +import net.dankito.utils.multiplatform.File +import net.dankito.utils.multiplatform.toBigDecimal import org.kapott.hbci.GV.HBCIJob import org.kapott.hbci.GV_Result.GVRKUms import org.kapott.hbci.GV_Result.GVRSaldoReq @@ -26,8 +30,6 @@ import org.kapott.hbci.passport.HBCIPassport import org.kapott.hbci.status.HBCIExecStatus import org.kapott.hbci.structures.Value import org.slf4j.LoggerFactory -import java.io.File -import java.math.BigDecimal import java.text.SimpleDateFormat import java.util.* @@ -105,7 +107,7 @@ open class hbci4jBankingClient( bookedTransactions.put(bankAccount, response.bookedTransactions) unbookedTransactions.put(bankAccount, response.unbookedTransactions) - balances.put(bankAccount, response.balance ?: BigDecimal.ZERO) // TODO: really add BigDecimal.Zero if balance couldn't be retrieved? + balances.put(bankAccount, response.balance?.toBigDecimal() ?: BigDecimal.Zero) // TODO: really add BigDecimal.Zero if balance couldn't be retrieved? } } @@ -162,7 +164,7 @@ open class hbci4jBankingClient( } // Auswertung des Saldo-Abrufs. - var balance = BigDecimal.ZERO + var balance = BigDecimal.Zero if (parameter.alsoRetrieveBalance && nullableBalanceJob != null) { val balanceResult = nullableBalanceJob.jobResult as GVRSaldoReq if(balanceResult.isOK == false) { @@ -170,7 +172,7 @@ open class hbci4jBankingClient( return GetTransactionsResponse(bankAccount, false, null, error = Exception("Could not fetch balance of bank account $bankAccount: $balanceResult")) } - balance = balanceResult.entries[0].ready.value.bigDecimalValue + balance = balanceResult.entries[0].ready.value.bigDecimalValue.toBigDecimal() } @@ -185,7 +187,7 @@ open class hbci4jBankingClient( } return GetTransactionsResponse(bankAccount, true, null, accountTransactionMapper.mapAccountTransactions(bankAccount, result), - listOf(), balance) + listOf(), balance?.toBigDecimal()) } catch(e: Exception) { log.error("Could not get accounting details for bank ${credentials.bankCode}", e) diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClientCreator.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClientCreator.kt index 79c95d59..5fe69061 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClientCreator.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClientCreator.kt @@ -5,7 +5,7 @@ import net.dankito.banking.ui.IBankingClient import net.dankito.banking.ui.IBankingClientCreator import net.dankito.banking.bankfinder.BankInfo import net.dankito.banking.util.IAsyncRunner -import java.io.File +import net.dankito.utils.multiplatform.File open class hbci4jBankingClientCreator : IBankingClientCreator { diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/util/hbci4jModelMapper.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/util/hbci4jModelMapper.kt index 323ad9dc..bc5557cc 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/util/hbci4jModelMapper.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/util/hbci4jModelMapper.kt @@ -1,5 +1,7 @@ package net.dankito.banking.util +import net.dankito.utils.multiplatform.BigDecimal +import net.dankito.utils.multiplatform.toBigDecimal import net.dankito.banking.ui.model.Customer import net.dankito.banking.ui.model.BankAccount import net.dankito.banking.ui.model.BankAccountType @@ -8,7 +10,6 @@ import net.dankito.banking.ui.model.tan.TanProcedureType import org.kapott.hbci.passport.HBCIPassport import org.kapott.hbci.structures.Konto import org.kapott.hbci.structures.Value -import java.math.BigDecimal open class hbci4jModelMapper { @@ -46,7 +47,7 @@ open class hbci4jModelMapper { BankAccount(customer, bankAccount.number, if (bankAccount.name2.isNullOrBlank() == false) bankAccount.name + " " + bankAccount.name2 else bankAccount.name, - iban, bankAccount.subnumber, bankAccount.customerid, BigDecimal.ZERO, bankAccount.curr, mapBankAccountType(bankAccount), + iban, bankAccount.subnumber, bankAccount.customerid, BigDecimal.Zero, bankAccount.curr, mapBankAccountType(bankAccount), null, bankAccount.limit?.value?.let { mapValue(it).toString() }, null, bankAccount.allowedGVs.contains("HKKAZ"), bankAccount.allowedGVs.contains("HKSAL"), bankAccount.allowedGVs.contains("HKCCS")) } @@ -71,7 +72,7 @@ open class hbci4jModelMapper { } protected open fun mapValue(value: Value): BigDecimal { - return BigDecimal.valueOf(value.longValue).divide(BigDecimal.valueOf(100)) + return java.math.BigDecimal.valueOf(value.longValue).divide(java.math.BigDecimal.valueOf(100)).toBigDecimal() }