diff options
| -rw-r--r-- | Readme.md | 1 | ||||
| -rw-r--r-- | lib/date.js | 22 | ||||
| -rw-r--r-- | test/date.unit.js | 10 |
3 files changed, 32 insertions, 1 deletions
@@ -112,6 +112,7 @@ This will interpolate the format string with the value of methods `name.lastName * future * between * recent + * soon * month * weekday * fake diff --git a/lib/date.js b/lib/date.js index e1ce7a48..1977137b 100644 --- a/lib/date.js +++ b/lib/date.js @@ -83,6 +83,26 @@ var _Date = function (faker) { }; /** + * soon + * + * @method faker.date.soon + * @param {number} days + */ + self.soon = function (days) { + var date = new Date(); + var range = { + min: 1000, + max: (days || 1) * 24 * 3600 * 1000 + }; + + var future = date.getTime(); + future += faker.random.number(range); // some time from now to N days later, in milliseconds + date.setTime(future); + + return date; + }; + + /** * month * * @method faker.date.month @@ -130,4 +150,4 @@ var _Date = function (faker) { }; -module['exports'] = _Date;
\ No newline at end of file +module['exports'] = _Date; diff --git a/test/date.unit.js b/test/date.unit.js index ffbc3201..bd283d07 100644 --- a/test/date.unit.js +++ b/test/date.unit.js @@ -67,6 +67,16 @@ describe("date.js", function () { }); + describe("soon()", function () { + it("returns a date N days into the future", function () { + + var date = faker.date.soon(30); + + assert.ok(date >= new Date()); + }); + + }); + describe("between()", function () { it("returns a random date between the dates given", function () { |
