[[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); | |
} |
Yeah I figured that out. But I'm unsure if d1.getTime() or d1.valueOf() actually work properly. I haven't found any conclusive answer for this on Google/Stackoverflow.
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.
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. :)
I have no experience with obj-j & cappuccino, but I wonder; is the `self === aDate' part pure JS? (It seems so).
Because in that case, it will never work. First of all, === is the identity equality operator, which means only if both are the exact same objects will it return `true'. However, even with the value equality operator (==) you cannot compare dates, you will have to compare the values: