Skip to content

Commit db81d17

Browse files
committed
Add default format for dateFormat
1 parent d4bdb8c commit db81d17

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/fake.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ function toBase64(str) {
2222
return Buffer.from(str).toString('base64');
2323
}
2424

25-
function formatDate(date, dateFormat) {
26-
if (dateFormat == null) {
27-
return date;
28-
}
29-
return moment(date).format(dateFormat);
30-
}
31-
3225
const fakeFunctions = {
3326
// Address section
3427
zipCode: () => faker.address.zipCode(),
@@ -86,19 +79,19 @@ const fakeFunctions = {
8679
date: {
8780
args: ['dateFormat', 'dateFrom', 'dateTo'],
8881
func: (dateFormat, dateFrom, dateTo) =>
89-
formatDate(faker.date.between(dateFrom, dateTo), dateFormat),
82+
moment(faker.date.between(dateFrom, dateTo)).format(dateFormat).toString(),
9083
},
9184
pastDate: {
9285
args: ['dateFormat'],
93-
func: (dateFormat) => formatDate(faker.date.past(), dateFormat),
86+
func: (dateFormat) => moment(faker.date.past()).format(dateFormat),
9487
},
9588
futureDate: {
9689
args: ['dateFormat'],
97-
func: (dateFormat) => formatDate(faker.date.future(), dateFormat),
90+
func: (dateFormat) => moment(faker.date.future()).format(dateFormat),
9891
},
9992
recentDate: {
10093
args: ['dateFormat'],
101-
func: (dateFormat) => formatDate(faker.date.recent(), dateFormat),
94+
func: (dateFormat) => moment(faker.date.recent()).format(dateFormat),
10295
},
10396

10497
// Finance section

src/fake_definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const fakeDefinitionAST = parse(/* GraphQL */ `
195195
"Only for type \`lorem\`"
196196
loremSize: fake__loremSize
197197
"Only for types \`*Date\`. Example value: \`YYYY MM DD\`. [Full Specification](http://momentjs.com/docs/#/displaying/format/)"
198-
dateFormat: String
198+
dateFormat: String = "YYYY-MM-DDTHH:mm:ss[Z]"
199199
"Only for types \`betweenDate\`. Example value: \`1986-11-02\`."
200200
dateFrom: String = "2010-01-01"
201201
"Only for types \`betweenDate\`. Example value: \`2038-01-19\`."

0 commit comments

Comments
 (0)