Re: NSDateComponents question
Re: NSDateComponents question
- Subject: Re: NSDateComponents question
- From: Chris Kane <email@hidden>
- Date: Tue, 1 Jul 2008 10:44:16 -0700
On Jul 1, 2008, at 9:26, mmalc crawford wrote:
Hi Chris,
On Jul 1, 2008, at 9:10 AM, Christopher Kane wrote:
The more subtle and serious issue is that Sunday in the current
week might be in the previous Month (so, Day < Weekday), or even
previous Year, so setting the Day to a negative value and keeping
the Month and Year the same will have ... "who knows what effect".
My apologies; I did do some testing and found that the resultant
date was always correct.
Could you elaborate on what circumstances this might not be correct?
Did you try starting with a starting date of Jan 1, 2009? The
Weekday would be 5, the Day 1.
January 2009
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
The previous Sunday is December 28, 2008.
Passing a Year, Month, Day of (2009, 1, -3) (-3 == 1 - (5 - 1) in
your original computation) is passing an out-of-bounds value with
dateWithComponents:, with who-knows-what effect. It might be well-
defined, it might not be. The result might change between OS
releases. In other words, it seems a bit ambiguous, so best to just
avoid it.
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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