Question

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

Was it helpful?

Solution

While you can certainly have a go at it, but I suspect that NSCalendar is tricky to subclass. It's toll-free bridged, which complicates things; is entwined with NSLocale, which complicates things; it's initialized with identifiers rather than being subclassed, which complicates things; and gives no guidance on which methods are its primitives which... complicates things...

Do you need the subclass in order to plug into an existing architecture? If not, it would probably be easiest to create an object from scratch that has a similar interface. You may be able to use an NSGregorianCalendar to do most of the work for you and just offset the date by the requisite days before calculating date components. You'll need special logic for 1700, 1800 and 1900 (and of course 2100, etc.) since NSGregorianCalendar won't let you create date components for a leap day in those years, but that's still probably easier than doing all the date component calculations by hand.

Just curious what the goal of such a calendar would be?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top