Add: - types/type-notification-category.ts Fix: - app/(application)/(user)/notifications/index.tsx - app/(application)/(user)/test-notifications.tsx - app/(application)/admin/notification/index.tsx - components/Notification/NotificationInitializer.tsx - hooks/use-notification-store.tsx - service/api-notifications.ts - utils/formatChatTime.ts ### No Issue
36 lines
1000 B
TypeScript
36 lines
1000 B
TypeScript
// utils/formatChatTime.ts
|
|
import dayjs from 'dayjs';
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
import 'dayjs/locale/id';
|
|
|
|
dayjs.extend(relativeTime);
|
|
dayjs.locale('id');
|
|
|
|
/**
|
|
* Format waktu pesan untuk tampilan chat
|
|
* @param date ISO string atau Date object
|
|
* @returns string formatted time
|
|
*/
|
|
export const formatChatTime = (date: string | Date): string => {
|
|
const messageDate = dayjs(date);
|
|
const now = dayjs();
|
|
|
|
// Jika hari ini
|
|
if (messageDate.isSame(now, 'day')) {
|
|
return messageDate.format('HH:mm'); // contoh: "14.30"
|
|
}
|
|
|
|
// Jika kemarin
|
|
if (messageDate.isSame(now.subtract(1, 'day'), 'day')) {
|
|
return messageDate.format('dddd HH:mm');
|
|
}
|
|
|
|
// Jika dalam 7 hari terakhir (tapi bukan kemarin/ hari ini)
|
|
if (now.diff(messageDate, 'day') < 7) {
|
|
return messageDate.format('dddd HH:mm'); // contoh: "Senin 14:30"
|
|
}
|
|
|
|
// Lebih dari seminggu lalu → tampilkan tanggal
|
|
return messageDate.format('D MMM YYYY HH:mm'); // contoh: "12 Mei 2024 14:30"
|
|
};
|