diff --git a/src/filters/date.js b/src/filters/date.js index f9fd1e0b2..058c90060 100644 --- a/src/filters/date.js +++ b/src/filters/date.js @@ -20,21 +20,21 @@ export function isValidDate(date) { * Converts a given date to a specific format. * * @param {number|string|Date} date - The date to be formatted. + * @param {Object} opts - Optional parameters to customize the output format. * @returns {string} The formatted date as a string in 'dd/mm/yyyy' format. If the provided date is not valid, an empty string is returned. * * @example * // returns "02/12/2022" * toDateFormat(new Date(2022, 11, 2)); */ -export function toDateFormat(date, locale = 'es-ES') { - if (!isValidDate(date)) { - return ''; - } - return new Date(date).toLocaleDateString(locale, { - year: 'numeric', - month: '2-digit', - day: '2-digit', - }); +export function toDateFormat(date, locale = 'es-ES', opts = {}) { + if (!isValidDate(date)) return ''; + + const format = Object.assign( + { year: 'numeric', month: '2-digit', day: '2-digit' }, + opts + ); + return new Date(date).toLocaleDateString(locale, format); } /**