• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSCalendar week-of-year calculations and week 1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCalendar week-of-year calculations and week 1


  • Subject: NSCalendar week-of-year calculations and week 1
  • From: Nick Zitzmann <email@hidden>
  • Date: Fri, 04 Jan 2013 17:44:03 -0700

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 (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

  • Follow-Ups:
    • Re: NSCalendar week-of-year calculations and week 1
      • From: Greg Parker <email@hidden>
    • Re: NSCalendar week-of-year calculations and week 1
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: NSSplitView -drawDividerInRect
  • Next by Date: Re: NSCalendar week-of-year calculations and week 1
  • Previous by thread: Simple Value Expressions in a Core Data Mapping Model?
  • Next by thread: Re: NSCalendar week-of-year calculations and week 1
  • Index(es):
    • Date
    • Thread