diff options
| author | Marak <[email protected]> | 2021-02-11 01:24:16 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-11 01:24:16 -0500 |
| commit | 9c8b3249ffa8412d305bea0522d5754f88f000ae (patch) | |
| tree | 665bb0c281ea8a170e5c8da414aed1b80e75d86b /lib/date.js | |
| parent | 00f18703af6bf46b0435f4cc9ed1838054a79c1c (diff) | |
| parent | 388b6cd8513b3b73daab5278e539f8f6bb600e12 (diff) | |
| download | faker-9c8b3249ffa8412d305bea0522d5754f88f000ae.tar.xz faker-9c8b3249ffa8412d305bea0522d5754f88f000ae.zip | |
Merge branch 'master' into master
Diffstat (limited to 'lib/date.js')
| -rw-r--r-- | lib/date.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/date.js b/lib/date.js index 081ddab5..5a7626b4 100644 --- a/lib/date.js +++ b/lib/date.js @@ -70,6 +70,28 @@ var _Date = function (faker) { return newDate; }; + /** + * betweens + * + * @method faker.date.between + * @param {date} from + * @param {date} to + */ + self.betweens = function (from, to, num) { + if (typeof num == 'undefined') { num = 3; } + var newDates = []; + var fromMilli = Date.parse(from); + var dateOffset = (Date.parse(to) - fromMilli) / ( num + 1 ); + var lastDate = from + for (var i = 0; i < num; i++) { + fromMilli = Date.parse(lastDate); + lastDate = new Date(fromMilli + dateOffset) + newDates.push(lastDate) + } + return newDates; + }; + + /** * recent * |
