Use Calendar to compute target dates

This commit is contained in:
Alfonso Grillo
2023-01-26 15:16:48 +01:00
parent a83075f2f3
commit a9f12947d4
3 changed files with 8 additions and 7 deletions
@@ -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)
}
}