Timeline · Use cases
Time zone meeting planner
A distributed team, each row shaded with that person's 09:00–17:00 in their own zone and shown in yours. A meeting that sits inside every shaded band suits everyone.
Live demo
Switch the display zone · Move the Global sync until it fits Tokyo too
Fullscreenimport { useMemo, useState } from "react"
import { ProScheduler, toZonedTime } from "@andreisaac/pro-scheduler"
import { dataZone, globalMeetings, globalTeam, workingHours } from "./data/global"
import { Choice, Toolbar, useEvents } from "./kit"
/** The zones a viewer can pick: each member's, by city. */
const zones = globalTeam.map((m) => ({ zone: m.timezone, label: m.city }))
function ZonePicker({ value, onChange }: { value: string; onChange: (zone: string) => void }) {
return (
<Toolbar label="Display time zone">
{zones.map((z) => (
<Choice key={z.zone} active={value === z.zone} onClick={() => onChange(z.zone)}>
{z.label}
</Choice>
))}
</Toolbar>
)
}
export function MeetingPlannerDemo() {
const { events, handlers } = useEvents(() => globalMeetings())
const [zone, setZone] = useState("America/New_York")
// Everyone's 09:00–17:00, in their own zone, shaded in the one shown.
const colors = useMemo(() => workingHours(zone), [zone])
return (
<>
<ZonePicker value={zone} onChange={setZone} />
<ProScheduler
data={events}
resources={globalTeam}
colors={colors}
dataTimezone={dataZone}
displayTimezone={zone}
view={{ timeline: { type: "week", resolutionHorizontal: "hour" } }}
styleConfig={{ unitWidthPx: 34, fitToWidth: false, resourceColWidth: 200 }}
renderResource={(member) => (
<div className="flex flex-col leading-tight">
<span className="text-sm font-medium">{member.name}</span>
<span className="text-xs text-muted-foreground">
{String(member.city)} ·{" "}
{toZonedTime(new Date(), String(member.timezone)).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
})}
</span>
</div>
)}
height={440}
{...handlers}
/>
</>
)
}// data/global.ts — sample data, relative to the current week or month.
import type { SchedulerEvent, SchedulerResource } from "@andreisaac/pro-scheduler"
import { weekStart } from "./studio"
export type Member = SchedulerResource & { id: string; timezone: string; city: string }
export const globalTeam: Member[] = [
{ id: "maya", name: "Maya", city: "San Francisco", timezone: "America/Los_Angeles", color: "#2563eb" },
{ id: "leo", name: "Leo", city: "New York", timezone: "America/New_York", color: "#059669" },
{ id: "ines", name: "Inês", city: "Lisbon", timezone: "Europe/Lisbon", color: "#d97706" },
{ id: "arjun", name: "Arjun", city: "Bengaluru", timezone: "Asia/Kolkata", color: "#7c3aed" },
{ id: "yuki", name: "Yuki", city: "Tokyo", timezone: "Asia/Tokyo", color: "#db2777" },
]
export const dataZone = "America/New_York"
/** "YYYY-MM-DDTHH:MM" for day `day` of this week, at New York time `hour:minute`. */
function ny(base: Date, day: number, hour: number, minute = 0) {
const d = new Date(base.getFullYear(), base.getMonth(), base.getDate() + day)
const p = (n: number) => String(n).padStart(2, "0")
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(hour)}:${p(minute)}`
}
export function globalMeetings(base = weekStart()): SchedulerEvent[] {
return [
{ id: "sync", title: "Global sync", start: ny(base, 0, 8), end: ny(base, 0, 9), resource: ["maya", "leo", "ines", "arjun"], recurring: "FREQ=WEEKLY;BYDAY=MO,TH" },
{ id: "design", title: "Design review", start: ny(base, 1, 11), end: ny(base, 1, 12), resource: ["maya", "leo", "ines"] },
{ id: "apac", title: "APAC handover", start: ny(base, 1, 20), end: ny(base, 1, 20, 30), resource: ["leo", "arjun", "yuki"], recurring: { repeat: "weekly", weekDays: "TU,WE,TH" } },
{ id: "infra", title: "Infra on-call", start: ny(base, 2, 3), end: ny(base, 2, 5), resource: ["arjun", "yuki"] },
{ id: "customer", title: "Customer call", start: ny(base, 3, 13), end: ny(base, 3, 14), resource: ["leo", "maya"] },
{ id: "planning", title: "Quarterly planning", start: ny(base, 4, 9), end: ny(base, 4, 11), resource: ["maya", "leo", "ines", "arjun", "yuki"] },
]
}About this demo
A distributed team, each row shaded with that person's 09:00–17:00 in their own zone and shown in yours. A meeting that sits inside every shaded band suits everyone.
Things to try
- Switch the display zone
- Move the Global sync until it fits Tokyo too
The props behind it are explained in Recurrence, time zones and order.