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