NSCalendar firstWeekday returns wrong based on NSLocale region

Hi,

I'm trying to implement a dynamic calendar where the first day of the week will be based on the locale, unfortunately, it seems NSLocale doesn't conform with the regions in the world, only works for US, for example:

NSCalendar *calendar = [NSCalendar currentCalendar];
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"pt_BR"];
[calendar setLocale:locale];
NSLog(@"firstDayOfWeek: %@", [calendar firstWeekday]); // Returns 2, which is Monday but in Brazil the first day of week is Sunday, it should return 1
NSCalendar *calendar = [NSCalendar currentCalendar];
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
[calendar setLocale:locale];
NSLog(@"firstDayOfWeek: %@", [calendar firstWeekday]); // Returns 1, which is correct for United States

Does anybody know which standard the NSLocale follows to return on the first day of the week?

Replies

Returns 2, which is Monday but in Brazil the first day of week is Sunday, it should return 1

Are you sure about that? I fired up a macOS 12.4 VM with the language set to Portuguese (Brazil) and the region set to Americas > Brazil. After the necessary restart (because I changed the primary language), I went back to Preferências do Sistema > Idioma e Região, clicked Avançado, and in the Geral tab the “Primeiro dia da semana” popup is set to “segunda-feira”. That’s Monday, right?

My experience is that many regions have a disparity between the official first day of the week, which is what macOS uses, and the first day of the week commonly used by folks in that region. For example, here in the UK the official frist day of the week is Monday but many folks, especially older folks, still use Sunday. And that’s why we have a preference (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Quinn,

Thanks for your response and your time testing this problem.

I'm Brazilian and I'm used to Sunday being the first day of the week there, and even this link here is very accurate with the first day of the week in the world:

http://chartsbin.com/view/41671

As you said could be that's not official, so my main question here would be, from where the official firstWeekday comes from?

I mean, does it follows any ISO standard? If not, do you know where can I find the official documentation that defines the first day of week for each country?

Thanks!

I mean, does it follows any ISO standard?

I’ve no idea.

Apple usually gets this sort of info from CLDR. It seems that CLDR does include first-day-of-the-week info, namely the firstDay element discussed here. You should look up the Brazil tables to see what that’s set to. That might also tell you where the value comes from. And if you think that’s wrong, CLDR has a process for requesting a fix. And it CLDR changes, those changes usually flow through to Apple platforms in the next major OS release.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for all information, really clarifying.

However, having a look at the CLDR repo I was able to find the firstDay element definition here:

https://github.com/unicode-org/cldr/blob/83821f2dbd9a9311b9b325e9452ebae396676bc0/common/supplemental/supplementalData.xml

And it seems that in CLDR repository, the firstDay for BR is declared correct, and is in the same group definition of US:

<firstDay day="sun"  territories="AG AS BD BR BS BT BW BZ CA CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY	SA SG SV TH TT TW UM US VE VI WS YE ZA ZW" />

Does that mean it's an Apple bug?

Cheers!

Does that mean it's an Apple bug?

Honestly, I’m not qualified to give a definitive answer to that. However, at this point it’s definitely worth you filing a bug about it. The fact that our platforms are out of sync with both your local experience and CLDR is weird.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for all the information.

I have opened a bug report, the report number is FB11401512

Cheers!

Add a Comment