fix dates
This commit is contained in:
parent
87d2106314
commit
4dac13bcc0
@ -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 = `<tr>
|
||||
${
|
||||
timeslots.map((ts) =>
|
||||
`<th>${
|
||||
weekDayNames[ts.date.getUTCDay()]
|
||||
} ${ts.date.getUTCDate()}. ${
|
||||
monthNames[ts.date.getUTCMonth()]
|
||||
`<th>${utcWeekDayName(ts.date)} ${utcDayOfMonth(ts.date)}. ${
|
||||
utcMonthName(ts.date)
|
||||
}</th>`
|
||||
)
|
||||
.join("")
|
||||
|
Loading…
x
Reference in New Issue
Block a user