39 lines
945 B
TypeScript
39 lines
945 B
TypeScript
const amountFormatter = new Intl.NumberFormat('ru-RU', {
|
|
style: 'currency',
|
|
currency: 'RUB',
|
|
minimumFractionDigits: 2,
|
|
});
|
|
|
|
export function formatAmount(kopecks: number): string {
|
|
return amountFormatter.format(kopecks / 100);
|
|
}
|
|
|
|
const dateFormatter = new Intl.DateTimeFormat('ru-RU', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric',
|
|
});
|
|
|
|
const dateTimeFormatter = new Intl.DateTimeFormat('ru-RU', {
|
|
day: '2-digit',
|
|
month: '2-digit',
|
|
year: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
});
|
|
|
|
export function formatDate(iso: string): string {
|
|
return dateFormatter.format(new Date(iso));
|
|
}
|
|
|
|
export function formatDateTime(iso: string): string {
|
|
return dateTimeFormatter.format(new Date(iso));
|
|
}
|
|
|
|
export function toISODate(date: Date): string {
|
|
const y = date.getFullYear();
|
|
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
const d = String(date.getDate()).padStart(2, '0');
|
|
return `${y}-${m}-${d}`;
|
|
}
|