aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlbuerste <[email protected]>2021-03-02 13:46:53 +0100
committerMarak <[email protected]>2021-03-03 20:14:45 -0500
commitadc8802d093dcee3bf14487f0d3432be77b65b62 (patch)
tree5703e4eabd88cdfe45c3b7c5a0e5b54c9625f057 /lib
parent7ad22c2e2aae2f5e6215bcdb91cf3fd28e727d92 (diff)
downloadfaker-adc8802d093dcee3bf14487f0d3432be77b65b62.tar.xz
faker-adc8802d093dcee3bf14487f0d3432be77b65b62.zip
Issue 1114: new datatypes module
Current status: - moved tests with seeding problem back to random.unit - implemented date method - added datatype module to seed funtion - added tests for date method
Diffstat (limited to 'lib')
-rw-r--r--lib/datatype.js22
-rw-r--r--lib/index.js2
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/datatype.js b/lib/datatype.js
index fba728ab..b7526907 100644
--- a/lib/datatype.js
+++ b/lib/datatype.js
@@ -84,8 +84,26 @@ function Datatype (faker, seed) {
*
* @method faker.datatype.date
*/
- this.date = function () {
- var random = faker.datatype.number({ min: 0, max: 8600000000000000 });
+ this.date = function (options) {
+ if (typeof options === "number") {
+ options = {
+ max: options
+ };
+ }
+
+ var minMax = 8640000000000000;
+
+ options = options || {};
+
+ if (typeof options.min === "undefined" || options.min < minMax*-1) {
+ options.min = new Date().setFullYear(1990, 1, 1);
+ }
+
+ if (typeof options.max === "undefined" || options.max > minMax) {
+ options.max = new Date().setFullYear(2100,1,1);
+ }
+
+ var random = faker.datatype.number(options);
return new Date(random);
};
diff --git a/lib/index.js b/lib/index.js
index 1f2ab0c5..cd1bede3 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -163,7 +163,9 @@ Faker.prototype.setLocale = function (locale) {
Faker.prototype.seed = function(value) {
var Random = require('./random');
+ var Datatype = require('./datatype');
this.seedValue = value;
this.random = new Random(this, this.seedValue);
+ this.datatype = new Datatype(this, this.seedValue);
}
module['exports'] = Faker;