From 65c695e8f923c4bbd615f5c94524c6a9f06098a3 Mon Sep 17 00:00:00 2001 From: Alexey Torkhov Date: Tue, 7 Mar 2017 23:51:29 +0400 Subject: [PATCH 1/3] Add faker.date.soon method --- lib/date.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/date.js b/lib/date.js index e1ce7a487..1977137bf 100644 --- a/lib/date.js +++ b/lib/date.js @@ -82,6 +82,26 @@ var _Date = function (faker) { return date; }; + /** + * 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 * @@ -130,4 +150,4 @@ var _Date = function (faker) { }; -module['exports'] = _Date; \ No newline at end of file +module['exports'] = _Date; From 963c3fb05ca278984963f64878da7c6d254c47d1 Mon Sep 17 00:00:00 2001 From: Alexey Torkhov Date: Tue, 7 Mar 2017 23:52:59 +0400 Subject: [PATCH 2/3] Update Readme.md --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index fc23abe54..3ad771383 100644 --- a/Readme.md +++ b/Readme.md @@ -112,6 +112,7 @@ This will interpolate the format string with the value of methods `name.lastName * future * between * recent + * soon * month * weekday * fake From 4ff046152e7d1c3214cda1e1ba62ee9f94e54ae5 Mon Sep 17 00:00:00 2001 From: Alexey Torkhov Date: Tue, 7 Mar 2017 23:55:34 +0400 Subject: [PATCH 3/3] Add test for faker.date.soon --- test/date.unit.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/date.unit.js b/test/date.unit.js index ffbc32012..bd283d07b 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 () {