diff --git a/src/helpers/commons/localeHelper.ts b/src/helpers/commons/localeHelper.ts index a09607437..c38808e82 100644 --- a/src/helpers/commons/localeHelper.ts +++ b/src/helpers/commons/localeHelper.ts @@ -21,6 +21,40 @@ export function formatDate(dateString?: string, format?: string, incomingFormat? else return tmp.format(format || 'L') } +export function formatDateLuxon(dateString: string, format: string, incomingFormat: string) { + const baseLocale = getLocale()?.split('_')[0] ?? fallbackLocale + const dt = DateTime.fromFormat(dateString, incomingFormat, { locale: baseLocale }) + + if (!dt.isValid) { + return null + } + + switch (format) { + case 'LT': + return dt.toLocaleString(DateTime.TIME_SIMPLE) + case 'LTS': + return dt.toLocaleString(DateTime.TIME_WITH_SECONDS) + case 'L': + return dt.toLocaleString(DateTime.DATE_SHORT) + case 'l': + return dt.toLocaleString(DateTime.DATE_SHORT).replace(/^0+/, '') + case 'LL': + return dt.toLocaleString(DateTime.DATE_MED) + case 'll': + return dt.toLocaleString(DateTime.DATE_MED).replace(/(\w{3})/, (match) => match.toUpperCase()) + case 'LLL': + return dt.toLocaleString(DateTime.DATETIME_MED) + case 'lll': + return dt.toLocaleString(DateTime.DATETIME_MED) + case 'LLLL': + return dt.toLocaleString(DateTime.DATETIME_FULL) + case 'llll': + return dt.toLocaleString(DateTime.DATETIME_FULL) + default: + return dt.toLocaleString(DateTime.DATE_SHORT) + } +} + export function formatDateWithLocale(dateString?: string | number, format?: any, keepNull?: boolean): string { if (keepNull && !dateString) return '' let dateToFormat = new Date() diff --git a/src/modules/qbe/qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue b/src/modules/qbe/qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue index d5891b14e..2f8384fb1 100644 --- a/src/modules/qbe/qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue +++ b/src/modules/qbe/qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue @@ -42,7 +42,7 @@