Re: Strange results with NSDateComponents vs NSCalendarDate
Re: Strange results with NSDateComponents vs NSCalendarDate
- Subject: Re: Strange results with NSDateComponents vs NSCalendarDate
- From: Chris Kane <email@hidden>
- Date: Mon, 12 Feb 2007 11:47:18 -0800
On Feb 11, 2007, at 6:58 PM, Sean McBride wrote:
Since you're converting from a date
to an absolute time using NSCalendar, and then converting back to a
date using NSCalendarDate (implicitly in the case of your call to
[NSDate description] via NSLog), and you're passing a date that's
around 100 AD, you get a different result. Since the Gregorian and
Julian calendars differ by one day every 400 years, and the date you
give is about 1483 years before the changeover date, you're getting a
difference of three days.
Is there a way to get the pure-Gregorian behaviour with NSCalendar/
NSDateComponents? Or must I use old NSCalendarDate? I was hoping to
purge all NSCalendarDate usage.
Q1: Not currently.
If you pass a year more recent than the 16th century, you should get
results that match. Either that, or use NSCalendar and
NSDateFormatter to display the date, rather than [NSDate
description].
Let me explain what I am really doing. AddressBook insists that
birthdays are fully specified (year, month, day) (<rdar://2970531>)
but
in in real life people often only know the month and day. As a
workaround, my app has set the year to 100 if the user does not know
the
year. Up to now I have been using the pure-Gregorian NSCalendarDate.
Now that I have changed to NSCalendar/NSDateComponents this has
apparently come back to bite me. Do you have any advice?
Use 1800 instead of 100? One bogus year is about as good as another.
And how many people are likely to put their great great great great
great great great grandmother (and her birthday) in their
AddressBook? 1800 gets you passed the switchover (Sept 1752) for
Great Britain and the United States to the Gregorian calendar.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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