[swift-evolution] [swift-corelibs-dev] Proposal: Conforming NSDate to Comparable
Brent Royal-Gordon
brent at architechies.com
Sat Dec 5 23:10:14 CST 2015
> NSDate (and dates/timestamps in general) is a poor choice for Strideable, because, DST.
> A Calendar using this interface for a repeating event would be broken using this. Or you would break anyone who really wants to iterate every fixed 86400 seconds.
Sometimes you want to add an interval of time according to the user’s clock; NSTimeInterval/NSDate math will do the wrong thing there. But sometimes you just want to get an NSDate thirty seconds from now, and for all you care the user can fly to Timbuktu during that time. That’s the sort of thing I’m using this for:
// Don’t add to undo manager if we’re too close to the last change
guard now - lastChangeDate > undoCoalescingTimespan else { return }
It is simply not the case that *all* arithmetic on NSDates is incorrect unless it involves NSCalendar and NSDateComponents.
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list