Spaces:
Running
Running
File size: 1,315 Bytes
f682f01 72775db f682f01 72775db f682f01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | // 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);
}
|