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" });
|
// .toLocaleTimeString(["en-UK"], { hour: "2-digit", minute: "2-digit" });
|
||||||
|
|
||||||
const weekDayNames = [
|
const weekDayNames = [
|
||||||
|
"Sunday",
|
||||||
"Monday",
|
"Monday",
|
||||||
"Tuesday",
|
"Tuesday",
|
||||||
"Wednesday",
|
"Wednesday",
|
||||||
"Thursday",
|
"Thursday",
|
||||||
"Friday",
|
"Friday",
|
||||||
"Saturday",
|
"Saturday",
|
||||||
"Sunday",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const monthNames = [
|
const monthNames = [
|
||||||
@ -32,29 +32,37 @@ const monthNames = [
|
|||||||
"December",
|
"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() {
|
async function makeScheduleTable() {
|
||||||
const timeslotData = await fetch("timeslots.json")
|
const timeslotData = await fetch("timeslots.json")
|
||||||
.then((res) => res.json());
|
.then((res) => res.json());
|
||||||
|
|
||||||
|
console.log(timeslotData);
|
||||||
|
|
||||||
const timeslots = timeslotData
|
const timeslots = timeslotData
|
||||||
.map(({ date, times }) => ({
|
.map(({ date, times }) => ({
|
||||||
dateString: date,
|
dateString: date,
|
||||||
// yea soo this hack makes the Date UTC
|
date: utcDateFromString(date),
|
||||||
date: new Date(
|
|
||||||
new Date(date).getTime() -
|
|
||||||
new Date().getTimezoneOffset() * 60 * 1000,
|
|
||||||
),
|
|
||||||
times,
|
times,
|
||||||
}))
|
}))
|
||||||
.toSorted((a, b) => a.date.getTime() - b.date.getTime());
|
.toSorted((a, b) => a.date.getTime() - b.date.getTime());
|
||||||
|
|
||||||
|
console.log(timeslots);
|
||||||
|
|
||||||
let tableHtml = `<tr>
|
let tableHtml = `<tr>
|
||||||
${
|
${
|
||||||
timeslots.map((ts) =>
|
timeslots.map((ts) =>
|
||||||
`<th>${
|
`<th>${utcWeekDayName(ts.date)} ${utcDayOfMonth(ts.date)}. ${
|
||||||
weekDayNames[ts.date.getUTCDay()]
|
utcMonthName(ts.date)
|
||||||
} ${ts.date.getUTCDate()}. ${
|
|
||||||
monthNames[ts.date.getUTCMonth()]
|
|
||||||
}</th>`
|
}</th>`
|
||||||
)
|
)
|
||||||
.join("")
|
.join("")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user