38 lines
878 B
TypeScript
38 lines
878 B
TypeScript
export const formatTime = (date: Date) => {
|
|
return date.toLocaleTimeString('id-ID', {
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
second: '2-digit',
|
|
});
|
|
};
|
|
|
|
export const formatDate = (date: Date | string | undefined) => {
|
|
if (!date) {
|
|
return '-';
|
|
}
|
|
|
|
const parsedDate = date instanceof Date ? date : new Date(date);
|
|
|
|
if (isNaN(parsedDate.getTime())) {
|
|
return '-';
|
|
}
|
|
|
|
return parsedDate.toLocaleDateString('id-ID', {
|
|
weekday: 'long',
|
|
day: 'numeric',
|
|
month: 'long',
|
|
year: 'numeric',
|
|
});
|
|
};
|
|
export const formatCurrency = (value: number) => {
|
|
return new Intl.NumberFormat('id-ID', {
|
|
style: 'currency',
|
|
currency: 'IDR',
|
|
minimumFractionDigits: 0,
|
|
}).format(value);
|
|
};
|
|
|
|
export const formatNumber = (value: number) => {
|
|
return new Intl.NumberFormat('id-ID').format(value);
|
|
};
|