Spaces:
Running
Running
Download src/utils/timeFormat.js from hari7775/resume-server: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/utils/timeFormat.js
- Command line
-
hf download hf://spaces/hari7775/resume-server/src/utils/timeFormat.js
-
curl -L -o timeFormat.js https://huggingface.co/spaces/hari7775/resume-server/resolve/main/src/utils/timeFormat.js
1.32 kB
| // Same layout as getFormattedTime() in the RTOS-V2 sketch: "3:07 PM Wed, 15th October 2026". | |
| // Uses the process timezone, which the Dockerfile sets with ENV TZ. | |
| const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | |
| const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; | |
| function getDaySuffix(day) { | |
| if (day >= 11 && day <= 13) return 'th'; | |
| switch (day % 10) { | |
| case 1: return 'st'; | |
| case 2: return 'nd'; | |
| case 3: return 'rd'; | |
| default: return 'th'; | |
| } | |
| } | |
| /** Milliseconds since the epoch -> "3:07 PM Wed, 15th October 2026" ("unknown" if the value is not a valid time) */ | |
| export function formatTime(ms) { | |
| const d = new Date(ms); | |
| if (Number.isNaN(d.getTime())) return 'unknown'; | |
| const hour24 = d.getHours(); | |
| const hour12 = hour24 % 12 === 0 ? 12 : hour24 % 12; | |
| const meridiem = hour24 >= 12 ? 'PM' : 'AM'; | |
| const minute = String(d.getMinutes()).padStart(2, '0'); | |
| const day = d.getDate(); | |
| return `${hour12}:${minute} ${meridiem} ${DAYS[d.getDay()]}, ${day}${getDaySuffix(day)} ${MONTHS[d.getMonth()]} ${d.getFullYear()}`; | |
| } | |
| /** Unix seconds -> same format */ | |
| export function formatUnix(seconds) { | |
| return formatTime(Number(seconds) * 1000); | |
| } | |