Thanks @Claude31 for pointing me to a couple of helpful sources.
I definitely understand that changing weekday will have unpredictable results for day, month, year. but I'm still not sure I understand why hour, minute need to get clobbered.
Having said that, thanks to your links I've changed my approach and am using Calendar's nextDate func
mutating func update(updatedWeekday: Int? = nil, updatedHour: Int? = nil, updatedMinute: Int? = nil) {
var components = DateComponents()
components.weekday = updatedWeekday == nil ? weekday : updatedWeekday
components.hour = updatedHour == nil ? hour : updatedHour
components.minute = updatedMinute == nil ? minute : updatedMinute
let nextDate = Self.calendar.nextDate(after: underlyingDate, matching: components, matchingPolicy: .nextTime, direction: .forward)
if let nextDate = nextDate {
underlyingDate = nextDate
}
}
Topic:
App & System Services
SubTopic:
General
Tags: