<font face="Verdana,Arial,Helvetica,sans-serif" size="2">Hi Alex, <br><br>Thanks for your response. <br><br>This failure doesn't happen with ISO8601 alone. There are half a dozen identifiers that aren't supported. Having said that, I added these identifiers to that if-statement and the calendar initialization did happen:<br><br>.indian, .islamicTabular, .islamicUmmAlQura, .iso8601, .persian, .republicOfChina<br><br>I am not sure if they would cause any other problems thought. <br><br>Another thing I got curious about: Why is NSCalendar.Identifier.ISO8601 associated with an empty string here (it doesn't really matter, I guess)?<br><a target="_blank" href="https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSCalendar.swift#L56">https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSCalendar.swift#L56</a><br><br><span><font face="Verdana,Arial,Helvetica,sans-serif" size="2"><font><font><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div dir="ltr" style="font-style: normal;"><br><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif">Pushkar N Kulkarni,</font></div>
<div dir="ltr" style="font-style: normal;"><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif">IBM Runtimes</font></div><div dir="ltr" style="font-style: normal;"><font face="Sans Serif, Verdana, Arial, Helvetica, sans-serif"><br></font></div><div dir="ltr"><font face="serif, Times New Roman, Times, serif"><i>Simplicity is prerequisite for reliability - Edsger W. Dijkstra</i></font></div>
<div dir="ltr" style="font-style: normal; font-size: 10.5pt; font-family: Arial;"><br></div></div></div></div></font></font></font></span><br><br><font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif" color="#000000" size="2"><font color="#990099"><a target="_blank" href="mailto:-----alblue@apple.com">-----alblue@apple.com</a> wrote: -----</font><div class="iNotesHistory" style="padding-left:5px;"><div style="padding-right:0px;padding-left:5px;border-left:solid black 2px;">To: Pushkar N Kulkarni/India/IBM@IBMIN<br>From: Alex Blewitt <alblue@apple.com><br>Sent by: <a target="_blank" href="mailto:alblue@apple.com">alblue@apple.com</a><br>Date: 10/04/2016 03:28PM<br>Cc: swift-corelibs-dev &lt;<a target="_blank" href="mailto:swift-corelibs-dev@swift.org">swift-corelibs-dev@swift.org</a>&gt;<br>Subject: Re: [swift-corelibs-dev] Calendar identifiers<br><br><!--Notes ACF
<meta http-equiv="Content-Type" content="text/html charset=utf8">--><br class=""><div><blockquote type="cite" class=""><div class="">On 4 Oct 2016, at 10:29, Pushkar N Kulkarni via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><font class="" face="Verdana,Arial,Helvetica,sans-serif" size="2">Hi there,&nbsp;<div class=""><br class=""></div><div class="">I've hit an obstacle while working on a crash seen in initing a Calendar (<a href="https://bugs.swift.org/browse/SR-2551)" target="_blank" class="">https://bugs.swift.org/browse/SR-2551)</a><br class=""><font class="" face="Verdana,Arial,Helvetica,sans-serif" size="2"><font class=""><font class=""><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div class="socmaildefaultfont" dir="ltr"><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">For the Calendar initialiser "<span class="syntax-keyword" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font class="" color="#aa0d91">init</font></span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font class="" color="#333333">(</font></span><span class="syntax-identifier" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;">identifier</span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font class="" color="#333333">:&nbsp;</font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font class="" color="#5c2699">Calendar</font></span><span style="font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);" class=""><font class="" color="#333333">.</font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px;"><font class="" color="#5c2699">Identifier</font></span><span class="syntax-type" style="box-sizing: inherit; font-family: Menlo, monospace; font-size: 14px; text-indent: -23.111167907714844px; background-color: rgb(249, 250, 250);"><font class="" color="#333333">)",&nbsp;</font></span>the possible values of Calendar.Identifier are listed <a target="_blank" href="https://developer.apple.com/reference/foundation/calendar.identifier" title="https://developer.apple.com/reference/foundation/calendar.identifier" class="">here</a>. However, we eventually end up calling "<span class="pl-en" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font class="" color="#795da3">_CFCalendarInitWithIdentifier</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font class="" color="#333333">(</font></span><span class="pl-c1" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font class="" color="#0086b3">CFCalendarRef</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font class="" color="#333333"> calendar, </font></span><span class="pl-c1" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;"><font class="" color="#0086b3">CFStringRef</font></span><span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; white-space: pre;" class=""><font class="" color="#333333"> identifier)" </font></span>and the latter works only for a specific set of calendar identifiers. See this if statement:</div><div dir="ltr" style="font-style: normal;" class="">&nbsp; &nbsp;<a href="https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/Locale.subproj/CFCalendar.c#L239" target="_blank" class="">https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/Locale.subproj/CFCalendar.c#L239</a><br class=""></div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">For other identifier values, we crash (that is SR-2551). On mac, all the identifier values are supported. It seems that the calendar identifier is ultimately encoded as a key-value pair in the locale ID for the calendar. &nbsp;</div><div dir="ltr" style="font-style: normal;" class=""><br class=""></div><div dir="ltr" style="font-style: normal;" class="">Can anybody please help me understand the rationale of the if-statement above? I am new to ICU. I did search for justifications but didn't come across convincing.&nbsp;<br class=""></div></div></div></div></font></font></font></div></font></div></blockquote><br class=""></div><div>The if statement is canonicalising the reference to the constant e.g. kCFCalendarIdentifierBuddhist. This allows other instances to be passed in but then resolved to the same instance, such that pointer comparisons work for future calls. The same is done for Swift.</div><div><br class=""></div><div>On macOS, there are additional checks in the CoreFoundation equivalent (such as&nbsp;kCFCalendarIdentifierISO8601) which is why it works on Darwin. However, I don't know if there were specific reasons for excluding the ISO8601 calendar, unless the ICU library doesn't understand it. Testing adding support should be a case of doing something similar to this commit, which re-enabled the Chinese calendar:</div><div><br class=""></div><div><a href="https://github.com/apple/swift-corelibs-foundation/commit/c1d940dd6099de65f959fd42274cf0e65984efe0" class="">https://github.com/apple/swift-corelibs-foundation/commit/c1d940dd6099de65f959fd42274cf0e65984efe0</a></div><br class=""><div class="">Of course building with the 'if' switch enabled may highlight other issues, but on a quick test build it seems that adding the additional if case to the statement results in the ISO8601 calendar being returned. I'll let others explain in more detail if there's some specific subtlety for why it was left out in the first place.</div><div class=""><br class=""></div><div class="">Alex</div></alblue@apple.com></div></div></font></font><BR>