• 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
Re: Trouble comparing NSCalendarDates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Trouble comparing NSCalendarDates
      • From: Tito Ciuro <email@hidden>
References: 
 >Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: j o a r <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: j o a r <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: j o a r <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: j o a r <email@hidden>)
 >Re: Trouble comparing NSCalendarDates (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Re: How to embed a popup menu in an NSTextField
  • Next by Date: Re: Trouble comparing NSCalendarDates
  • Previous by thread: Re: Trouble comparing NSCalendarDates
  • Next by thread: Re: Trouble comparing NSCalendarDates
  • Index(es):
    • Date
    • Thread