/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/components/chart-uplot/lib/get-date-format.ts
48 строк
1 KB
Marin Atanasov
Components: Move `UplotChart` to client (#99095)
31 янв 2025, 16:12
Не верифицирован
31 янв 2025, 16:12
167214b
Код
Авторство
О чём код?
// because 'en' defaults to the OS variant - replace numeric month with short month to avoid ambiguity const MONTH_FORMAT = 'short'; export default function getDateFormat( template: string, date: Date, locale = 'en' ): string { let newDayMonthFormat; let newYearFormat; switch ( template ) { case '{M}/{D}': // only show day and month in a local format. return date.toLocaleDateString( locale, { month: MONTH_FORMAT, day: 'numeric' } ); case '{M}/{D}\n{YYYY}': // Show day, month and a year in local format. newDayMonthFormat = date.toLocaleDateString( locale, { month: MONTH_FORMAT, day: 'numeric', } ); newYearFormat = date.toLocaleDateString( locale, { year: 'numeric', } ); // add new line to match the format return `${ newDayMonthFormat }\n${ newYearFormat }`; case '{MMM}': // only month return date.toLocaleDateString( locale, { month: MONTH_FORMAT, } ); case '{MMM}\n{YYYY}': // month and year newDayMonthFormat = date.toLocaleDateString( locale, { month: MONTH_FORMAT, } ); newYearFormat = date.toLocaleDateString( locale, { year: 'numeric', } ); // add new line to match the format return `${ newDayMonthFormat }\n${ newYearFormat }`; default: break; } // fallback that shouldn't happen. return date.toLocaleDateString( locale ); }