• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting an era's beginning date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting an era's beginning date


  • Subject: Re: Getting an era's beginning date
  • From: Christopher Nebel <email@hidden>
  • Date: Tue, 29 Jan 2008 13:17:23 -0800

On Jan 28, 2008, at 8:31 PM, Nick Zitzmann wrote:

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 like this:

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 00:00:00 -0800


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.



--Chris Nebel _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Getting an era's beginning date (From: Nick Zitzmann <email@hidden>)
 >Re: Getting an era's beginning date (From: 慧 松本 <email@hidden>)
 >Re: Getting an era's beginning date (From: Christopher Nebel <email@hidden>)
 >Re: Getting an era's beginning date (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: [Leopard, GC] Custom view in NSMenuItem crashes
  • Next by Date: Best way to notify the Controller when one Array object value is changed
  • Previous by thread: Re: Getting an era's beginning date
  • Next by thread: Re: Getting an era's beginning date
  • Index(es):
    • Date
    • Thread