• 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: Strange results with NSDateComponents vs NSCalendarDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange results with NSDateComponents vs NSCalendarDate


  • Subject: Re: Strange results with NSDateComponents vs NSCalendarDate
  • From: "Sean McBride" <email@hidden>
  • Date: Sun, 11 Feb 2007 21:58:41 -0500

Hi Deborah,

I was hoping you'd reply, thanks for sharing your expertise!

>The reason they differ is that NSCalendarDate uses the Gregorian
>calendar for all of time, even before it was actually adopted.
>NSCalendar's version of the Gregorian calendar uses the Julian
>calendar before October 4, 1582.

I see!  Is this documented?  I can't find anything about it.

>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.

>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?

Thanks,

Sean

--
"Good artists borrow from the work of others, great artists steal" - Picasso

_______________________________________________

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

  • Follow-Ups:
    • Re: Strange results with NSDateComponents vs NSCalendarDate
      • From: Deborah Goldsmith <email@hidden>
    • Re: Strange results with NSDateComponents vs NSCalendarDate
      • From: Chris Kane <email@hidden>
References: 
 >Strange results with NSDateComponents vs NSCalendarDate (From: "Sean McBride" <email@hidden>)
 >Re: Strange results with NSDateComponents vs NSCalendarDate (From: Deborah Goldsmith <email@hidden>)

  • Prev by Date: Re: Resizing an NSButtonCell
  • Next by Date: Re: Very strange Cocoa application issue.
  • Previous by thread: Re: Strange results with NSDateComponents vs NSCalendarDate
  • Next by thread: Re: Strange results with NSDateComponents vs NSCalendarDate
  • Index(es):
    • Date
    • Thread