Re: Trouble comparing NSCalendarDates
Re: Trouble comparing NSCalendarDates
- Subject: Re: Trouble comparing NSCalendarDates
- From: Tito Ciuro <email@hidden>
- Date: Mon, 15 Nov 2004 12:24:12 +0100
On Nov 15, 2004, at 11:35, Darkshadow wrote:
Well, you're already using the timeIntervalSinceDate: method - you
could use that to check if the two are equal. If it returns a time
interval of less than 1, then only the sub-second information is
different and you can consider them equal.
The problem is that it's a framework returning the date, so other
developers are probably going to wonder why the date returned doesn't
match the one stored.
-- Tito
On Nov 15, 2004, at 5:14 AM, Tito Ciuro wrote:
Hello again,
I think I know what happens...
If I call this:
returnedValue = [NSCalendarDate dateWithString: [NSString
stringWithUTF8String: data]];
The proper date is returned... *however*: if you compare both dates,
they're still *not* the same. It seems to me that the original date
created using [NSCalendarDate date] stores sub-second information.
This extra info is not stored to disk, so when we instantiate a new
NSCalendarDate object with the above statement, the sub-second
information has been lost:
NSTimeInterval interval = [testDataDate
timeIntervalSinceDate:verifyDate];
NSLog(@"interval between the two: %f", interval);
shows:
2004-11-15 11:03:18.880 QuickLiteTestRun[2243] interval between the
two: 0.872705
So, in order to compare both dates we'll have to do this instead:
[[testDataDate description] isEqualToString: [verifyDate
description]];
Is there any way I can store/retrieve to disk all the information
belonging to an NSCalendarDate?
Thanks once again,
-- Tito
On Nov 15, 2004, at 10:32, j o a r wrote:
You should probably do:
NSString *dateStr = [NSString stringWithUTF8String: data];
NSCalendarDate *aDate = [NSCalendarDate dateWithString: dateStr
calendarFormat: nil];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden