It has come to my attention that NSDate returns the wrong date for days near the end of the year. This is a major issue since my application depends on NSDate values in order to operate properly meaning that my application is have problems that I cannot correct.
Let me explain with the use of these examples. I created a simple example using the following code to display today's date:
This is a rather simple segment of code which uses [NSDate date] to get the date value for today. dateLabel is the UILabel that appears on the view in the following series of pictures.
Notice in this first image that the date is manually set to 12/25/2008 on the Mac's "Date & Time" option in the control panel. Whatever is set here is what the iPhone simulator uses as its time and date. Notice also that the date is printed properly by the date formatter: "Thursday, December 25, 2008".
This image shows the problem that is occurring. The date is manually set to 12/29/2008 and the application is restarted in the simulator. This time, the date is printed wrong! The date shows up as "Monday, December 29, 2009" which is just wrong! That date does not even exist!
This image shows the date functioning properly again. If the date is manually set to 1/1/2009 then it displays "Thursday, January 1, 2009" which is correct.
This image is yet another test but for next year. The date is manually set to 12/30/2009 and the application is relaunched. This time the date shows up as "Wednesday, December 30, 2010" which is once again a none existent date and incorrect.
Yet another test to prove my point. The date is manually set to 12/31/2011 and the date is showing up correctly. It is important to note that the problem only seems to occur during the week of New Year's meaning that the date problem just started occurring today, 12/28/2008, since the New Year begins on Thursday.
Final picture to prove the bug. The date is set automatically by the Mac so the date is set to 12/28/2008. Notice though that the date shows up as "Sunday, December 28, 2009" instead of 2008.
All in all, this is a huge flaw in the NSDate functionally and I'm rather confused as to how something like this could be happening. I just wanted to point out this problem to other Developers to see if others have noticed this issue.
You can download the XCode project I used to create these screen shots to test the problem yourself. I have not actually run the code on the phone but know that the same problem is occurring since my application has been producing weird results. If I manually set the date forward to January 1st, 2009 though the problems go away.
Here is the link for the code.
Let me know what you all are experiencing.
Thanks!
Let me explain with the use of these examples. I created a simple example using the following code to display today's date:
Code:
// Create the date formatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE, MMMM d, YYYY"];
// Set the dateLabel on the view to today's date using the date formatter
NSDate *today = [NSDate date];
dateLabel.text = [dateFormatter stringFromDate:today];
This is a rather simple segment of code which uses [NSDate date] to get the date value for today. dateLabel is the UILabel that appears on the view in the following series of pictures.
Notice in this first image that the date is manually set to 12/25/2008 on the Mac's "Date & Time" option in the control panel. Whatever is set here is what the iPhone simulator uses as its time and date. Notice also that the date is printed properly by the date formatter: "Thursday, December 25, 2008".
This image shows the problem that is occurring. The date is manually set to 12/29/2008 and the application is restarted in the simulator. This time, the date is printed wrong! The date shows up as "Monday, December 29, 2009" which is just wrong! That date does not even exist!
This image shows the date functioning properly again. If the date is manually set to 1/1/2009 then it displays "Thursday, January 1, 2009" which is correct.
This image is yet another test but for next year. The date is manually set to 12/30/2009 and the application is relaunched. This time the date shows up as "Wednesday, December 30, 2010" which is once again a none existent date and incorrect.
Yet another test to prove my point. The date is manually set to 12/31/2011 and the date is showing up correctly. It is important to note that the problem only seems to occur during the week of New Year's meaning that the date problem just started occurring today, 12/28/2008, since the New Year begins on Thursday.
Final picture to prove the bug. The date is set automatically by the Mac so the date is set to 12/28/2008. Notice though that the date shows up as "Sunday, December 28, 2009" instead of 2008.
All in all, this is a huge flaw in the NSDate functionally and I'm rather confused as to how something like this could be happening. I just wanted to point out this problem to other Developers to see if others have noticed this issue.
You can download the XCode project I used to create these screen shots to test the problem yourself. I have not actually run the code on the phone but know that the same problem is occurring since my application has been producing weird results. If I manually set the date forward to January 1st, 2009 though the problems go away.
Here is the link for the code.
Let me know what you all are experiencing.
Thanks!