• 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
NSCalendar bug.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCalendar bug.


  • Subject: NSCalendar bug.
  • From: Half Activist <email@hidden>
  • Date: Tue, 30 Jan 2007 15:46:38 +0100

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


  • Follow-Ups:
    • Re: NSCalendar bug.
      • From: Johan Kool <email@hidden>
    • Re: NSCalendar bug.
      • From: Tommy Nordgren <email@hidden>
    • Re: NSCalendar bug.
      • From: Deborah Goldsmith <email@hidden>
  • Prev by Date: Re: (no subject)
  • Next by Date: Re: How to add an managedObject to an arrayController and inherit from a superentity ?
  • Previous by thread: NSBrowser and cell size
  • Next by thread: Re: NSCalendar bug.
  • Index(es):
    • Date
    • Thread