I just tested with other time zones and the results are different... For some time zones, the result is correct, for others, not. I used the following code to print the result for all time zones.
Optional(1970-08-31 23:00:00 +0000) for Europe/London
Optional(1995-08-31 23:00:00 +0000) for Europe/Paris
Optional(2002-08-31 22:00:00 +0000) for Europe/Vilnius
Optional(2023-09-01 07:00:00 +0000) for America/Los_Angeles
for zone in TimeZone.knownTimeZoneIdentifiers {
var calendar: Calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: zone) ?? .autoupdatingCurrent
let matchingDateComponents: DateComponents = DateComponents(month: 9)
let date: Date? = calendar.nextDate(
after: Date.now,
matching: matchingDateComponents,
matchingPolicy: .nextTime,
direction: .backward
)
print(zone, date)
}
Topic:
App & System Services
SubTopic:
General
Tags: