Skip to content

Commit

Permalink
Merge branch 'deserialization-date'
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Dec 3, 2017
2 parents 0c185b5 + 2191572 commit 1fbb504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mixins/property-accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
break;

case Date:
value = isNaN(value) ? String(value) : Number(value);
outValue = new Date(value);
break;

Expand Down
23 changes: 23 additions & 0 deletions test/unit/property-accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});

});

</script>
Expand Down

0 comments on commit 1fbb504

Please sign in to comment.