On Jan 28, 2008, at 9:11 PM, Christopher Nebel wrote:
Realistic or not, they did it. =) I think the Japanese calendar
support was added in Tiger; the era names go back to Taika in 645
AD. I found that I can get at least the year by using something
jp = [[NSCalendar alloc] initWithCalendarIdentifier:@"japanese"];
components = [NSDateComponents alloc] init];
[components setEra:235]; // Heisei; Taika is 0.
date = [jp dateFromComponents: components]; // date is 1989-01-01
Notice, however, that the day is wrong. I don't know if that's a
deficiency in my code or in the era data itself.
The date is actually correct. This is why I wanted to know the
method of getting an era's beginning date, because eras, unlike
years, months, and days, can begin and end at any time on a calendar.
In the case of the Japanese calendar, the 235th era is indeed the
Heisei era, but since you didn't specify year & date components,
NSCalendar assumes you meant the first year/month/day in that time
frame. The first year of the Heisei era is 1989, but January 1, 1989
is actually in the Showa (234th) era.
I guess I shouldn't have said "wrong", but rather "not what we
wanted." =) With a bit more experimentation, I established that Mac
OS does in fact know the precise date of the era change -- getting the
era for January 8, 1989 tells me 235 (Heisei), but for January 7, it's
234 (Showa). How to get NSCalendar (or whoever) to return that date,
however, escapes me.