Last active
April 11, 2025 16:59
-
-
Save ryzokuken/4f3b856cae68c592e297cdf495816613 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// deno run https://gist.githubusercontent.com/ryzokuken/4f3b856cae68c592e297cdf495816613/raw/3a82c748a6648af518dc9e816f08a3a513d19911/tc39-times.js <date> <timezone> | |
import { Temporal } from "npm:@js-temporal/polyfill"; | |
const startTime = Temporal.PlainTime.from("10:00"); | |
const inputDate = Deno.args[0]; | |
if (inputDate === undefined) throw Error("must provide a start date"); | |
const inputTz = Deno.args[1]; | |
if (inputTz === undefined) throw Error("must provide a meeting timezone"); | |
const startDate = Temporal.PlainDate.from(inputDate); | |
const days = 4; | |
const showTimeZones = [ | |
// CLDR abbreviations are locale specific so we need to provide different locales for the desired short TZ names | |
["America/Los_Angeles", "en-US"], | |
["America/Chicago", "en-US"], | |
["Europe/London", "en-GB"], | |
["Europe/Madrid", "es-ES"], | |
]; | |
const formatOptions = { | |
hour: "2-digit", | |
hour12: false, | |
hourCycle: "h23", | |
minute: "2-digit", | |
}; | |
const baseTime = startDate.toZonedDateTime({ | |
timeZone: inputTz, | |
plainTime: startTime, | |
}); | |
function spans(time, tz) { | |
time = time.withTimeZone(tz); | |
return { | |
am: [time, time.add({ hours: 2 })], | |
pm1: [time.add({ hours: 3 }), time.add({ hours: 5 })], | |
pm2: [time.add({ hours: 5 }), time.add({ hours: 7 })], | |
}; | |
} | |
function formatSpan(span, locale) { | |
return `${ | |
span[0].toLocaleString( | |
locale, | |
formatOptions, | |
) | |
}-${ | |
span[1].toLocaleString(locale, { | |
...formatOptions, | |
timeZoneName: "short", | |
}) | |
}`; | |
} | |
let current = baseTime; | |
const timeRow = []; | |
for (let i = 0; i < days; i++) { | |
let amText = []; | |
let pm1Text = []; | |
let pm2Text = []; | |
for (const zone of showTimeZones) { | |
const [z, l] = zone; | |
const zoneSpans = spans(current, z); | |
amText.push(formatSpan(zoneSpans.am, l)); | |
pm1Text.push(formatSpan(zoneSpans.pm1, l)); | |
pm2Text.push(formatSpan(zoneSpans.pm2, l)); | |
} | |
timeRow.push( | |
current.toPlainDate().toString(), | |
amText.join("\n"), | |
pm1Text.join("\n"), | |
pm2Text.join("\n"), | |
); | |
current = current.add({ days: 1 }); | |
} | |
console.log(timeRow.join("\n\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment