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): anchor all-day events in user tz + render times in user tz
Adam Eivy7cfcc956fa0e
diff --git a/client/src/pages/Timeline.jsx b/client/src/pages/Timeline.jsxindex fc3d80772e..c99a5007ee 100644--- a/client/src/pages/Timeline.jsx+++ b/client/src/pages/Timeline.jsx@@ -79,7 +79,10 @@ function Histogram({ histogram }) {);}-function EventRow({ event }) {+// `timezone` is the server's configured user timezone — event times render in+// it so rows line up with the day window and histogram buckets even when the+// browser is in a different zone (e.g. viewing remotely over Tailscale).+function EventRow({ event, timezone }) {const Icon = kindIcon(event.kind, event.source);const when = new Date(event.happenedAt);const participants = (event.participants || [])@@ -94,7 +97,7 @@ function EventRow({ event }) {</div><div className="min-w-0 flex-1"><div className="flex flex-wrap items-center gap-2">- <span className="font-mono text-xs text-gray-500">{formatClockTime(when)}</span>+ <span className="font-mono text-xs text-gray-500">{formatClockTime(when, { timeZone: timezone })}</span><KindBadge kind={event.kind} /><span className="text-[10px] uppercase tracking-wide text-gray-500">{event.source}</span>{Number.isFinite(event.durationS) && event.durationS > 0 && (@@ -215,7 +218,7 @@ export default function Timeline() {</div>) : (<div className="flex flex-col gap-2 pb-6">- {events.map((event) => <EventRow key={event.id} event={event} />)}+ {events.map((event) => <EventRow key={event.id} event={event} timezone={day?.timezone} />)}</div>)}</div>diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.jsindex 748b45f5f8..fd6d967729 100644--- a/client/src/utils/formatters.js+++ b/client/src/utils/formatters.js@@ -53,10 +53,12 @@ export function formatDateFull(date) {/*** Format a Date as a clock time string with seconds (e.g., "02:30:45 PM")* @param {Date} date - Date object+ * @param {object} [options] - { timeZone } — render in a specific IANA timezone+ * (e.g. the server's configured user timezone) instead of the browser's* @returns {string} Formatted clock time*/-export function formatClockTime(date) {- return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });+export function formatClockTime(date, { timeZone } = {}) {+ return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit', ...(timeZone ? { timeZone } : {}) });}/**diff --git a/server/services/calendarSync.js b/server/services/calendarSync.jsindex d9c504c284..dcc503e124 100644--- a/server/services/calendarSync.js+++ b/server/services/calendarSync.js@@ -2,6 +2,7 @@ import { readdir, unlink } from 'fs/promises';import { join } from 'path';import { atomicWrite, ensureDir, filterBySearch as genericFilterBySearch, PATHS, readJSONFile, safeDate, UUID_RE } from '../lib/fileUtils.js';import { ServerError } from '../lib/errorHandler.js';+import { getUserTimezone } from '../lib/timezone.js';import { getAccount, updateSyncStatus } from './calendarAccounts.js';export const CACHE_DIR = join(PATHS.calendar, 'cache');@@ -305,7 +306,10 @@ export async function logCalendarTouchpoints(accountId, events = []) {// dynamically to keep this hook lazy (mirrors the tribe auto-log path).export async function recordCalendarActivity(account, events = []) {const { calendarActivityCandidates, recordEvents } = await import('./humanActivity.js');- const candidates = calendarActivityCandidates(account, events);+ // The user's configured timezone anchors offset-less values (Google all-day+ // events normalize to "YYYY-MM-DDT00:00:00") so they land on the right local day.+ const timezone = await getUserTimezone();+ const candidates = calendarActivityCandidates(account, events, Date.now(), timezone);if (candidates.length === 0) return { recorded: 0, skipped: 0 };return recordEvents(candidates);}diff --git a/server/services/humanActivity.js b/server/services/humanActivity.jsindex fc512bbde7..14da472c47 100644--- a/server/services/humanActivity.js+++ b/server/services/humanActivity.js@@ -203,22 +203,45 @@ export function messageActivityCandidates(account, messages = []) {return out;}+// Resolve a calendar time value to a UTC instant, interpreting OFFSET-LESS+// values in the given timezone instead of the Node process's OS timezone.+// Google all-day events are normalized to "YYYY-MM-DDT00:00:00" (no offset) —+// `new Date()` would parse that as server-OS-local, so for a user west of UTC+// an all-day July 4 event could land inside July 3's local-day window. Values+// with an explicit offset (Z / ±hh:mm) pass straight through.+export function resolveEventInstant(value, timezone) {+ if (!value) return null;+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;+ const s = String(value).trim();+ const m = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2}))?(?:\.\d+)?)?$/.exec(s);+ if (m && timezone) {+ const [, y, mo, d, hh, mm, ss] = m;+ const midnight = localMidnightUtc(Number(y), Number(mo), Number(d), timezone);+ const dayMs = ((Number(hh) || 0) * 3600 + (Number(mm) || 0) * 60 + (Number(ss) || 0)) * 1000;+ return new Date(midnight.getTime() + dayMs);+ }+ const parsed = new Date(s);+ return Number.isNaN(parsed.getTime()) ? null : parsed;+}+// Map calendar events to activity candidates. Only events that have already// happened (end/start <= now) and weren't declined/cancelled count as activity,-// mirroring the tribe touchpoint gate.-export function calendarActivityCandidates(account, events = [], now = Date.now()) {+// mirroring the tribe touchpoint gate. `timezone` (the user's configured IANA+// zone) anchors offset-less/all-day values; without it they fall back to+// `new Date()` semantics.+export function calendarActivityCandidates(account, events = [], now = Date.now(), timezone = null) {const accountId = account?.id || null;const out = [];for (const event of events || []) {if (event?.isCancelled || event?.myStatus === 'declined') continue;- const startedAt = event.startTime || event.endTime;+ const startedAt = resolveEventInstant(event.startTime, timezone) || resolveEventInstant(event.endTime, timezone);if (!startedAt) continue;- const completedAt = event.endTime || event.startTime;- if (new Date(completedAt).getTime() > now) continue; // not finished yet+ const completedAt = resolveEventInstant(event.endTime, timezone) || startedAt;+ if (completedAt.getTime() > now) continue; // not finished yetconst eventKey = event.externalId || event.id;if (!eventKey) continue;- const start = new Date(event.startTime).getTime();- const end = new Date(event.endTime).getTime();+ const start = resolveEventInstant(event.startTime, timezone)?.getTime();+ const end = resolveEventInstant(event.endTime, timezone)?.getTime();const durationS = Number.isFinite(start) && Number.isFinite(end) && end > start? Math.round((end - start) / 1000): null;@@ -226,7 +249,7 @@ export function calendarActivityCandidates(account, events = [], now = Date.now(source: 'calendar',accountId,kind: 'calendar.event',- happenedAt: startedAt,+ happenedAt: startedAt.toISOString(),durationS,title: event.title || '(untitled event)',summary: shortSummary(event.location || event.description || ''),diff --git a/server/services/humanActivity.test.js b/server/services/humanActivity.test.jsindex 7ef8202304..fc359f0545 100644--- a/server/services/humanActivity.test.js+++ b/server/services/humanActivity.test.js@@ -199,4 +199,21 @@ describe('calendarActivityCandidates', () => {// ends in the future relative to `now`expect(calendarActivityCandidates(account, [{ externalId: 'c', startTime: '2026-07-05T08:00:00Z', endTime: '2026-07-05T08:30:00Z' }], now)).toEqual([]);});+ it('anchors offset-less/all-day values in the user timezone, not the server OS zone', () => {+ // Google all-day events normalize to "YYYY-MM-DDT00:00:00" (no offset). With+ // the user in America/Los_Angeles, midnight July 4 local = 07:00Z — NOT+ // whatever the Node process's OS timezone would parse it as (which could+ // land the event inside July 3's local-day window for users west of UTC).+ const nowLate = new Date('2026-07-06T00:00:00Z').getTime();+ const [c] = calendarActivityCandidates(account, [+ { externalId: 'ad1', title: 'Independence Day', startTime: '2026-07-04T00:00:00', endTime: '2026-07-05T00:00:00', isAllDay: true },+ ], nowLate, 'America/Los_Angeles');+ expect(c.happenedAt).toBe('2026-07-04T07:00:00.000Z');+ expect(c.durationS).toBe(24 * 3600);+ // Values WITH an explicit offset pass straight through untouched.+ const [z] = calendarActivityCandidates(account, [+ { externalId: 'ad2', title: 'Zoomed', startTime: '2026-07-04T09:00:00Z', endTime: '2026-07-04T09:30:00Z' },+ ], nowLate, 'America/Los_Angeles');+ expect(z.happenedAt).toBe('2026-07-04T09:00:00.000Z');+ });});