[swift-users] Linux - Calendar date(byAdding:to:wrappingComponents:) returns nil when it shouldn't?

Jason Ji jason.y.ji at gmail.com
Tue Oct 4 14:10:15 CDT 2016


Hello,

I'm having an issue with (NS)Calendar on Linux which I think is a bug, but
I just wanted to check first if it was just me or if this is indeed a bug.
I've filed a bug report here, just in case:
https://bugs.swift.org/browse/SR-2846

In short, Calendar has a method date(byAdding:to:wrappingComponents:) which
returns a new date which is the result of date arithmetic on the passed-in
date. It works fine on El Capitan, but doesn't seem to work properly on
Ubuntu 14.04. Below is some sample code:

import Foundation

let today = Date()
let diffComponents = DateComponents(day: -1)
let newDate = Calendar.current.date(byAdding: diffComponents, to:
today)		//returns nil


I've tried this in the swift REPL on Ubuntu 14.04 with both Swift
3.0-RELEASE, and the latest snapshot (October 2).

If anyone else could try this out as a sanity check for me, that would be
great - I'd be happy to be embarrassed that I've done something wrong.

Thanks,

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161004/36f3f50c/attachment.html>


More information about the swift-users mailing list