Skip to content

Instantly share code, notes, and snippets.

@klaaspieter
Created July 19, 2010 11:17
Show Gist options
  • Save klaaspieter/481288 to your computer and use it in GitHub Desktop.
Save klaaspieter/481288 to your computer and use it in GitHub Desktop.
[[CPDate dateWithTimeIntervalSince1970:seconds] isEqualToDate:[CPDate dateWithTimeIntervalSince1970:seconds]]
// initWithTimeIntervalSince1970 is defined as
- (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds
{
self = new Date(seconds * 1000);
return self;
}
// equalToDate was defined as (not working)
- (BOOL)isEqualToDate:(CPDate)aDate
{
if (!aDate)
return NO;
return self === aDate;
}
// equalToDate is now defined as (working)
- (BOOL)isEqualToDate:(CPDate)aDate
{
if (!aDate)
return NO;
return !(self < aDate || self > aDate);
}
@alloy
Copy link

alloy commented Jul 19, 2010

Why would you wonder that? Afaik, the valueOf method is implemented by all, as it is the way to get a primitive value out of objects. For instance: http://msdn.microsoft.com/en-us/library/ftx8swz5(v=VS.85).aspx, https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object/valueOf etc.

@klaaspieter
Copy link
Author

I'm not wondering about browser implementation, more about if they will always return the same value for the same time. I've read several comments on Stackoverflow which said they were unsure about it.

If it's guaranteed to always be equal than the question is which of these two methods is faster. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment