Create a new NSCalendar

I want to be able to convert between Gregorian and Julian calendars (note: not a "Julian date") using NSCalendar on the iPhone. How can I subclass NSCalendar to use the Julian calendar? I want to do this without respect for 1582 or 1752 or any year.

+2


source to share


1 answer


For now you can of course go for it, but I suspect NSCalendar

subclassing is tricky. This is a helpless bridging, which complicates things; intertwines with NSLocale, which complicates things; it is initialized with identifiers, not a subclass, which complicates things; and gives no indication of what methods are its primitives, which ... complicates things ...

Do you need a subclass to connect to your existing architecture? Otherwise, it would be easiest to create an object from scratch with a similar interface. You can use NSGregorianCalendar

to do most of the work for you and just offset the date for the required days before calculating the date components. You will need special logic for 1700, 1800 and 1900 (and of course 2100, etc.), since it NSGregorianCalendar

won't let you create date components for leap days in those years, but this is still arguably easier than the whole component component calculation manually.



Just wondering what was the purpose of such a calendar?

+1


source







All Articles