diff options
| author | Matthew Bergman <[email protected]> | 2014-07-22 16:13:47 -0400 |
|---|---|---|
| committer | Matthew Bergman <[email protected]> | 2014-07-22 16:13:47 -0400 |
| commit | 503e1983a0181191efcc9ba174d2586a778ab06a (patch) | |
| tree | c9f904cfd51a56d64f336ceb7de50e2a9b0440c8 | |
| parent | 40256d5cba2f8dad0e303f4976a15372d45129da (diff) | |
| parent | aae6d9720e77f5f371a865e65eac9cd26626008d (diff) | |
| download | faker-503e1983a0181191efcc9ba174d2586a778ab06a.tar.xz faker-503e1983a0181191efcc9ba174d2586a778ab06a.zip | |
Merge pull request #86 from northernv/fix-future-date
Ensure Date.future returns a date in the future.
| -rw-r--r-- | lib/date.js | 2 | ||||
| -rw-r--r-- | test/date.unit.js | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/date.js b/lib/date.js index 23e0dc58..df2049eb 100644 --- a/lib/date.js +++ b/lib/date.js @@ -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(); diff --git a/test/date.unit.js b/test/date.unit.js index 39f96a79..5f78cd5d 100644 --- a/test/date.unit.js +++ b/test/date.unit.js @@ -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) |
