diff options
| author | Marak <[email protected]> | 2017-09-08 13:13:55 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-09-08 13:13:55 -0400 |
| commit | 4adcc929c7a063e56704b24b66ca1edc63b4e02a (patch) | |
| tree | 979d48539e3eeda40531a1807e46dc5754cb561c | |
| parent | af953d8f86934e19fd8a0d4ccc7d2a7b5c5d0552 (diff) | |
| parent | 4ff046152e7d1c3214cda1e1ba62ee9f94e54ae5 (diff) | |
| download | faker-4adcc929c7a063e56704b24b66ca1edc63b4e02a.tar.xz faker-4adcc929c7a063e56704b24b66ca1edc63b4e02a.zip | |
Merge pull request #487 from atorkhov/patch-2
[api] Added faker.date.soon
| -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 () { |
