Short question: Given a year, week-of-year, and weekday in that week-of-year, 
what is the most reliable way to get the NSDate for that day even when the 
week-of-year is week 1? This is calendrical grey area, because there may be two 
week 1s in a year.

Long question:

We're using the NSCalendar class to get an NSDate given a year, week-of-year, 
and weekday number. For weeks 2 through 52 of the Gregorian year, NSCalendar 
gives us the correct date.

But this falls apart when the week-of-year number is week 1, because many years 
on the Gregorian calendar have two week 1s. In 2013 AD, there are two week 1s 
if the first weekday is on a Sunday - this week, and the last week of the year. 
So when I tell it to find the date corresponding to Sunday of week 1 of 2013, I 
want NSCalendar to return December 30, 2012. That is the first Sunday of the 
first week of 2013. However, it actually returns December 29, 2013. That date 
is the Sunday of the **other** week 1 of 2013, the one that is the first week 
of 2014.

What do I have to set in NSDateComponents to give NSCalendar a little more 
context so I get the correct date number? I already tried setting the month to 
1 (January) in the components, and I got the same incorrect results.

Nick Zitzmann
<http://www.chronosnet.com/>


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to