Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDate return "1604" for year value?

I'm try to get birth data for contacts but if user does not choose year or the contact come from Facebook and the year or the data it self is hidden so it give me the "1604" value for the year u can see what i mean in the image.

enter image description here

enter image description here

like image 334
Omarj Avatar asked Dec 24 '12 15:12

Omarj


2 Answers

Congratulations, you've discovered an implementation detail!

First off, Contacts stores dates as points in time, and it is impossible to store a point in time without a year, because every point in time has a year. Thus, a decision had to be made about how Address Book would store an "unknown" year in a date. It was decided that "1604" would be a fine year, for several reasons:

  1. When you're talking about Address Book, it is unlikely that you'll have anyone in your address book who was born in 1604.
  2. 1604 was a leap year (by the rules of how leap years are calculated), which means that if the person whose birth year you don't know was born on February 29th, then 1604 could handle that, too.
  3. 1604 was before the Julian-Gregorian calendar switch.

Thus, if you're pulling birthdates out of Address Book, you'll need to special-case 1604 as the "birthdate where the year is unknown".

Note: To my knowledge, this is only supported when dealing with the Gregorian calendar. For all other calendars, this behavior is undefined.

like image 75
Dave DeLong Avatar answered Oct 12 '22 11:10

Dave DeLong


You can init the year in viewDidLoad.

Or check if the year was not chosen by the user, present error message.

like image 29
Luda Avatar answered Oct 12 '22 11:10

Luda