[swift-evolution] [swift-corelibs-dev] Proposal: Conforming NSDate to Comparable

Pierre Habouzit phabouzit at apple.com
Sat Dec 5 21:10:38 CST 2015


-Pierre

> On Dec 5, 2015, at 3:51 PM, Brent Royal-Gordon via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
> 
>> I think it's a good idea to conform NSDate to the Comparable protocol, so instead of using:
>> 
>> if someDate.compare(today) == .OrderedAscending { }
>> 
>> Developers can easily compare using compare dates using comparison operators:
>> 
>> if someDate < today { }
> 
> I would also suggest we add Strideable, which would allow you to add and subtract NSTimeIntervals, plus subtract two NSDates to get the NSTimeInterval between them.
> 
> https://gist.github.com/brentdax/11b3275424d0833cfd99

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.

-Pierre


More information about the swift-evolution mailing list