diff options
| author | Michael Radionov <[email protected]> | 2015-07-18 14:38:12 +0300 |
|---|---|---|
| committer | Michael Radionov <[email protected]> | 2015-07-18 14:38:12 +0300 |
| commit | 7e1d18b7b897921e50f810bd7397dcec6f5bd40c (patch) | |
| tree | f03345604887f7f792b5f73735409821147c9d56 /lib/date.js | |
| parent | 662fd808eb78f241aee859ba6011e883a6ca1261 (diff) | |
| download | faker-7e1d18b7b897921e50f810bd7397dcec6f5bd40c.tar.xz faker-7e1d18b7b897921e50f810bd7397dcec6f5bd40c.zip | |
Adding generators: faker.date.month(), faker.date.weekday()
Diffstat (limited to 'lib/date.js')
| -rw-r--r-- | lib/date.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/date.js b/lib/date.js index e868580d..2c53a4e4 100644 --- a/lib/date.js +++ b/lib/date.js @@ -49,7 +49,39 @@ var _Date = function (faker) { date.setTime(future); return date; - } + }; + + self.month = function (options) { + options = options || {}; + + var type = 'wide'; + if (options.abbr) { + type = 'abbr'; + } + if (options.context && typeof faker.definitions.date.month[type + '_context'] !== 'undefined') { + type += '_context'; + } + + var source = faker.definitions.date.month[type]; + + return faker.random.arrayElement(source); + }; + + self.weekday = function (options) { + options = options || {}; + + var type = 'wide'; + if (options.abbr) { + type = 'abbr'; + } + if (options.context && typeof faker.definitions.date.weekday[type + '_context'] !== 'undefined') { + type += '_context'; + } + + var source = faker.definitions.date.weekday[type]; + + return faker.random.arrayElement(source); + }; return self; |
