diff options
| author | Shane A. Stillwell <[email protected]> | 2014-05-21 21:19:04 -0500 |
|---|---|---|
| committer | Shane A. Stillwell <[email protected]> | 2014-05-21 21:19:04 -0500 |
| commit | aae6d9720e77f5f371a865e65eac9cd26626008d (patch) | |
| tree | 24dfefee31b14faa87f7fe5f62b945f2c8a1638a | |
| parent | daa95b3a4f3eb5131970271be3820ddb45d30022 (diff) | |
| download | faker-aae6d9720e77f5f371a865e65eac9cd26626008d.tar.xz faker-aae6d9720e77f5f371a865e65eac9cd26626008d.zip | |
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 795e674e..1b93f4e6 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 83b73ca9..b5481c0f 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) |
