Re: Trouble comparing NSCalendarDates
Re: Trouble comparing NSCalendarDates
- Subject: Re: Trouble comparing NSCalendarDates
- From: j o a r <email@hidden>
- Date: Mon, 15 Nov 2004 14:25:59 +0100
On 2004-11-15, at 13.52, Tito Ciuro wrote:
So I guess it's impossible to store a date and later recreate a
perfect copy, correct? I was hoping that adding the extra sub-second
info to the date would end up making it the same as the original date.
You could do something like this:
NSCalendarDate *aDate = [NSCalendarDate calendarDate];
NSString *dateStr = [aDate descriptionWithCalendarFormat: C_FORMAT];
NSCalendarDate *restoredCalendarDate1 = [NSCalendarDate
dateWithString: dateStr calendarFormat: C_FORMAT];
NSCalendarDate *restoredCalendarDate2 = [NSCalendarDate
dateWithString: dateStr calendarFormat: C_FORMAT];
NSTimeInterval interval = [restoredCalendarDate1
timeIntervalSinceDate: restoredCalendarDate2];
BOOL isEqual = [restoredCalendarDate1 isEqualToDate:
restoredCalendarDate2];
NSLog(@"interval: %f, isEqual: %d", interval2, isEqual2);
interval: 0.000000, isEqual: 1
In other words, if you generate two instances from the same string
representation they will be equal. So, if you *always* pass your new
instances through a serialization, you could later compare them to
other de-serialized instances using "isEqualToDate".
That said, I think it's better that you settle for a time interval
granularity, and compare like suggested in the page from the
documentation that you quoted in your last message.
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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