Re: NSCalendar week-of-year calculations and week 1
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