Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
import { parseLocalDate } from '@core/util/local-date';
import type { CalendarEvent, CalendarTimeFormat } from '../types';
import { isSameLocalDate, isTimedPointEvent } from './calendar-date';
import { formatCalendarTime } from './time-format';
const formatDate = new Intl.DateTimeFormat(undefined, {
weekday: 'short',
month: 'long',
day: 'numeric',
});
const formatShortDate = new Intl.DateTimeFormat(undefined, {
month: 'short',
day: 'numeric',
});
export function parseCalendarDate(value: string) {
return parseLocalDate(value) ?? new Date(value);
}
export function formatEventSchedule(
event: CalendarEvent,
timeFormat: CalendarTimeFormat
) {
const start = parseCalendarDate(event.start);
const end = parseCalendarDate(event.end);
if (event.allDay) {
const inclusiveEnd = new Date(end);
inclusiveEnd.setDate(inclusiveEnd.getDate() - 1);
return isSameLocalDate(start, inclusiveEnd)
? `${formatDate.format(start)} · All day`
: `${formatShortDate.format(start)}–${formatShortDate.format(inclusiveEnd)} · All day`;
}
if (isTimedPointEvent(event)) {
return `${formatDate.format(start)} · ${formatCalendarTime(start, timeFormat)} · No duration`;
}
return isSameLocalDate(start, end)
? `${formatDate.format(start)} · ${formatCalendarTime(start, timeFormat)}–${formatCalendarTime(end, timeFormat)}`
: `${formatDate.format(start)}, ${formatCalendarTime(start, timeFormat)}–${formatDate.format(end)}, ${formatCalendarTime(end, timeFormat)}`;
}