Compare commits
10 Commits
amalia/06-
...
amalia/10-
| Author | SHA1 | Date | |
|---|---|---|---|
| d861a3ea86 | |||
| 2f97ce81e4 | |||
| 3c0a5639b6 | |||
| 3ce650a27d | |||
| 5efb96a92a | |||
| 93ae77d335 | |||
| 0c131b80ef | |||
| 5fd5c15394 | |||
| cb565ba0bd | |||
| 940fa5a5b7 |
File diff suppressed because it is too large
Load Diff
11
src/lib/formatDateTime.ts
Normal file
11
src/lib/formatDateTime.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
function formatDateTime(date: Date) {
|
||||
return new Intl.DateTimeFormat('id-ID', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
day: '2-digit',
|
||||
month: 'short',
|
||||
year: 'numeric',
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
export default formatDateTime
|
||||
38
src/lib/timeAgo.ts
Normal file
38
src/lib/timeAgo.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
function timeAgo(date: Date) {
|
||||
const now = new Date();
|
||||
const d = new Date(date);
|
||||
|
||||
const diffMs = now.getTime() - d.getTime();
|
||||
const seconds = Math.floor(diffMs / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
|
||||
// 🔥 cek apakah masih hari yang sama
|
||||
const isToday =
|
||||
now.getDate() === d.getDate() &&
|
||||
now.getMonth() === d.getMonth() &&
|
||||
now.getFullYear() === d.getFullYear();
|
||||
|
||||
if (isToday) {
|
||||
if (seconds < 60) return `${seconds} detik lalu`;
|
||||
if (minutes < 60) return `${minutes} menit lalu`;
|
||||
return `${hours} jam lalu`;
|
||||
}
|
||||
|
||||
// 🔥 kalau bukan hari ini → tampil tanggal + jam
|
||||
const time = d.toLocaleTimeString("id-ID", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
const datePart = d.toLocaleDateString("id-ID", {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
});
|
||||
|
||||
return `${time} ${datePart}`;
|
||||
}
|
||||
|
||||
|
||||
export default timeAgo
|
||||
Reference in New Issue
Block a user