aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarak <[email protected]>2015-07-21 01:01:12 -0700
committerMarak <[email protected]>2015-07-21 01:01:12 -0700
commiteb23a6ffc3a1a753e20049fb0cee2722b8627264 (patch)
treef03345604887f7f792b5f73735409821147c9d56 /lib
parent662fd808eb78f241aee859ba6011e883a6ca1261 (diff)
parent7e1d18b7b897921e50f810bd7397dcec6f5bd40c (diff)
downloadfaker-eb23a6ffc3a1a753e20049fb0cee2722b8627264.tar.xz
faker-eb23a6ffc3a1a753e20049fb0cee2722b8627264.zip
Merge pull request #251 from mradionov/master
[api] Adding generators: faker.date.month(), faker.date.weekday()
Diffstat (limited to 'lib')
-rw-r--r--lib/date.js34
-rw-r--r--lib/index.js1
-rw-r--r--lib/locales/en/date/index.js4
-rw-r--r--lib/locales/en/date/month.js63
-rw-r--r--lib/locales/en/date/weekday.js43
-rw-r--r--lib/locales/en/index.js1
-rw-r--r--lib/locales/ru/date/index.js4
-rw-r--r--lib/locales/ru/date/month.js59
-rw-r--r--lib/locales/ru/date/weekday.js39
-rw-r--r--lib/locales/ru/index.js1
10 files changed, 248 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;
diff --git a/lib/index.js b/lib/index.js
index 07a0f825..2ebd6028 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -91,6 +91,7 @@ function Faker (opts) {
"finance": ["account_type", "transaction_type", "currency"],
"internet": ["avatar_uri", "domain_suffix", "free_email", "password"],
"commerce": ["color", "department", "product_name", "price", "categories"],
+ "date": ["month", "weekday"],
"title": "",
"separator": ""
};
diff --git a/lib/locales/en/date/index.js b/lib/locales/en/date/index.js
new file mode 100644
index 00000000..8c45d3f6
--- /dev/null
+++ b/lib/locales/en/date/index.js
@@ -0,0 +1,4 @@
+var date = {};
+module["exports"] = date;
+date.month = require("./month");
+date.weekday = require("./weekday");
diff --git a/lib/locales/en/date/month.js b/lib/locales/en/date/month.js
new file mode 100644
index 00000000..14416723
--- /dev/null
+++ b/lib/locales/en/date/month.js
@@ -0,0 +1,63 @@
+// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1799
+module["exports"] = {
+ wide: [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December"
+ ],
+ // Property "wide_context" is optional, if not set then "wide" will be used instead
+ // It is used to specify a word in context, which may differ from a stand-alone word
+ wide_context: [
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December"
+ ],
+ abbr: [
+ "Jan",
+ "Feb",
+ "Mar",
+ "Apr",
+ "May",
+ "Jun",
+ "Jul",
+ "Aug",
+ "Sep",
+ "Oct",
+ "Nov",
+ "Dec"
+ ],
+ // Property "abbr_context" is optional, if not set then "abbr" will be used instead
+ // It is used to specify a word in context, which may differ from a stand-alone word
+ abbr_context: [
+ "Jan",
+ "Feb",
+ "Mar",
+ "Apr",
+ "May",
+ "Jun",
+ "Jul",
+ "Aug",
+ "Sep",
+ "Oct",
+ "Nov",
+ "Dec"
+ ]
+};
diff --git a/lib/locales/en/date/weekday.js b/lib/locales/en/date/weekday.js
new file mode 100644
index 00000000..f16cb0bf
--- /dev/null
+++ b/lib/locales/en/date/weekday.js
@@ -0,0 +1,43 @@
+// Source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/en.xml#L1847
+module["exports"] = {
+ wide: [
+ "Sunday",
+ "Monday",
+ "Tuesday",
+ "Wednesday",
+ "Thursday",
+ "Friday",
+ "Saturday"
+ ],
+ // Property "wide_context" is optional, if not set then "wide" will be used instead
+ // It is used to specify a word in context, which may differ from a stand-alone word
+ wide_context: [
+ "Sunday",
+ "Monday",
+ "Tuesday",
+ "Wednesday",
+ "Thursday",
+ "Friday",
+ "Saturday"
+ ],
+ abbr: [
+ "Sun",
+ "Mon",
+ "Tue",
+ "Wed",
+ "Thu",
+ "Fri",
+ "Sat"
+ ],
+ // Property "abbr_context" is optional, if not set then "abbr" will be used instead
+ // It is used to specify a word in context, which may differ from a stand-alone word
+ abbr_context: [
+ "Sun",
+ "Mon",
+ "Tue",
+ "Wed",
+ "Thu",
+ "Fri",
+ "Sat"
+ ]
+};
diff --git a/lib/locales/en/index.js b/lib/locales/en/index.js
index e66d19a7..95708a0b 100644
--- a/lib/locales/en/index.js
+++ b/lib/locales/en/index.js
@@ -16,3 +16,4 @@ en.team = require("./team");
en.hacker = require("./hacker");
en.app = require("./app");
en.finance = require("./finance");
+en.date = require("./date");
diff --git a/lib/locales/ru/date/index.js b/lib/locales/ru/date/index.js
new file mode 100644
index 00000000..8c45d3f6
--- /dev/null
+++ b/lib/locales/ru/date/index.js
@@ -0,0 +1,4 @@
+var date = {};
+module["exports"] = date;
+date.month = require("./month");
+date.weekday = require("./weekday");
diff --git a/lib/locales/ru/date/month.js b/lib/locales/ru/date/month.js
new file mode 100644
index 00000000..5deda00c
--- /dev/null
+++ b/lib/locales/ru/date/month.js
@@ -0,0 +1,59 @@
+// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1734
+module["exports"] = {
+ wide: [
+ "январь",
+ "февраль",
+ "март",
+ "апрель",
+ "май",
+ "июнь",
+ "июль",
+ "август",
+ "сентябрь",
+ "октябрь",
+ "ноябрь",
+ "декабрь"
+ ],
+ wide_context: [
+ "января",
+ "февраля",
+ "марта",
+ "апреля",
+ "мая",
+ "июня",
+ "июля",
+ "августа",
+ "сентября",
+ "октября",
+ "ноября",
+ "декабря"
+ ],
+ abbr: [
+ "янв.",
+ "февр.",
+ "март",
+ "апр.",
+ "май",
+ "июнь",
+ "июль",
+ "авг.",
+ "сент.",
+ "окт.",
+ "нояб.",
+ "дек."
+ ],
+ abbr_context: [
+ "янв.",
+ "февр.",
+ "марта",
+ "апр.",
+ "мая",
+ "июня",
+ "июля",
+ "авг.",
+ "сент.",
+ "окт.",
+ "нояб.",
+ "дек."
+ ]
+};
diff --git a/lib/locales/ru/date/weekday.js b/lib/locales/ru/date/weekday.js
new file mode 100644
index 00000000..fc91073e
--- /dev/null
+++ b/lib/locales/ru/date/weekday.js
@@ -0,0 +1,39 @@
+// source: http://unicode.org/cldr/trac/browser/tags/release-27/common/main/ru.xml#L1825
+module["exports"] = {
+ wide: [
+ "Воскресенье",
+ "Понедельник",
+ "Вторник",
+ "Среда",
+ "Четверг",
+ "Пятница",
+ "Суббота"
+ ],
+ wide_context: [
+ "воскресенье",
+ "понедельник",
+ "вторник",
+ "среда",
+ "четверг",
+ "пятница",
+ "суббота"
+ ],
+ abbr: [
+ "Вс",
+ "Пн",
+ "Вт",
+ "Ср",
+ "Чт",
+ "Пт",
+ "Сб"
+ ],
+ abbr_context: [
+ "вс",
+ "пн",
+ "вт",
+ "ср",
+ "чт",
+ "пт",
+ "сб"
+ ]
+};
diff --git a/lib/locales/ru/index.js b/lib/locales/ru/index.js
index c822cf0e..9c2d7660 100644
--- a/lib/locales/ru/index.js
+++ b/lib/locales/ru/index.js
@@ -8,3 +8,4 @@ ru.name = require("./name");
ru.phone_number = require("./phone_number");
ru.commerce = require("./commerce");
ru.company = require("./company");
+ru.date = require("./date");