Re: Strange results with NSDateComponents vs NSCalendarDate
Re: Strange results with NSDateComponents vs NSCalendarDate
- Subject: Re: Strange results with NSDateComponents vs NSCalendarDate
- From: "Sean McBride" <email@hidden>
- Date: Tue, 13 Feb 2007 22:28:39 -0500
Deborah Goldsmith (email@hidden) on 2007-02-12 20:50 said:
>The underlying ICU library allows you to choose the calendar cutover
>date, but there is no exported API for that.
For the best I'd say; but I'll file a bug on the lack of docs about the
Julian-Gregorian cutover existing.
>The problem comes just from using [NSDate description] to display the
>date/time. The value is correct; it's just the way you're formatting
>it. If you use NSDateFormatter and NSCalendar for everything
>(including formatting dates), you should be fine.
No, it's more than that. Consider a person who's birthday is shown as
(and meant to be) "February 11, 100" by AddressBook.app. The birthday
was inputted in AdressBook.app. Then I do:
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDate *bdayDate = [aPerson valueForProperty:
kABBirthdayProperty];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]
init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
NSString *formattedDateString = [dateFormatter
stringFromDate:bdayDate];
NSLog(@"formattedDateString for locale %@: %@",
[[dateFormatter locale] localeIdentifier],
formattedDateString);
and I get:
formattedDateString for locale en_CA: Thursday, February 13, 0100
13:00:00 EDT (CA)
Two days off.
>> 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?
>
>Well, if your data is already out in the field in year 100, just make
>sure you don't use NSCalendarDate or [NSDate description] for
>anything. It would be better to use something like 1900 or 2000 than
>100 if you still have a choice.
I don't use [NSDate description] anywhere. I'm working on getting rid
of all NSCalendarDate usage. But it seems I need it to get the month
and day out of those 'unknown year' birthdays.
I will be switching magic numbers, 1800 seems good, thanks Chris.
Thanks Deborah!
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Mac Software Designer Montréal, Québec, Canada
_______________________________________________
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