refactor(helpers): refactor printDate func

This commit is contained in:
Slincnik 2025-01-07 19:37:52 +03:00
parent 26b33e3298
commit b5f20894c3
No known key found for this signature in database

View file

@ -68,16 +68,12 @@ export function randomNum(min = 0, max = 100) {
/** /**
* Formats a date for the specified client and locale. * Formats a date for the specified client and locale.
* *
* @param {Object} client - The client object containing language data.
* @param {string} date - The date to format. * @param {string} date - The date to format.
* @param {string} [format=null] - The date format to use. If not provided, the default format for the client's language will be used. * @param {Intl.LocalesArgument} [locale] - The locale to use for formatting the date.
* @param {string} [locale=client.defaultLanguage.name] - The locale to use for formatting the date.
* @returns {string} The formatted date. * @returns {string} The formatted date.
*/ */
export function printDate(client, date, format = null, locale = client.defaultLanguage.name) { export function printDate(date, locale = "en-US") {
const { format: languageFormat, locale: localeFormat } = client.languages.find(language => language.name === locale); return new Intl.DateTimeFormat(locale).format(date);
if (format === "" || format === null) format = languageFormat;
return new Intl.DateTimeFormat(localeFormat).format(date);
} }
/** /**