RE: Bug in NSCalendarDate?
RE: Bug in NSCalendarDate?
- Subject: RE: Bug in NSCalendarDate?
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 3 May 2004 12:29:33 -0400
>
Using the method:
>
>
[NSCalendarDate dateWithYear:2004 month:0 day:ii hour:0 minute:0
>
second:0 timeZone:[NSTimeZone localTimeZone]]
>
>
returns date=2004-05-06 00:00:00 -0600 when ii = 127
>
returns date=2003-08-25 00:00:00 -0600 when ii = 128
>
>
Has the same problem if the year is 2003. Almost looks like the day
>
value is cast to a char instead of an int internally.
>
>
Am I missing something?
The documentation implies that what you are doing is illegal.
"+ (id)dateWithYear:(int)year month:(unsigned)month day:(unsigned)day
hour:(unsigned)hour minute:(unsigned)minute second:(unsigned)second
timeZone:(NSTimeZone *)aTimeZone
"Returns a calendar date initialized with the specified values for year,
month, day, hour, minute, second, and time zone, aTimeZone. The year value
must include the century (for example, 1999 instead of 99). The other values
are the standard ones: 1 through 12 for months, 1 through 31 for days, 0
through 23 for hours, and 0 through 59 for both minutes and seconds."
It would have been good if the docs also said, "The result is undefined if
the values provided are outside these ranges." But that does seem to be the
case. month = 0 and day > 31 seem to be illegal. Perhaps you should file a
bug against the docs.
If you want to find the nth day of 2004, do this:
unsigned n = 127;
NSCalendarDate *dayZero = [NSCalendarDate dateWithYear:2003
month:12 day:31 hour:0 minute:0 second:0 timeZone:[NSTimeZone
defaultTimeZone]];
NSCalendarDate *nthDayOf2004 = [dayZero dateByAddingYears:0 months:0
days:n hours:0 minutes:0 seconds:0];
Jonathan
p.s. localTimeZone simply forwards messages to defaultTimeZone, so you are
probably better off simply using defaultTimeZone directly, unless you are
archiving the date or using DO.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.