<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 5 Oct 2016, at 16:48, Alex Blewitt via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 4 Oct 2016, at 20:10, Jason Ji via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="gmail_signature"><div class="">Hello,</div><div class=""><br class=""></div><div class="">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:&nbsp;<a href="https://bugs.swift.org/browse/SR-2846" class="">https://bugs.swift.org/browse/SR-2846</a></div><div class=""><br class=""></div><div class="">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:</div><div class=""><br class=""></div><div class=""><pre class="gmail-code-java" style="margin-top:0px;margin-bottom:0px;padding:0px;max-height:30em;overflow:auto;white-space:pre-wrap;word-wrap:normal;color:rgb(51,51,51);font-size:12px"><span class="gmail-code-keyword" style="color:rgb(0,0,145)">import</span> Foundation

let today = Date()
let diffComponents = DateComponents(day: -1)
let newDate = Calendar.current.date(byAdding: diffComponents, to: today)                <span class="gmail-code-comment" style="color:rgb(128,128,128)">//returns nil</span></pre></div><div class=""><br class=""></div><div class="">I've tried this in the swift REPL on Ubuntu 14.04 with both Swift 3.0-RELEASE, and the latest snapshot (October 2).</div><div class=""><br class=""></div><div class="">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.</div></div></div></div></div></blockquote><br class=""></div><div class="">It's worth explicitly specifying a calendar (so that it rules out any environmental setup) -- for example, Calendar(identifier:.gregorian). However, I see 'nil' as well as the return result for this operation, so it could be a bug.</div></div></div></blockquote><br class=""></div><div>I think the bug is here:</div><div><br class=""></div><div><a href="https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSCalendar.swift#L464" class="">https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSCalendar.swift#L464</a></div><div><br class=""></div><div><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""></tr><tr style="box-sizing: border-box;" class=""><td id="LC464" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre; background-color: rgb(248, 238, 199);">        _convert(comps<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>isLeapMonth, type: <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>L<span class="pl-pds" style="box-sizing: border-box;">"</span></span>, vector: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&amp;</span>vector, compDesc: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">&amp;</span>compDesc)</td></tr><tr style="box-sizing: border-box;" class=""><td id="L465" class="blob-num js-line-number" data-line-number="465" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td></tr></tbody></table><br class=""></div><div><br class=""></div><div>The leap month is defined with a capital letter here, but a lower-case letter when it's decoded:</div><div><br class=""></div><div><a href="https://github.com/apple/swift-corelibs-foundation/blob/338f4bf3a89c75a0420b49f5701466e106af02b5/CoreFoundation/Locale.subproj/CFCalendar.c#L423" class="">https://github.com/apple/swift-corelibs-foundation/blob/338f4bf3a89c75a0420b49f5701466e106af02b5/CoreFoundation/Locale.subproj/CFCalendar.c#L423</a></div><div><br class=""></div><div><table class="js-file-line-container highlight tab-size" data-tab-size="8" style="box-sizing: border-box; border-spacing: 0px; border-collapse: collapse; tab-size: 8; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><tbody style="box-sizing: border-box;" class=""><tr style="box-sizing: border-box;" class=""></tr><tr style="box-sizing: border-box;" class=""><td id="LC423" class="js-file-line blob-code-inner blob-code" style="box-sizing: border-box; padding: 0px 10px; position: relative; line-height: 20px; vertical-align: top; overflow: visible; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; word-wrap: normal; white-space: pre; background-color: rgb(248, 238, 199);">    <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">'</span>l<span class="pl-pds" style="box-sizing: border-box;">'</span></span>: <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> UCAL_IS_LEAP_MONTH;</td></tr><tr style="box-sizing: border-box;" class=""><td id="L424" class="blob-num js-line-number" data-line-number="424" style="box-sizing: border-box; padding: 0px 10px; width: 50px; min-width: 50px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; line-height: 20px; color: rgba(0, 0, 0, 0.298039); text-align: right; white-space: nowrap; vertical-align: top; cursor: pointer; -webkit-user-select: none; border-style: solid; border-color: rgb(238, 238, 238); border-width: 0px 1px 0px 0px;"></td></tr></tbody></table><br class=""></div><div><br class=""></div><div>The lower-case l should be the correct version so this probably needs to be changed here. In addition, there are optional-of-bool issues here; the 'comps.isLeapMonth' is a boolean value, which means it attempts to roll forward the leap month (which doesn't make sense). I think the error was introduced here, although it didn't help that the capitalisation was also wrong at the time:</div><div><br class=""></div><div><a href="https://github.com/apple/swift-corelibs-foundation/commit/d3300b7118924d6ad8ba411d317f33eade854bc5" class="">https://github.com/apple/swift-corelibs-foundation/commit/d3300b7118924d6ad8ba411d317f33eade854bc5</a>&nbsp;</div><div><br class=""></div><div>Alex</div><br class=""></body></html>