import customParseFormatPlugin from "dayjs/plugin/customParseFormat"; import dayjs from "dayjs"; import timezone from 'dayjs/plugin/timezone'; dayjs.extend(customParseFormatPlugin); dayjs.extend(timezone); export function toLocaleStringForAmount(value: string | number, locale: string): string { if (typeof value === 'number') { return value.toLocaleString(locale); } else if (typeof value === 'string') { const numberValue = +value; if (!isNaN(numberValue)) { return numberValue.toLocaleString(locale); } } return value; } export function toLocaleString(initialValue: string, type: string,serverDateTimeFormat:string, locale: string, timeZone: string, dateTimeFormat: string, dateFormat: string): string { if (type === "amount") { return toLocaleStringForAmount(initialValue, locale); } else if (type?.startsWith("date")) { if (!initialValue) { return initialValue } const formattedDate = dayjs(initialValue, serverDateTimeFormat).tz(timeZone) if (type === "date") { return formattedDate.format(dateFormat); } else if (type === "dateTime") { return formattedDate.format(dateTimeFormat); } } return initialValue; }