Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { msToIsoDate } from "https://esm.town/v/rwev/msToIsoDate";
import { msDay as msDay2 } from "https://esm.town/v/stevekrouse/msDay?v=1";
export function adjustMsToWeekday(msDay) {
let date = new Date(msDay);
while (date.getDay() == 0 || date.getDay() == 6) {
date = new Date(date.getTime() - msDay2);
}
const adjustedMs = date.getTime();
if (adjustedMs != msDay) {
console.log(
`Adjusted ${msToIsoDate(
msDay
)} to ${msToIsoDate(adjustedMs)}`
);
}
return adjustedMs;
}
October 23, 2023