feat: creats frontend for the project
This commit is contained in:
38
frontend/src/utils/format.ts
Normal file
38
frontend/src/utils/format.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user