I got two questions about JavaScript Date objects.
I’ve created two date objects in my code and from all “appearances” they are the same values, yet, a comparison with the equality operator(==) returns the boolean value of false. Here they are as shown in Chrome’s JavaScript console:
beginEditingLastUpdate;
Tue Mar 12 2013 18:10:56 GMT-0500 (Central Daylight Time)
endEditingLastUpdate;
Tue Mar 12 2013 18:10:56 GMT-0500 (Central Daylight Time)
Those were copied’n’pasted right out of the console. So I am confused on this one.
Why do all my Date objects show a protype as “InvalidDate”. I have created date objects by simply calling the Date() constructor and they still have a prototype(actually proto if it matters) of “InvalidDate”. What’s up with this?
My first thought is try logging to the console with beginEditingLastUpdate.getTime() as this will give you a result accurate to the microsecond, instead of the iso-format string which is only displays with an accuracy of one second. I’d say there’s a difference between the two times but it’s less than one second.
I’m not sure why you’re seeing invalid date, however if you’re calling new Date() - ie with the new keyword and no arguments - it would certainly be unusual to see InvalidDate. If you’re calling new Date(some_value) please provide what some_value is.
edit: If you can provide the context of how you’re using yourdate.proto I may be able to better respond to part 2 of your question. As a guess, if you’re checking if an object is a date, try using
yourdate instanceof Date // returns true if yourdate is a Date object