Fixed substracting 90 days as previous implementation had an issue when crossing daylight saving changes (wenn die Zeitumstellung innerhalb der letzten 90 Tage lag)

This commit is contained in:
dankito 2021-04-17 22:12:42 +02:00
parent 9c9ebb9d57
commit cc99ebdbce
6 changed files with 21 additions and 9 deletions

View File

@ -38,6 +38,8 @@ expect class Date(millisSinceEpoch: Long) {
fun day(): Int fun day(): Int
fun addDays(days: Int): Date
fun compareTo(other: Date): Int fun compareTo(other: Date): Int

View File

@ -86,6 +86,12 @@ actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class
return components.day.toInt() 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 { actual fun compareTo(other: Date): Int {

View File

@ -56,6 +56,15 @@ actual class Date actual constructor(millisSinceEpoch: Long) : java.util.Date(mi
return super.getDate() 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 { private fun formatDate(dateFormatStyle: Int): Int {
val dateStringString = DateFormat.getDateInstance(dateFormatStyle).format(this) val dateStringString = DateFormat.getDateInstance(dateFormatStyle).format(this)

View File

@ -22,9 +22,6 @@ open class FinTsClient(
companion object { companion object {
val SupportedAccountTypes = listOf(AccountType.Girokonto, AccountType.Festgeldkonto, AccountType.Kreditkartenkonto) 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) { 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 -> getTransactionsAsync(GetTransactionsParameter(account, account.supportsRetrievingBalance, ninetyDaysAgo, abortIfTanIsRequired = true), bank) { response ->
callback(response) callback(response)

View File

@ -242,7 +242,7 @@ open class FinTsJobExecutor(
val successful = response.successful && (parameter.alsoRetrieveBalance == false || balance != null) val successful = response.successful && (parameter.alsoRetrieveBalance == false || balance != null)
val fromDate = parameter.fromDate 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() ?: bookedTransactions.map { it.valueDate }.sortedBy { it.millisSinceEpoch }.firstOrNull()
val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.errorMessage) val retrievedData = RetrievedAccountData(parameter.account, successful, balance, bookedTransactions, unbookedTransactions, fromDate, parameter.toDate ?: Date.today, response.errorMessage)

View File

@ -80,8 +80,6 @@ open class BankingPresenter(
val OpticalTanMethods = listOf(TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanQrCode, val OpticalTanMethods = listOf(TanMethodType.ChipTanFlickercode, TanMethodType.ChipTanQrCode,
TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan, TanMethodType.QrCode) TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.photoTan, TanMethodType.QrCode)
protected const val OneDayMillis = 24 * 60 * 60 * 1000L
protected val ShortDateStyleDateFormatter = DateFormatter(DateFormatStyle.Short) protected val ShortDateStyleDateFormatter = DateFormatter(DateFormatStyle.Short)
protected val MediumDateStyleDateFormatter = DateFormatter(DateFormatStyle.Medium) 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) { 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) fetchAccountTransactionsAsync(account, fromDate, abortIfTanIsRequired, callback)
} }
@ -477,7 +475,7 @@ open class BankingPresenter(
} }
open fun getDayOfFirstTransactionStoredOnBankServer(account: IBankAccount<IAccountTransaction>): Date { open fun getDayOfFirstTransactionStoredOnBankServer(account: IBankAccount<IAccountTransaction>): Date {
return Date(Date.today.millisSinceEpoch - (account.countDaysForWhichTransactionsAreKept ?: 0) * OneDayMillis) return Date.today.addDays((account.countDaysForWhichTransactionsAreKept ?: 0) * -1)
} }
protected open fun getDateOfFirstRetrievedTransaction(transactions: Collection<IAccountTransaction>): Date? { protected open fun getDateOfFirstRetrievedTransaction(transactions: Collection<IAccountTransaction>): Date? {