Public
Script
December 19, 2023
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
import { weekRange as weekRange2 } from "https://esm.town/v/andreterron/weekRange";
import { workedOutByDay } from "https://esm.town/v/andreterron/workedOutByDay";
import { addDays, format } from "npm:date-fns@2.30.0";
import { formatInTimeZone, utcToZonedTime } from "npm:date-fns-tz@2.0.0";
export const workoutDays = async (
byDay: Record<string, any>,
timezone: string = "America/Los_Angeles",
) => {
const todayKey = formatInTimeZone(
new Date(),
timezone,
"yyyy-MM-dd",
);
const weekRange = await weekRange2();
return weekRange.map((day) => {
const key = format(day, "yyyy-MM-dd");
const previousKey = format(addDays(day, -1), "yyyy-MM-dd");
const workedOut = !!byDay[key];
const past = key < todayKey;
return {
day: key,
workedOut,
// Timezones are hard, so we compare strings
past,
today: key === todayKey,
failed: past && !workedOut && !byDay[previousKey],
};
});
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 19, 2023