Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
fix(date): fix date decode in relaxed mode (#13)
Browse files Browse the repository at this point in the history
Fixes NODE-1446
  • Loading branch information
daprahamian committed May 1, 2018
1 parent a911f8d commit dc416aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/ext_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function deserializeValue(self, key, value, options) {

if (typeof d === 'string') date.setTime(Date.parse(d));
else if (d instanceof BSON.Long) date.setTime(d.toNumber());
else if (typeof d === 'number' && options.relaxed) date.setTime(d);
return date;
}

Expand Down
7 changes: 5 additions & 2 deletions test/extend_mongodb_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ describe('Extended JSON', function() {
});

it('should allow relaxed parsing', function() {
const dt = new Date(1452124800000);
const inputObject = {
int: { $numberInt: '500' },
long: { $numberLong: '42' },
double: { $numberDouble: '24' }
double: { $numberDouble: '24' },
date: { $date: { $numberLong: '1452124800000' } }
};

const parsed = extJSON.parse(JSON.stringify(inputObject), { relaxed: true });
expect(parsed).to.eql({
int: 500,
long: 42,
double: 24
double: 24,
date: dt
});
});
});
Expand Down

0 comments on commit dc416aa

Please sign in to comment.