Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix packing of date objects in hashmaps #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ var RJSON = (function() {
return value;
} else if (isArray(value)) {
return encodeArray(value);
} else if (isDate(value)) {
return value.toString();
} else {
return encodeObject(value);
}
Expand Down Expand Up @@ -241,6 +243,10 @@ var RJSON = (function() {
return toString.apply(obj) === '[object Array]';
}

function isDate(val) {
return (val instanceof Date && isNaN(val.valueOf()) === false);
}

return {
pack: pack,
unpack: unpack
Expand Down
3 changes: 3 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ test('Hashmaps', function() {
// but restored document will be fully identical to the original document
testPacked({'test': [{'b': '1', 'a': '1'}, {'b': '2', 'a': '2'}]},
'{"test":[{"a":"1","b":"1"},[2,"2","2"]]}');
dt = new Date()
testPacked({'ts': dt},
'{"ts":"'+ dt.toString() +'"}');

});

Expand Down