Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: show off-hour and overnight calendar events accurately

[._.]/ Adam Eivy5036ec6170fb
diff --git a/client/src/components/calendar/DayView.jsx b/client/src/components/calendar/DayView.jsx
index 4d85de4571..09d79b9aad 100644
--- a/client/src/components/calendar/DayView.jsx
+++ b/client/src/components/calendar/DayView.jsx
@@ -4,42 +4,36 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
import ChronotypeOverlay from './ChronotypeOverlay';
-import { buildSubcalendarColorMap, eventChipStyle } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, getEventDayMinutes } from './calendarUtils';
import { formatDateFull, formatHourOfDay } from '../../utils/formatters';
import BrailleSpinner from '../BrailleSpinner';
import { useThemeContext } from '../ThemeContext';
import useUrlParams from '../../hooks/useUrlParams';
-const START_HOUR = 6;
-const END_HOUR = 23;
-const HOURS = Array.from({ length: END_HOUR - START_HOUR }, (_, i) => i + START_HOUR); // 6am to 10pm
+const START_HOUR = 0;
+const END_HOUR = 24;
+const HOURS = Array.from({ length: END_HOUR - START_HOUR }, (_, i) => i + START_HOUR);
const PX_PER_HOUR = 80;
const PX_PER_15MIN = PX_PER_HOUR / 4; // 20px per 15-min block
const START_MINUTES = START_HOUR * 60;
-function getEventMinutes(event) {
- const start = new Date(event.startTime);
- const end = new Date(event.endTime);
- return {
- startMin: start.getHours() * 60 + start.getMinutes(),
- endMin: end.getHours() * 60 + end.getMinutes()
- };
-}
-
-function getEventPosition(event) {
- const { startMin, endMin } = getEventMinutes(event);
+function getEventPosition(event, day) {
+ const { startMin, endMin } = getEventDayMinutes(event, day);
const top = ((startMin - START_MINUTES) / 60) * PX_PER_HOUR;
- const height = Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN);
- return { top: Math.max(top, 0), height };
+ const height = Math.min(
+ Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN),
+ HOURS.length * PX_PER_HOUR - top,
+ );
+ return { top, height };
}
/**
* Assign columns to overlapping events so they render side-by-side.
* Returns a Map of eventKey -> { column, totalColumns }
*/
-function layoutEvents(events) {
+function layoutEvents(events, day) {
const items = events.map(e => {
- const { startMin, endMin } = getEventMinutes(e);
+ const { startMin, endMin } = getEventDayMinutes(e, day);
return { event: e, startMin, endMin: Math.max(endMin, startMin + 15) };
}).sort((a, b) => a.startMin - b.startMin || a.endMin - b.endMin);
@@ -105,7 +99,9 @@ export default function DayView({ accounts }) {
const fetchEvents = useCallback(async () => {
const startDate = date.toISOString();
- const endDate = new Date(date.getTime() + 24 * 60 * 60 * 1000).toISOString();
+ const nextDay = new Date(date);
+ nextDay.setDate(nextDay.getDate() + 1);
+ const endDate = nextDay.toISOString();
const data = await api.getCalendarEvents({ startDate, endDate, limit: 200 }).catch(() => ({ events: [] }));
setEvents(data?.events || []);
setLoading(false);
@@ -134,8 +130,8 @@ export default function DayView({ accounts }) {
};
const allDayEvents = useMemo(() => events.filter(e => e.isAllDay), [events]);
- const timedEvents = useMemo(() => events.filter(e => !e.isAllDay), [events]);
- const layout = useMemo(() => layoutEvents(timedEvents), [timedEvents]);
+ const timedEvents = useMemo(() => events.filter(e => !e.isAllDay && getEventDayMinutes(e, date)), [events, date]);
+ const layout = useMemo(() => layoutEvents(timedEvents, date), [timedEvents, date]);
const colorMap = useMemo(() => buildSubcalendarColorMap(accounts), [accounts]);
const selectedEventKey = searchParams.get('event');
const selectedEvent = events.find((event) => `${event.accountId}:${event.id}` === selectedEventKey) || null;
@@ -221,7 +217,7 @@ export default function DayView({ accounts }) {
<ChronotypeOverlay startHour={START_HOUR} pxPerHour={PX_PER_HOUR} />
{timedEvents.map(event => {
- const { top, height } = getEventPosition(event);
+ const { top, height } = getEventPosition(event, date);
const key = eventKey(event);
const { column, totalColumns } = layout.get(key) || { column: 0, totalColumns: 1 };
const widthPercent = 100 / totalColumns;
@@ -235,7 +231,6 @@ export default function DayView({ accounts }) {
style={{
top,
height,
- minHeight: PX_PER_15MIN,
left: `calc(${leftPercent}% + 2px)`,
width: `calc(${widthPercent}% - 4px)`,
...eventChipStyle(eventColor, theme?.mode)
diff --git a/client/src/components/calendar/WeekView.jsx b/client/src/components/calendar/WeekView.jsx
index 2ebe76bd19..da9b5188a8 100644
--- a/client/src/components/calendar/WeekView.jsx
+++ b/client/src/components/calendar/WeekView.jsx
@@ -4,14 +4,14 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
import ChronotypeOverlay from './ChronotypeOverlay';
-import { buildSubcalendarColorMap, eventChipStyle } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, getEventDayMinutes } from './calendarUtils';
import BrailleSpinner from '../BrailleSpinner';
import { useThemeContext } from '../ThemeContext';
import { formatMonthDay, formatWeekdayShort, formatDateShort, formatHourOfDay } from '../../utils/formatters';
import useUrlParams from '../../hooks/useUrlParams';
-const START_HOUR = 6;
-const END_HOUR = 23;
+const START_HOUR = 0;
+const END_HOUR = 24;
const HOURS = Array.from({ length: END_HOUR - START_HOUR }, (_, i) => i + START_HOUR);
const PX_PER_HOUR = 80;
const PX_PER_15MIN = PX_PER_HOUR / 4; // 20px per 15-min block
@@ -32,29 +32,23 @@ function getWeekDays(weekStart) {
});
}
-function getEventMinutes(event) {
- const start = new Date(event.startTime);
- const end = new Date(event.endTime);
- return {
- startMin: start.getHours() * 60 + start.getMinutes(),
- endMin: end.getHours() * 60 + end.getMinutes()
- };
-}
-
-function getEventPosition(event) {
- const { startMin, endMin } = getEventMinutes(event);
+function getEventPosition(event, day) {
+ const { startMin, endMin } = getEventDayMinutes(event, day);
const top = ((startMin - START_MINUTES) / 60) * PX_PER_HOUR;
- const height = Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN);
- return { top: Math.max(top, 0), height };
+ const height = Math.min(
+ Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN),
+ HOURS.length * PX_PER_HOUR - top,
+ );
+ return { top, height };
}
function eventKey(e) {
return `${e.accountId}-${e.id}`;
}
-function layoutEvents(events) {
+function layoutEvents(events, day) {
const items = events.map(e => {
- const { startMin, endMin } = getEventMinutes(e);
+ const { startMin, endMin } = getEventDayMinutes(e, day);
return { event: e, startMin, endMin: Math.max(endMin, startMin + 15) };
}).sort((a, b) => a.startMin - b.startMin || a.endMin - b.endMin);
@@ -110,7 +104,7 @@ export default function WeekView({ accounts }) {
const [searchParams, updateParams] = useUrlParams();
const { theme } = useThemeContext();
- const weekDays = getWeekDays(weekStart);
+ const weekDays = useMemo(() => getWeekDays(weekStart), [weekStart]);
const weekEnd = new Date(weekStart);
weekEnd.setDate(weekEnd.getDate() + 7);
const weekStartIso = weekStart.toISOString();
@@ -151,10 +145,9 @@ export default function WeekView({ accounts }) {
const selectedEvent = events.find((event) => `${event.accountId}:${event.id}` === selectedEventKey) || null;
// Group events by day
- const eventsByDay = useMemo(() => weekDays.map(day => {
- const dayStr = day.toDateString();
- return events.filter(e => !e.isAllDay && new Date(e.startTime).toDateString() === dayStr);
- }), [events, weekDays]);
+ const eventsByDay = useMemo(() => weekDays.map(day =>
+ events.filter(e => !e.isAllDay && getEventDayMinutes(e, day))
+ ), [events, weekDays]);
const allDayByDay = useMemo(() => weekDays.map(day => {
const dayStr = day.toDateString();
@@ -163,8 +156,8 @@ export default function WeekView({ accounts }) {
// Memoize layouts per day
const layoutsByDay = useMemo(
- () => eventsByDay.map(dayEvents => layoutEvents(dayEvents)),
- [eventsByDay]
+ () => eventsByDay.map((dayEvents, index) => layoutEvents(dayEvents, weekDays[index])),
+ [eventsByDay, weekDays]
);
const now = new Date();
@@ -275,7 +268,7 @@ export default function WeekView({ accounts }) {
return (
<div key={dayIndex} className="flex-1 relative border-l border-port-border/50">
{dayEvents.map(event => {
- const { top, height } = getEventPosition(event);
+ const { top, height } = getEventPosition(event, weekDays[dayIndex]);
const key = eventKey(event);
const { column, totalColumns } = layout.get(key) || { column: 0, totalColumns: 1 };
const widthPercent = 100 / totalColumns;
@@ -289,7 +282,6 @@ export default function WeekView({ accounts }) {
style={{
top,
height,
- minHeight: PX_PER_15MIN,
left: `calc(${leftPercent}% + 1px)`,
width: `calc(${widthPercent}% - 2px)`,
...eventChipStyle(evColor, theme?.mode)
diff --git a/client/src/components/calendar/calendarEventChips.test.jsx b/client/src/components/calendar/calendarEventChips.test.jsx
index 3c349f1ab3..68e95d5779 100644
--- a/client/src/components/calendar/calendarEventChips.test.jsx
+++ b/client/src/components/calendar/calendarEventChips.test.jsx
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
-import { render, screen, cleanup, act } from '@testing-library/react';
+import { render, screen, cleanup, act, fireEvent, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
// One suite for the three views because the thing under test is one contract
@@ -35,9 +35,10 @@ import ChronotypeOverlay from './ChronotypeOverlay';
const SUBCALENDAR_COLOR = '#fbd75b';
const ACCOUNTS = [{ subcalendars: [{ calendarId: 'cal-1', color: SUBCALENDAR_COLOR }] }];
-const at = (hour) => {
+const at = (hour, minute = 0, dayOffset = 0) => {
const d = new Date();
- d.setHours(hour, 0, 0, 0);
+ d.setDate(d.getDate() + dayOffset);
+ d.setHours(hour, minute, 0, 0);
return d.toISOString();
};
@@ -108,7 +109,10 @@ beforeEach(() => {
api.getChronotypeEnergySchedule.mockResolvedValue(null);
});
-afterEach(cleanup);
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
describe.each([
['MonthView', (accounts) => <MonthView accounts={accounts} />, ['Quarter Close']],
@@ -141,6 +145,83 @@ describe.each([
});
});
+describe.each([
+ ['DayView', DayView],
+ ['WeekView', WeekView],
+])('%s full-day event placement', (name, View) => {
+ beforeEach(() => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(new Date(2026, 8, 8, 12));
+ });
+
+ const event = (id, startTime, endTime) => ({ ...TIMED, id, title: id, startTime, endTime });
+ const positions = (title) => screen.queryAllByRole('button', { name: title }).map(chip => ({
+ top: Number.parseFloat(chip.style.top), height: Number.parseFloat(chip.style.height),
+ }));
+ const expectFullDayGrid = () => {
+ const firstRow = screen.getByText('12 AM').closest('[style]');
+ const hourRows = [...firstRow.parentElement.children].filter(row => row.style.height === '80px');
+ expect(hourRows).toHaveLength(24);
+ expect(screen.getByText('11 PM')).toBeInTheDocument();
+ };
+
+ it('keeps all 24 hours when the only event is during ordinary hours', async () => {
+ api.getCalendarEvents.mockResolvedValue({ events: [event('Ordinary meeting', at(10), at(11))] });
+ await renderView(<View accounts={ACCOUNTS} />);
+ expectFullDayGrid();
+ expect(positions('Ordinary meeting')).toEqual([{ top: 800, height: 80 }]);
+ });
+
+ it('positions early and late events inside the grid and opens their details', async () => {
+ api.getCalendarEvents.mockResolvedValue({ events: [
+ event('Early meeting', at(5), at(5, 30)),
+ event('Late meeting', at(23, 30), at(23, 45)),
+ event('Midnight finish', at(22), at(0, 0, 1)),
+ ] });
+ await renderView(<View accounts={ACCOUNTS} />);
+ expectFullDayGrid();
+ expect(positions('Early meeting')).toEqual([{ top: 400, height: 40 }]);
+ expect(positions('Late meeting')).toEqual([{ top: 1880, height: 20 }]);
+ expect(positions('Midnight finish')).toEqual([{ top: 1760, height: 160 }]);
+
+ for (const title of ['Early meeting', 'Late meeting', 'Midnight finish']) {
+ fireEvent.click(chipFor(title));
+ const detail = await screen.findByRole('dialog', { name: title });
+ fireEvent.click(within(detail).getByRole('button', { name: 'Close' }));
+ }
+ });
+
+ it('clips overnight portions to each intersecting day and treats midnight as exclusive', async () => {
+ api.getCalendarEvents.mockResolvedValue({ events: [
+ event('Overnight arrival', at(22, 0, -1), at(1)),
+ event('Overnight departure', at(23), at(2, 0, 1)),
+ event('Already ended', at(23, 0, -1), at(0)),
+ ] });
+ await renderView(<View accounts={ACCOUNTS} />);
+ if (name === 'DayView') {
+ expect(positions('Overnight arrival')).toEqual([{ top: 0, height: 80 }]);
+ expect(positions('Overnight departure')).toEqual([{ top: 1840, height: 80 }]);
+ expect(positions('Already ended')).toEqual([]);
+ } else {
+ expect(positions('Overnight arrival')).toEqual([{ top: 1760, height: 160 }, { top: 0, height: 80 }]);
+ expect(positions('Overnight departure')).toEqual([{ top: 1840, height: 80 }, { top: 0, height: 160 }]);
+ expect(positions('Already ended')).toEqual([{ top: 1840, height: 80 }]);
+ }
+ });
+});
+
+it('requests the next local midnight on a daylight-saving transition day', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(new Date(2026, 2, 8, 12));
+ api.getCalendarEvents.mockResolvedValue({ events: [] });
+ await renderView(<DayView accounts={ACCOUNTS} />);
+ expect(api.getCalendarEvents).toHaveBeenCalledWith({
+ startDate: new Date(2026, 2, 8).toISOString(),
+ endDate: new Date(2026, 2, 9).toISOString(),
+ limit: 200,
+ });
+});
+
describe('ChronotypeOverlay zone labels', () => {
const ZONES = {
zones: [
diff --git a/client/src/components/calendar/calendarUtils.js b/client/src/components/calendar/calendarUtils.js
index 3a3af53b73..7660bb8a9d 100644
--- a/client/src/components/calendar/calendarUtils.js
+++ b/client/src/components/calendar/calendarUtils.js
@@ -1,5 +1,26 @@
import { chipColors } from '../../lib/chipContrast';
+/**
+ * Local clock minutes for the portion of a timed event inside one calendar day.
+ * The next midnight is exclusive and maps to 1440, including on DST days whose
+ * elapsed duration is not 24 hours. A non-intersecting event returns null.
+ */
+export function getEventDayMinutes(event, day) {
+ const start = new Date(event.startTime);
+ const end = new Date(event.endTime);
+ const dayStart = new Date(day);
+ dayStart.setHours(0, 0, 0, 0);
+ const dayEnd = new Date(dayStart);
+ dayEnd.setDate(dayEnd.getDate() + 1);
+ if (![start, end, dayStart].every(date => Number.isFinite(date.getTime()))
+ || end < start || start >= dayEnd || end <= dayStart) return null;
+
+ return {
+ startMin: start <= dayStart ? 0 : start.getHours() * 60 + start.getMinutes(),
+ endMin: end >= dayEnd ? 1440 : end.getHours() * 60 + end.getMinutes(),
+ };
+}
+
/**
* Neutral chip for an event whose subcalendar has no color (or one we can't
* parse). `--port-accent` is a space-separated RGB triple, so it only becomes a