Back to packages list

Vals using date-fns-tz

Description from the NPM package:
Time zone support for date-fns v3 with the Intl API
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
31
32
import { email } from "https://esm.town/v/std/email?v=9";
import { fetch } from "https://esm.town/v/std/fetch";
export const shitIsMySiteDown = async () => {
const URL = "https://withseismic.com";
const TIMEZONE: string = "UTC";
const { format } = await import("npm:date-fns-tz");
const timestamp = format(new Date(), "dd-MM-yyyy'T'HH:mm:ssXXX", { timeZone: TIMEZONE });
let status = "up";
try {
const response = await fetch(URL);
if (response.status !== 200) {
throw new Error(`status code: ${response.status}`);
}
} catch (error) {
status = "down";
const subject = `Website down alert: ${URL}`;
const body = `As of ${timestamp} (${TIMEZONE}), ${URL} is down. Reason: ${error.message}.`;
// Send email using the updated email function.
await email({
subject: subject,
text: body,
});
} finally {
console.log(`Checked website status at ${timestamp} in TIMEZONE ${TIMEZONE}: ${status}.`);
return { status }
}
};
1
2
3
4
5
6
7
export async function toDatesWithTz(
dateStrings: string[],
timeZone: string,
): Promise<Date[]> {
const { toDate } = await import("npm:date-fns-tz");
return dateStrings.map((s) => toDate(s, { timeZone }));
}
1
Next