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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): DST-correct day boundaries + server-authoritative today
Adam Eivy81969db841b0
diff --git a/client/src/pages/Timeline.jsx b/client/src/pages/Timeline.jsxindex 5b34f9929e..fc3d80772e 100644--- a/client/src/pages/Timeline.jsx+++ b/client/src/pages/Timeline.jsx@@ -112,8 +112,11 @@ function EventRow({ event }) {export default function Timeline() {const { date: dateParam } = useParams();const navigate = useNavigate();- const today = localDateStr(new Date());- const date = /^\d{4}-\d{2}-\d{2}$/.test(dateParam || '') ? dateParam : today;+ // Bare /timeline sends NO date — the server defaults to "today" in the USER's+ // configured timezone (which may differ from this browser's). The response+ // carries both the resolved `date` and the server's `today`, so the display+ // and the Today/next-day gates follow the server's day, not the browser's.+ const urlDate = /^\d{4}-\d{2}-\d{2}$/.test(dateParam || '') ? dateParam : null;const [day, setDay] = useState(null);const [loading, setLoading] = useState(true);@@ -121,12 +124,17 @@ export default function Timeline() {useEffect(() => {let active = true;setLoading(true);- api.getTimelineDay({ date, silent: true })+ api.getTimelineDay(urlDate ? { date: urlDate, silent: true } : { silent: true }).then((result) => { if (active) setDay(result); }).catch((err) => { if (active) { setDay(null); toast.error(`Failed to load timeline: ${err.message}`); } }).finally(() => { if (active) setLoading(false); });return () => { active = false; };- }, [date]);+ }, [urlDate]);++ // Browser-local fallbacks cover only the loading/error window before the+ // server response supplies the authoritative `date` and `today`.+ const today = day?.today || localDateStr(new Date());+ const date = day?.date || urlDate || today;const goto = (target) => navigate(target === today ? '/timeline' : `/timeline/${target}`);diff --git a/server/services/humanActivity.db.test.js b/server/services/humanActivity.db.test.jsindex 16e4cc5c01..6adb5a9660 100644--- a/server/services/humanActivity.db.test.js+++ b/server/services/humanActivity.db.test.js@@ -121,6 +121,9 @@ describe.skipIf(!dbReady)('humanActivity store (#2150)', () => {// then sanity-check the summary shape for the same day.const summary = await getDaySummary({ date: '2026-07-04' });expect(summary.date).toBe('2026-07-04');+ // The server's "today" (user-timezone) ships with every summary so the+ // client can gate its Today/next-day controls on the server's day.+ expect(summary.today).toMatch(/^\d{4}-\d{2}-\d{2}$/);expect(summary.histogram).toHaveLength(24);expect(typeof summary.counts.total).toBe('number');expect(summary.counts.bySource).toBeTruthy();diff --git a/server/services/humanActivity.js b/server/services/humanActivity.jsindex eb0146cc21..fc512bbde7 100644--- a/server/services/humanActivity.js+++ b/server/services/humanActivity.js@@ -47,17 +47,36 @@ export function localDayKey(when, timezone) {return `${p.year}-${String(p.month).padStart(2, '0')}-${String(p.day).padStart(2, '0')}`;}+// UTC instant of local midnight for a (y, m, d) calendar date in `timezone`.+// The offset is sampled at the approximate midnight, then the candidate is+// verified with the formatter-based getLocalParts and nudged by the exact+// landed-vs-desired delta (the same DST correction pattern as nextLocalTime in+// lib/timezone.js). getUtcOffsetMs alone is NOT re-sampled at the candidate —+// its toLocaleString round-trip mis-parses ambiguous wall-clock times right at+// a transition, which is exactly when the correction matters.+function localMidnightUtc(y, mo, d, timezone) {+ const approxUtc = new Date(Date.UTC(y, mo - 1, d, 0, 0, 0));+ const offset = getUtcOffsetMs(approxUtc, timezone);+ let t = approxUtc.getTime() - offset;+ const p = getLocalParts(new Date(t), timezone);+ const desired = Date.UTC(y, mo - 1, d);+ const landed = Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute);+ if (landed !== desired) t -= landed - desired;+ return new Date(t);+}+// UTC [start, end) instants that bound a local calendar day (YYYY-MM-DD) in the-// given timezone. Offset is sampled at local midnight; a DST transition mid-day-// shifts the far boundary by ≤1h, which is acceptable for day bucketing.+// given timezone. The end is the NEXT local date's midnight — not start + 24h —+// so DST transition days keep their true 23h/25h length instead of leaking an+// hour into (or dropping an hour from) the neighboring day.export function localDayRangeUtc(dateStr, timezone) {const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(String(dateStr || '').trim());if (!m) return null;const [, y, mo, d] = m.map(Number);- const approxUtc = new Date(Date.UTC(y, mo - 1, d, 0, 0, 0));- const offset = getUtcOffsetMs(approxUtc, timezone);- const start = new Date(approxUtc.getTime() - offset);- const end = new Date(start.getTime() + 24 * 60 * 60 * 1000);+ const start = localMidnightUtc(y, mo, d, timezone);+ // Date.UTC rolls d+1 over month/year boundaries for us.+ const next = new Date(Date.UTC(y, mo - 1, d + 1));+ const end = localMidnightUtc(next.getUTCFullYear(), next.getUTCMonth() + 1, next.getUTCDate(), timezone);return { start, end };}@@ -337,14 +356,19 @@ export async function listEvents({ from, to, source, kind, personId, limit } = {// source/kind tallies. `date` defaults to today in the user's timezone.export async function getDaySummary({ date } = {}) {const timezone = await getUserTimezone();- const day = /^\d{4}-\d{2}-\d{2}$/.test(String(date || '')) ? date : todayInTimezone(timezone);+ // `today` is computed in the USER's configured timezone (not the browser's) and+ // returned so the client can default the bare /timeline route and gate its+ // Today/next-day controls on the server's notion of the current day.+ const today = todayInTimezone(timezone);+ const day = /^\d{4}-\d{2}-\d{2}$/.test(String(date || '')) ? date : today;const range = localDayRangeUtc(day, timezone);- if (!range) return { date: day, timezone, events: [], histogram: hourlyHistogram([], timezone), counts: summarizeCounts([]) };+ if (!range) return { date: day, today, timezone, events: [], histogram: hourlyHistogram([], timezone), counts: summarizeCounts([]) };const events = await listEvents({ from: range.start.toISOString(), to: range.end.toISOString(), limit: 2000 });// listEvents returns newest-first; a day view reads better oldest-first.const ordered = [...events].reverse();return {date: day,+ today,timezone,events: ordered,histogram: hourlyHistogram(ordered, timezone),diff --git a/server/services/humanActivity.test.js b/server/services/humanActivity.test.jsindex 00f366650b..7ef8202304 100644--- a/server/services/humanActivity.test.js+++ b/server/services/humanActivity.test.js@@ -52,6 +52,25 @@ describe('localDayKey / localDayRangeUtc', () => {expect(localDayRangeUtc('not-a-date', 'UTC')).toBeNull();expect(localDayKey('not-a-date', 'UTC')).toBeNull();});+ it('ends at the NEXT local midnight across DST transitions (25h fall-back, 23h spring-forward)', () => {+ // 2026-11-01 America/Los_Angeles: clocks fall back — a 25-hour local day.+ // start = midnight PDT (07:00Z); end = next midnight PST (08:00Z on 11-02).+ const fallBack = localDayRangeUtc('2026-11-01', 'America/Los_Angeles');+ expect(fallBack.start.toISOString()).toBe('2026-11-01T07:00:00.000Z');+ expect(fallBack.end.toISOString()).toBe('2026-11-02T08:00:00.000Z');+ expect(fallBack.end.getTime() - fallBack.start.getTime()).toBe(25 * 60 * 60 * 1000);+ // 2026-03-08 America/Los_Angeles: clocks spring forward — a 23-hour local day.+ const springForward = localDayRangeUtc('2026-03-08', 'America/Los_Angeles');+ expect(springForward.start.toISOString()).toBe('2026-03-08T08:00:00.000Z');+ expect(springForward.end.toISOString()).toBe('2026-03-09T07:00:00.000Z');+ expect(springForward.end.getTime() - springForward.start.getTime()).toBe(23 * 60 * 60 * 1000);+ });+ it('rolls the end boundary over month and year edges', () => {+ const monthEdge = localDayRangeUtc('2026-01-31', 'UTC');+ expect(monthEdge.end.toISOString()).toBe('2026-02-01T00:00:00.000Z');+ const yearEdge = localDayRangeUtc('2026-12-31', 'UTC');+ expect(yearEdge.end.toISOString()).toBe('2027-01-01T00:00:00.000Z');+ });});describe('participant normalization', () => {