• 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
Re: NSCalendar week-of-year calculations and week 1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCalendar week-of-year calculations and week 1


  • Subject: Re: NSCalendar week-of-year calculations and week 1
  • From: Kyle Sluder <email@hidden>
  • Date: Fri, 04 Jan 2013 17:21:41 -0800

On Fri, Jan 4, 2013, at 04:44 PM, Nick Zitzmann wrote:
> 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.

Use -setYearForWeekOfYear:, like so:

Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on
darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Foundation
>>> dc = Foundation.NSDateComponents.alloc().init()
>>> dc.setWeekOfYear_(1)
>>> dc.setYearForWeekOfYear_(2013)
>>> dc.setWeekday_(1)
>>> Foundation.NSCalendar.currentCalendar().dateFromComponents_(dc)
2012-12-30 08:00:00 +0000

If you use -setYear: instead of -setYearForWeekOfYear:, you get the
behavior you described.

--Kyle Sluder
_______________________________________________

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

References: 
 >NSCalendar week-of-year calculations and week 1 (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: NSCalendar week-of-year calculations and week 1
  • Next by Date: Re: NSCalendar week-of-year calculations and week 1
  • Previous by thread: NSCalendar week-of-year calculations and week 1
  • Next by thread: Re: NSCalendar week-of-year calculations and week 1
  • Index(es):
    • Date
    • Thread