4dbd2eb441
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
/**
|
||
* Görüntüleme biçimleri (tr-TR, Europe/Istanbul). Sunucu ve istemci aynı sonucu üretir
|
||
* çünkü yerel ayar ve saat dilimi her zaman açıkça verilir (hydration uyumsuzluğu olmaz).
|
||
*/
|
||
export const LOCALE = "tr-TR";
|
||
export const TIME_ZONE = "Europe/Istanbul";
|
||
|
||
const moneyFmt = new Intl.NumberFormat(LOCALE, { style: "currency", currency: "TRY" });
|
||
|
||
/** Kuruş cinsinden tamsayı tutarı TL olarak biçimlendirir: 125050 → "₺1.250,50". */
|
||
export function formatMoney(amountMinor: number): string {
|
||
if (!Number.isSafeInteger(amountMinor)) {
|
||
throw new TypeError(`amountMinor tamsayı olmalı: ${amountMinor}`);
|
||
}
|
||
return moneyFmt.format(amountMinor / 100);
|
||
}
|
||
|
||
const dateFmt = new Intl.DateTimeFormat(LOCALE, {
|
||
timeZone: TIME_ZONE,
|
||
day: "2-digit",
|
||
month: "2-digit",
|
||
year: "numeric",
|
||
});
|
||
|
||
const dateTimeFmt = new Intl.DateTimeFormat(LOCALE, {
|
||
timeZone: TIME_ZONE,
|
||
day: "2-digit",
|
||
month: "2-digit",
|
||
year: "numeric",
|
||
hour: "2-digit",
|
||
minute: "2-digit",
|
||
});
|
||
|
||
/** UTC tarihi İstanbul saatine göre "dd.MM.yyyy" biçiminde gösterir. */
|
||
export function formatDate(date: Date | string): string {
|
||
return dateFmt.format(new Date(date));
|
||
}
|
||
|
||
/** UTC tarihi İstanbul saatine göre "dd.MM.yyyy HH:mm" biçiminde gösterir. */
|
||
export function formatDateTime(date: Date | string): string {
|
||
return dateTimeFmt.format(new Date(date));
|
||
}
|