NSDate return "1604" for year value?
Asked Answered
J

2

12

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

Jaunita answered 24/12, 2012 at 15:57 Comment(0)
C
21

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.

Circumvent answered 24/12, 2012 at 16:12 Comment(2)
so i can check if it is equal to "1604" the format will be just setDateFormat:@"MM-dd"Jaunita
@Jaunita yes. You can extract the year using a Gregorian NSCalendar to get the appropriate NSDateComponents.Circumvent
A
1

You can init the year in viewDidLoad.

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

Amorist answered 24/12, 2012 at 16:7 Comment(2)
ok but this picker for native add new contact ??? and what about the contact come from Facebook ??Jaunita
You have to check if you have the year different from 1604, and if so, ask the user to fill this detail outAmorist

© 2022 - 2024 — McMap. All rights reserved.