Download src/utils/formatDate.js from TA-PangandaranAI/PangandaranAI_FE: direct link, hf CLI and curl.
- Browser
- Download file 978 Bytes
-
https://huggingface.co/spaces/TA-PangandaranAI/PangandaranAI_FE/resolve/main/src/utils/formatDate.js
- Command line
-
hf download hf://spaces/TA-PangandaranAI/PangandaranAI_FE/src/utils/formatDate.js
-
curl -L -o formatDate.js https://huggingface.co/spaces/TA-PangandaranAI/PangandaranAI_FE/resolve/main/src/utils/formatDate.js
978 Bytes
| /** | |
| * Date formatting helpers | |
| */ | |
| export function formatTimestamp(isoString) { | |
| const date = new Date(isoString); | |
| return date.toLocaleTimeString('id-ID', { | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| }); | |
| } | |
| export function formatDate(isoString) { | |
| const date = new Date(isoString); | |
| return date.toLocaleDateString('id-ID', { | |
| day: '2-digit', | |
| month: 'long', | |
| year: 'numeric', | |
| }); | |
| } | |
| export function formatRelativeDate(isoString) { | |
| const date = new Date(isoString); | |
| const now = new Date(); | |
| const diffMs = now - date; | |
| const diffMins = Math.floor(diffMs / 60000); | |
| const diffHours = Math.floor(diffMs / 3600000); | |
| const diffDays = Math.floor(diffMs / 86400000); | |
| if (diffMins < 1) return 'Baru saja'; | |
| if (diffMins < 60) return `${diffMins} menit lalu`; | |
| if (diffHours < 24) return `${diffHours} jam lalu`; | |
| if (diffDays < 7) return `${diffDays} hari lalu`; | |
| return formatDate(isoString); | |
| } | |