Skip to content

Commit

Permalink
Merge pull request #86 from northernv/fix-future-date
Browse files Browse the repository at this point in the history
Ensure Date.future returns a date in the future.
  • Loading branch information
FotoVerite committed Jul 22, 2014
2 parents 40256d5 + aae6d97 commit 503e198
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var date = {
future: function (years, refDate) {
var date = (refDate) ? new Date(Date.parse(refDate)) : new Date();
var future = date.getTime();
future += Faker.random.number(years) * 365 * 3600 * 1000; // some time from now to N years later, in milliseconds
future += Faker.random.number(years) * 365 * 3600 * 1000 + 1000; // some time from now to N years later, in milliseconds
date.setTime(future)

return date.toJSON();
Expand Down
8 changes: 8 additions & 0 deletions test/date.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ describe("date.js", function () {
assert.ok(Date.parse(date) > new Date());
});

it("returns a future date when N = 0", function () {

var refDate = new Date();
var date = Date.parse(Faker.Date.future(0), refDate.toJSON());

assert.ok(date > refDate); // date should be after the date given, but before the current time
});

it("returns a date N years after the date given", function () {

var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
Expand Down

0 comments on commit 503e198

Please sign in to comment.