Saturday, October 14, 2023
HomeiOS Developmentios - Trying to find date backwards with `nextDate(after:matching...` simply unusually lengthy...

ios – Trying to find date backwards with `nextDate(after:matching…` simply unusually lengthy in time?


I take advantage of nextDate(after:matching:matchingPolicy:repeatedTimePolicy:route:) to seek for a date backwards.

I need to seek for the twenty third of the month earlier than, however I get a leap to from 2022 to 1995.

Is that this a bug or am I simply lacking one thing calendar-wise that makes this consequence truly right?

var calendar: Calendar = .autoupdatingCurrent
calendar.timeZone = TimeZone(identifier: "Europe/Stockholm")!

let date = Date(timeIntervalSince1970: 1666310400.0) // "Oct 21, 2022 at 2:00 AM"
print(date) // "2022-10-21 00:00:00 +0000n"
calendar.nextDate(after: date, // "Sep 23, 1995 at 12:00 AM" ??
                  matching: DateComponents(day: 23),
                  matchingPolicy: .previousTimePreservingSmallerComponents,
                  route: .backward)



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments