views:

551

answers:

4

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date rolls over from December 26th to December 27th, the year changes to 2010.

I even rolled it forward to 2011... and it changes when December 25th changes to the 26th.... but wait... in 2012, it correctly rolls over on December 31 - January 1... and then its back to 29th-30th in 2013. Is there some kind of astronomical phenomenon I am not aware of going on or does Apple run on some crazy Heechee calendar I don't know of? The calendar app works correctly...

The most likely explanation is I am missing something so obvious that I will slap myself when I realize it. But hey, I haven't slept in... wow I don't remember if its been two days or three. Take pity and help me out here.

UPDATE: So maybe it wasn't something simple. Still looking for an answer here! Am I really the only person who has experienced this?? I'll bet when the end of December rolls around, more people will hit the same roadblock.

UPDATE2: Anyone? Still looking, still not finding...

UPDATE3: Still haven't found a solution. Come on! This is an interesting puzzle!

UPDATE4: Still no answer found. I have submitted the app and it is now in the appstore. Would still like to see this problem solved so I can update the app.

A: 

I'm also experiencing this problem, although my app is already live. Any help much appreciated.

Graham
No solution yet. My app also went live a couple weeks back. Still hoping for an answer here. If you agree that this is a good question, make sure to vote it up so we can get it figured out!
Max Kilgore
Also, for future reference you should consider posting statements like these as a comment instead of an answer. Hope you find the answers you are looking for!
Max Kilgore
+3  A: 

There may be this problem, that when you are on the last week of the month and the week has fewer than 7 days left in current month, then perhaps the API treated the week as the first week of the next month. Since december of 2012 has already 7 days in its last week there is no problem in that month.

I was getting the same problem here, and I solved it.

- (int) currentWeekOfMonth
{
    return CFCalendarGetOrdinalityOfUnit (
           CFCalendarCopyCurrent(),
           kCFCalendarUnitWeek,
           kCFCalendarUnitMonth,
           [self absoluteTime]);
}

my requirement is to show week number and for this i calculate the week number of first week of month and the add this to the total number of week in month.

int currentWeekNumberInYear =   [_calendarInfo currentWeekOfYear];
int currentWeekNumberInMonth = [_calendarInfo currentWeekOfMonth];
currentWeekNumberInYear = currentWeekNumberInYear-currentWeekNumberInMonth +1;
currentWeekNumberInYear = currentWeekNumberInYear<0 ? (NSInteger)[_calendarInfo weeksInMonth] ==5 ?49:48   : currentWeekNumberInYear;

I hope it will be useful to you.

vikas
Great idea! Ill go check it in my code and see what happens.
Max Kilgore
This worked for me! Thanks for the help!
Max Kilgore
+1  A: 

This post on TUAW describes a similar problem in PhotoBooth on Mac OS X:

http://www.tuaw.com/2009/12/29/beware-photo-booth-time-stamps-its-a-bug-not-a-feature/

One commenter agrees with vikas that it's an end-of-week issue.

Frank Schmitt
A: 

Turns out its the Date format string used to set up the NSDateFormatter that was causing this for me.

"yyyy" corresponds to the 4-digit year, while YYYY corresponds to the year starting from the Sunday of the 1st week of year. Why anyone would want this is anyone's guess, and it would really help if Apple provided a link to their list of format specifiers, but there you go.

Just make sure your format string has the year component in lowercase and it should be sorted.

Graham