Hi,
Since iOS 11, there have been a lot of weird functionning with how Calendar (NSCalendar) and Date (formatters, components, etc) work.
This was so bad that nearly every single Apple app was displaying very weird behavior (and even broken ones) when setting the phone's calendar to anything but Gregorian.
I am not going to upload a Playground (because then this post will take ages to get moderated), but I'm going to pass some code here:
Edit: Well, nevermind, it went into moderation ... this edit is 3 days later, still in moderation ... let's see how long it takes.
Edit2: One week later...
Supposing the device is set to Japanese Calendar or we get a Japanese Date (for example: 1983-01-01, displayed normally as S58-01-01, the S is for Showa era)
Using:
Calendar.current.date(from: japaneseComponents)
we get:
2631-12-31 15:00:00 +0000
normally, we should get: 1982-01-01 15:00:00 +0000 ... Why the weird year? and why did the date shift from 01-01 to 12-31???
Doing something as trivial as:
Calendar.current.dateComponents([.year], from: Calendar.current.date(from: japaneseComponents), to: Date())
we get:
-613
(normally, we should get: 35)
notice: This weird year display has been in almost all of Apple apps (Music, Health, Calendar), and I've filled countless bug reports that are still open for half a year now.
Using:
japaneseComponents.calendar.date(from: japaneseComponents)
we get:
1982-12-31 15:00:00 +0000
note: The date is close but it shifted by one day.
Going all out and trying:
japanseComponents.calendar?.dateComponents([.year], from: japaneseComponents.calendar?.date(from: japaneseComponents), to: Date())
we finally get the correct difference: 35
This kind of behaviour was never here before, any calendar could correctly calculate date differences if given the correct components (that include Calendar and Era), but now it doesn't work anymore.
This broke almost all apps using Calendar to handle internationalization, and forced us to work only with Gregorian to avoid headache.