Skip to content

Commit

Permalink
Add default format for dateFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 2, 2020
1 parent d4bdb8c commit db81d17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
15 changes: 4 additions & 11 deletions src/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ function toBase64(str) {
return Buffer.from(str).toString('base64');
}

function formatDate(date, dateFormat) {
if (dateFormat == null) {
return date;
}
return moment(date).format(dateFormat);
}

const fakeFunctions = {
// Address section
zipCode: () => faker.address.zipCode(),
Expand Down Expand Up @@ -86,19 +79,19 @@ const fakeFunctions = {
date: {
args: ['dateFormat', 'dateFrom', 'dateTo'],
func: (dateFormat, dateFrom, dateTo) =>
formatDate(faker.date.between(dateFrom, dateTo), dateFormat),
moment(faker.date.between(dateFrom, dateTo)).format(dateFormat).toString(),
},
pastDate: {
args: ['dateFormat'],
func: (dateFormat) => formatDate(faker.date.past(), dateFormat),
func: (dateFormat) => moment(faker.date.past()).format(dateFormat),
},
futureDate: {
args: ['dateFormat'],
func: (dateFormat) => formatDate(faker.date.future(), dateFormat),
func: (dateFormat) => moment(faker.date.future()).format(dateFormat),
},
recentDate: {
args: ['dateFormat'],
func: (dateFormat) => formatDate(faker.date.recent(), dateFormat),
func: (dateFormat) => moment(faker.date.recent()).format(dateFormat),
},

// Finance section
Expand Down
2 changes: 1 addition & 1 deletion src/fake_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const fakeDefinitionAST = parse(/* GraphQL */ `
"Only for type \`lorem\`"
loremSize: fake__loremSize
"Only for types \`*Date\`. Example value: \`YYYY MM DD\`. [Full Specification](http://momentjs.com/docs/#/displaying/format/)"
dateFormat: String
dateFormat: String = "YYYY-MM-DDTHH:mm:ss[Z]"
"Only for types \`betweenDate\`. Example value: \`1986-11-02\`."
dateFrom: String = "2010-01-01"
"Only for types \`betweenDate\`. Example value: \`2038-01-19\`."
Expand Down

0 comments on commit db81d17

Please sign in to comment.