diff --git a/public/index.js b/public/index.js index d3d0f36..7fed8a1 100644 --- a/public/index.js +++ b/public/index.js @@ -8,13 +8,13 @@ timeUtcSpan.innerText = new Date() // .toLocaleTimeString(["en-UK"], { hour: "2-digit", minute: "2-digit" }); const weekDayNames = [ + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", - "Sunday", ]; const monthNames = [ @@ -32,29 +32,37 @@ const monthNames = [ "December", ]; +const utcWeekDayName = (utcDate) => weekDayNames[utcDate.getUTCDay()]; +const utcDayOfMonth = (utcDate) => utcDate.getUTCDate(); +const utcMonthName = (utcDate) => monthNames[utcDate.getUTCMonth()]; + +const utcDateFromString = (dateString) => + new Date( + new Date(dateString).getTime() - + new Date().getTimezoneOffset() * 60 * 1000, + ); + async function makeScheduleTable() { const timeslotData = await fetch("timeslots.json") .then((res) => res.json()); + console.log(timeslotData); + const timeslots = timeslotData .map(({ date, times }) => ({ dateString: date, - // yea soo this hack makes the Date UTC - date: new Date( - new Date(date).getTime() - - new Date().getTimezoneOffset() * 60 * 1000, - ), + date: utcDateFromString(date), times, })) .toSorted((a, b) => a.date.getTime() - b.date.getTime()); + console.log(timeslots); + let tableHtml = `