Trying to verify a function which receives millisSinceEpoch and gives back the time if it is today's date, otherwise it gives the date.
getLocaleAbbreviatedDatetimeString: function(millisSinceEpoch) {
var date = new Date(millisSinceEpoch);
if (date.toLocaleDateString() == new Date().toLocaleDateString()) {
// The replace function removes 'seconds' from the returned time.
return date.toLocaleTimeString().replace(/:\d\d /, ' ');
}
return date.toLocaleDateString();
I plan on verifying this by faking the Date() constructor, but I'm uncertain about how to fake a constructor using 'prototype'?
Furthermore, is there an alternate way to validate this ?