mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Use Calendar to compute target dates
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
enum PollHistoryConstants {
|
||||
static let chunkSizeInDays: UInt = 30
|
||||
static let oneDayInSeconds: TimeInterval = 8.6 * 10e3
|
||||
}
|
||||
|
||||
enum PollHistoryViewModelResult: Equatable {
|
||||
|
||||
@@ -142,8 +142,10 @@ extension PollHistoryViewModel.Context {
|
||||
}
|
||||
}
|
||||
|
||||
var syncedPastDays: UInt {
|
||||
let timeDelta = max(viewState.syncStartDate.timeIntervalSince(viewState.syncedUpTo), 0)
|
||||
return UInt((timeDelta / PollHistoryConstants.oneDayInSeconds).rounded())
|
||||
var syncedPastDays: Int {
|
||||
guard let days = Calendar.current.dateComponents([.day], from: viewState.syncedUpTo, to: viewState.syncStartDate).day else {
|
||||
return 0
|
||||
}
|
||||
return max(0, days)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ private extension PollHistoryService {
|
||||
|
||||
func startPagination() -> AnyPublisher<TimelinePollDetails, Error> {
|
||||
let startingTimestamp = oldestEventDate
|
||||
targetTimestamp = startingTimestamp.subtractingDays(chunkSizeInDays)
|
||||
targetTimestamp = startingTimestamp.subtractingDays(chunkSizeInDays) ?? startingTimestamp
|
||||
|
||||
let batchSubject = PassthroughSubject<TimelinePollDetails, Error>()
|
||||
currentBatchSubject = batchSubject
|
||||
@@ -190,8 +190,8 @@ private extension PollHistoryService {
|
||||
}
|
||||
|
||||
private extension Date {
|
||||
func subtractingDays(_ days: UInt) -> Date {
|
||||
addingTimeInterval(-TimeInterval(days) * PollHistoryConstants.oneDayInSeconds)
|
||||
func subtractingDays(_ days: UInt) -> Date? {
|
||||
Calendar.current.date(byAdding: DateComponents(day: -Int(days)), to: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user