Skip to content

Commit

Permalink
New option to submit locale to date filter
Browse files Browse the repository at this point in the history
English is set as the default. For #667.
  • Loading branch information
palewire authored Feb 17, 2021
1 parent aff5c7d commit ca56280
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/filters/date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { format, isDate, parseISO } = require('date-fns');
const localeLookup = require('date-fns/locale');

function dateFilter(value, formatString) {
function dateFilter(value, formatString, locale = 'en') {
if (!formatString) {
throw new Error('A "formatString" must be passed to the date filter');
}
Expand All @@ -14,7 +15,7 @@ function dateFilter(value, formatString) {
// TODO: should we check with isDate again just in case parseISO
// returned an invalid date?

return format(value, formatString);
return format(value, formatString, { locale: localeLookup[locale] });
}

module.exports = { dateFilter };

0 comments on commit ca56280

Please sign in to comment.