diff --git a/lib/mixins/property-accessors.html b/lib/mixins/property-accessors.html index fdae8380c3..d8bbec0dfd 100644 --- a/lib/mixins/property-accessors.html +++ b/lib/mixins/property-accessors.html @@ -384,6 +384,7 @@ break; case Date: + value = isNaN(value) ? String(value) : Number(value); outValue = new Date(value); break; diff --git a/test/unit/property-accessors.html b/test/unit/property-accessors.html index 9ceebfbbdb..51b3cd7d0b 100644 --- a/test/unit/property-accessors.html +++ b/test/unit/property-accessors.html @@ -113,6 +113,29 @@ }); }); + suite('testing for deserialization of date', function() { + let date; + + setup(function() { + date = new Date(); + }); + + test('can handle string timestamp', function() { + const deserializedDate = window.XFoo.prototype._deserializeValue(String(date.getTime()), Date); + assert.equal(deserializedDate.getTime(), date.getTime()); + }); + + test('can handle number timestamp', function() { + const deserializedDate = window.XFoo.prototype._deserializeValue(date.getTime(), Date); + assert.equal(deserializedDate.getTime(), date.getTime()); + }); + + test('can handle full date', function() { + const deserializedDate = window.XFoo.prototype._deserializeValue(date.toString(), Date); + assert.equal(deserializedDate.toString(), date.toString()); + }); + }); + });