Timezone Meeting Planner — TypeScript source
One explicit moment, every team timezone: wall-clock rows with weekday and UTC offset, a 9-to-17 business-hours window marker per zone, and the best next meeting starts ranked by how many teammates are awake for them.
This is the TypeScript implementation — the same logic the interactive tool runs, in a shareable, citable form.
// Pure surface of the timezone-converter tool (slug: timezone-converter).
// Everything takes an EXPLICIT ISO instant — never the ambient clock — so the
// Go twin (time/tzdata) and the tests are deterministic across runtimes. Zone
// data comes from Intl (the platform tzdb); older runtimes without
// supportedValuesOf fall back to a fixed common-zone list.
export interface ZoneInfo {
zone: string;
/** Local wall-clock time, HH:mm (24h). */
time: string;
/** Local date, YYYY-MM-DD. */
date: string;
/** Local weekday, long English name. */
weekday: string;
/** Offset from UTC as +HH:mm / -HH:mm. */
offset: string;
/** Offset from UTC in minutes (east positive). */
offsetMinutes: number;
}
export interface MeetingWindow {
/** Inclusive start hour, local (default 9). */
start: number;
/** Exclusive end hour, local (default 17). */
end: number;
}
export interface ZoneStatus {
zone: string;
/** Local hour 0..23 at the instant. */
hour: number;
time: string;
inWindow: boolean;
}
export interface MeetingPlan {
instant: string;
window: Required<MeetingWindow>;
zones: ZoneStatus[];
inWindowCount: number;
/** Fraction of zones inside the window, 0..1. */
score: number;
}
export const FALLBACK_ZONES: readonly string[] = [
'UTC',
'America/Los_Angeles',
'America/Denver',
'America/Chicago',
'America/New_York',
'America/Sao_Paulo',
'Europe/London',
'Europe/Paris',
'Europe/Berlin',
'Europe/Moscow',
'Africa/Cairo',
'Africa/Lagos',
'Africa/Johannesburg',
'Asia/Dubai',
'Asia/Karachi',
'Asia/Kolkata',
'Asia/Dhaka',
'Asia/Bangkok',
'Asia/Shanghai',
'Asia/Singapore',
'Asia/Hong_Kong',
'Asia/Tokyo',
'Asia/Seoul',
'Australia/Sydney',
'Pacific/Auckland',
];
/** All IANA zones from the platform, or the fallback list on old runtimes.
* 'UTC' is always present — Node's supportedValuesOf omits it. */
export function listTimeZones(): string[] {
const supported = (Intl as unknown as { supportedValuesOf?: (k: string) => string[] }).supportedValuesOf;
let zones: string[];
if (typeof supported === 'function') {
try {
zones = supported('timeZone');
} catch {
zones = [...FALLBACK_ZONES];
}
} else {
zones = [...FALLBACK_ZONES];
}
if (!zones.includes('UTC')) zones = ['UTC', ...zones];
return zones.sort();
}
function parts(instant: Date, zone: string): Record<string, string> | null {
try {
const fmt = new Intl.DateTimeFormat('en-CA', {
timeZone: zone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
weekday: 'long',
hourCycle: 'h23',
});
const out: Record<string, string> = {};
for (const p of fmt.formatToParts(instant)) out[p.type] = p.value;
return out;
} catch {
return null; // invalid zone id
}
}
/** Wall-clock info for one zone at an instant. Invalid zone → null. */
export function zoneInfo(iso: string, zone: string): ZoneInfo | null {
const instant = new Date(iso);
if (Number.isNaN(instant.getTime())) return null;
const p = parts(instant, zone);
if (!p) return null;
const asUTC = Date.UTC(Number(p.year), Number(p.month) - 1, Number(p.day), Number(p.hour), Number(p.minute));
const offsetMinutes = Math.round((asUTC - instant.getTime()) / 60000);
const sign = offsetMinutes < 0 ? '-' : '+';
const abs = Math.abs(offsetMinutes);
const hh = String(Math.floor(abs / 60)).padStart(2, '0');
const mm = String(abs % 60).padStart(2, '0');
return {
zone,
time: `${p.hour}:${p.minute}`,
date: `${p.year}-${p.month}-${p.day}`,
weekday: p.weekday,
offset: `${sign}${hh}:${mm}`,
offsetMinutes,
};
}
/** Meeting feasibility at an instant: which zones sit inside local business
* hours. Zones failing to parse are dropped from the result. */
export function meetingPlan(
iso: string,
zones: string[],
window: MeetingWindow = { start: 9, end: 17 },
): MeetingPlan | null {
const instant = new Date(iso);
if (Number.isNaN(instant.getTime())) return null;
const w = { start: window.start, end: window.end };
const statuses: ZoneStatus[] = [];
for (const zone of zones) {
const p = parts(instant, zone);
if (!p) continue; // invalid zone: dropped, not fatal
const hour = Number(p.hour);
statuses.push({ zone, hour, time: `${p.hour}:${p.minute}`, inWindow: hour >= w.start && hour < w.end });
}
const inWindowCount = statuses.filter((s) => s.inWindow).length;
return {
instant: iso,
window: w,
zones: statuses,
inWindowCount,
score: statuses.length === 0 ? 0 : inWindowCount / statuses.length,
};
}
export interface SlotSuggestion {
iso: string;
inWindowCount: number;
score: number;
}
/** Scan forward hourly from the instant for the best meeting starts. Returns
* up to `count` suggestions sorted by score desc, then earliest. */
export function suggestSlots(
iso: string,
zones: string[],
window: MeetingWindow = { start: 9, end: 17 },
count = 3,
hours = 24,
): SlotSuggestion[] {
const start = new Date(iso);
if (Number.isNaN(start.getTime())) return [];
const slots: SlotSuggestion[] = [];
for (let h = 0; h < hours; h++) {
const at = new Date(start.getTime() + h * 3600000);
// toISOString() always re-parses, so the plan here is never null.
const plan = meetingPlan(at.toISOString(), zones, window)!;
if (plan.zones.length === 0) continue;
slots.push({ iso: at.toISOString(), inWindowCount: plan.inWindowCount, score: plan.score });
}
slots.sort((a, b) => b.score - a.score || a.iso.localeCompare(b.iso));
return slots.slice(0, count);
}
Also available in 1 other language
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in several languages — the same contract, ported. Compare all languages side by side →