diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Date.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Date.kt index 87e0df1b..864da226 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -38,6 +38,8 @@ expect class Date(millisSinceEpoch: Long) { fun day(): Int + fun addDays(days: Int): Date + fun compareTo(other: Date): Int 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 d40d01b7..935ceafb 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -86,6 +86,12 @@ actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class return components.day.toInt() } + actual fun addDays(days: Int): Date { + val calendar = NSCalendar.currentCalendar + + return calendar.dateByAddingUnit(NSCalendarUnitDay, days, this.date, 0)!! + } + actual fun compareTo(other: Date): Int { diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Date.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Date.kt index eca7f31b..aef6fd28 100644 --- a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -56,6 +56,15 @@ actual class Date actual constructor(millisSinceEpoch: Long) : java.util.Date(mi return super.getDate() } + actual fun addDays(days: Int): Date { + val calendar = Calendar.getInstance() + calendar.time = this + calendar.add(Calendar.DATE, days) + + return Date(calendar.time.time) + } + + private fun formatDate(dateFormatStyle: Int): Int { val dateStringString = DateFormat.getDateInstance(dateFormatStyle).format(this) 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 8b14b790..ad0da522 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -22,9 +22,6 @@ open class FinTsClient( companion object { val SupportedAccountTypes = listOf(AccountType.Girokonto, AccountType.Festgeldkonto, AccountType.Kreditkartenkonto) - - const val OneDayMillis = 24 * 60 * 60 * 1000L - const val NinetyDaysMillis = 90 * OneDayMillis } @@ -159,7 +156,7 @@ open class FinTsClient( */ open fun tryGetTransactionsOfLast90DaysWithoutTan(bank: BankData, account: AccountData, callback: (GetTransactionsResponse) -> Unit) { - val ninetyDaysAgo = Date(Date.today.millisSinceEpoch - NinetyDaysMillis) + val ninetyDaysAgo = Date.today.addDays(-90) getTransactionsAsync(GetTransactionsParameter(account, account.supportsRetrievingBalance, ninetyDaysAgo, abortIfTanIsRequired = true), bank) { response -> callback(response) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt index 07e65a7b..7b7ccb89 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt @@ -242,7 +242,7 @@ open class FinTsJobExecutor( val successful = response.successful && (parameter.alsoRetrieveBalance == false || balance != null) val fromDate = parameter.fromDate - ?: parameter.account.countDaysForWhichTransactionsAreKept?.let { Date(Date.today.millisSinceEpoch - it * FinTsClient.OneDayMillis) } + ?: parameter.account.countDaysForWhichTransactionsAreKept?.let { Date.today.addDays(it * -1) } ?: bookedTransactions.map { it.valueDate }.sortedBy { it.millisSinceEpoch }.firstOrNull() val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.errorMessage) diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 32b3ce1d..b07f9948 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -80,8 +80,6 @@ open class BankingPresenter( val OpticalTanMethods = listOf(TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanQrCode, TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan, TanMethodType.QrCode) - protected const val OneDayMillis = 24 * 60 * 60 * 1000L - protected val ShortDateStyleDateFormatter = DateFormatter(DateFormatStyle.Short) protected val MediumDateStyleDateFormatter = DateFormatter(DateFormatStyle.Medium) @@ -432,7 +430,7 @@ open class BankingPresenter( } open fun updateAccountTransactionsAsync(account: TypedBankAccount, abortIfTanIsRequired: Boolean = false, callback: ((GetTransactionsResponse) -> Unit)? = null) { - val fromDate = account.retrievedTransactionsUpTo?.let { Date(it.millisSinceEpoch - OneDayMillis) } // one day before last received transactions + val fromDate = account.retrievedTransactionsUpTo?.addDays(-1) // one day before last received transactions fetchAccountTransactionsAsync(account, fromDate, abortIfTanIsRequired, callback) } @@ -477,7 +475,7 @@ open class BankingPresenter( } open fun getDayOfFirstTransactionStoredOnBankServer(account: IBankAccount): Date { - return Date(Date.today.millisSinceEpoch - (account.countDaysForWhichTransactionsAreKept ?: 0) * OneDayMillis) + return Date.today.addDays((account.countDaysForWhichTransactionsAreKept ?: 0) * -1) } protected open fun getDateOfFirstRetrievedTransaction(transactions: Collection): Date? {