Files
Client_Fe/src/lib/format.ts
T
Dhananjaya99 a1b870fa8a first commit
2026-09-28 11:48:14 +05:30

28 lines
751 B
TypeScript

const DISPLAY_LOCALE = "en-LK"
const DISPLAY_TIME_ZONE = "Asia/Colombo"
/** Formatting is explicit so SSR and browser renders produce the same output. */
export function formatCurrency(amount: number) {
return `Rs. ${amount.toLocaleString(DISPLAY_LOCALE)}`
}
export function formatTime(iso: string) {
return new Date(iso).toLocaleTimeString(DISPLAY_LOCALE, {
hour: "numeric",
minute: "2-digit",
timeZone: DISPLAY_TIME_ZONE,
})
}
export function formatDate(iso: string) {
return new Date(iso).toLocaleDateString(DISPLAY_LOCALE, {
month: "short",
day: "numeric",
year: "numeric",
timeZone: DISPLAY_TIME_ZONE,
})
}
export function formatDateTime(iso: string) {
return `${formatDate(iso)}, ${formatTime(iso)}`
}