Re: NSCalendar bug.
Re: NSCalendar bug.
- Subject: Re: NSCalendar bug.
- From: Deborah Goldsmith <email@hidden>
- Date: Tue, 30 Jan 2007 10:24:15 -0800
Another possible issue is that CFAbsoluteTime is a floating point
number. Try adding one second to d2 and see what you get.
Deborah Goldsmith
Internationalization, Unicode Liaison
Apple Inc.
email@hidden
On Jan 30, 2007, at 10:15 AM, Deborah Goldsmith wrote:
How are you setting d1 and d2? Note that 2039 and 2045 are past the
range of the usual 32 bit Unix date/time routines. Are you sure
you're not wrapping around and getting something in the 20th century?
Deborah Goldsmith
Internationalization, Unicode Liaison
Apple Inc.
email@hidden
On Jan 30, 2007, at 6:46 AM, Half Activist wrote:
Hello Cocoa-dev members,
I'm posting to the list because I'm wondering if there is a bug
in the implementation of NSCalendar, actually the gregorian calendar.
Suppose you've got the following code to compute the number of
days between two dates, d1 and d2.
static NSCalendar *gregorian = nil;
if( gregorian == nil )
gregorian = [ NSCalendar currentCalendar ];
unsigned int unitFlags = NSDayCalendarUnit;
NSDateComponents *comps = [ gregorian components: unitFlags
fromDate: d1 toDate: d2 options: 0 ];
int days = [ comps day ];
if:
d1 = 2045-10-01 00:00:00 +0100
d2 = 2045-10-30 00:00:00 +0100
then the result of this code is 'days == 28' where it should be 29.
it also fails for:
d1 = 2039-04-01 00:00:00 +0100
d2 = 2039-10-31 00:00:00 +0100
the result being 212 days instead of 213.
I discovered it while testing 2 other implementations of date
interval algorithm,
as I considered I could rely on NSCalendar to detect errors.
The two other algorithms always give the same result, and so do
various date interval calculator
on the Internet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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