Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

perf(activity): keep overview date math on plain UTC dates (#9422)

Wolf Mermelsteinddfaf8bfc202
diff --git a/apps/web/package.json b/apps/web/package.json
index 167e9f17fa..957c28f048 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -72,6 +72,7 @@
"@corvu/dialog": "^0.2.4",
"@corvu/drawer": "^0.2.4",
"@date-fns/tz": "^1.4.1",
+ "@date-fns/utc": "^2.1.1",
"@effect/platform-browser": "4.0.0-rc.111",
"@floating-ui/dom": "^1.7.4",
"@fontsource-variable/inter": "^5.2.8",
diff --git a/apps/web/src/features/activity/core/activity-dates.test.ts b/apps/web/src/features/activity/core/activity-dates.test.ts
new file mode 100644
index 0000000000..7d6b364cb2
--- /dev/null
+++ b/apps/web/src/features/activity/core/activity-dates.test.ts
@@ -0,0 +1,82 @@
+import { addDays, eachDayOfInterval, format } from 'date-fns';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import {
+ formatOverviewDate,
+ OVERVIEW_TZ,
+ parseOverviewDate,
+} from './activity-dates';
+import { buildContributionGrid } from './contribution-grid';
+import { placeholderOverview } from './placeholder-overview';
+
+afterEach(() => vi.unstubAllEnvs());
+
+describe('overview calendar dates', () => {
+ it('keeps date arithmetic in UTC across viewer daylight saving changes', () => {
+ const start = parseOverviewDate('2026-03-08');
+ const next = addDays(start, 1);
+ expect(next.getTime() - start.getTime()).toBe(86_400_000);
+ expect(formatOverviewDate(next)).toBe('2026-03-09');
+ expect(format(start, 'EEE, MMM d, yyyy', { in: OVERVIEW_TZ })).toBe(
+ 'Sun, Mar 8, 2026'
+ );
+ });
+
+ it('includes leap day without shifting the server date window', () => {
+ const grid = buildContributionGrid({
+ from: '2024-02-28',
+ to: '2024-03-02',
+ days: [{ date: '2024-02-29', count: 2 }],
+ });
+ expect(grid.weeks.flat().filter((day) => day !== null)).toEqual([
+ { date: '2024-02-28', count: 0, intensity: 0 },
+ { date: '2024-02-29', count: 2, intensity: 4 },
+ { date: '2024-03-01', count: 0, intensity: 0 },
+ ]);
+ });
+});
+
+it.each(['UTC', 'America/New_York', 'Pacific/Auckland'])(
+ 'preserves calendar windows and skeleton length in %s',
+ (zone) => {
+ vi.stubEnv('TZ', zone);
+ for (const dates of [
+ ['2024-02-28', '2024-02-29', '2024-03-01', '2024-03-02'],
+ ['2026-03-07', '2026-03-08', '2026-03-09', '2026-03-10'],
+ ['2026-10-31', '2026-11-01', '2026-11-02', '2026-11-03'],
+ ]) {
+ const from = parseOverviewDate(dates[0]);
+ const last = parseOverviewDate(dates[3]);
+ expect(
+ eachDayOfInterval({ start: from, end: last }, { in: OVERVIEW_TZ }).map(
+ formatOverviewDate
+ )
+ ).toEqual(dates);
+ const grid = buildContributionGrid({
+ from: dates[0],
+ to: formatOverviewDate(addDays(last, 1)),
+ days: [],
+ });
+ expect(
+ grid.weeks.flatMap((week) =>
+ week.flatMap((day) => (day ? [day.date] : []))
+ )
+ ).toEqual(dates);
+ }
+ for (const month of [2, 10]) {
+ const overview = placeholderOverview(new Date(2026, month, 9, 12));
+ expect(
+ (parseOverviewDate(overview.to).getTime() -
+ parseOverviewDate(overview.from).getTime()) /
+ 86_400_000
+ ).toBe(365);
+ expect(overview.to).toBe(month === 2 ? '2026-03-10' : '2026-11-10');
+ }
+ }
+);
+
+it('rejects invalid calendar dates rather than normalizing them into the next month', () => {
+ expect(Number.isNaN(parseOverviewDate('2026-02-30').getTime())).toBe(true);
+ expect(() => formatOverviewDate(parseOverviewDate('2026-02-30'))).toThrow(
+ RangeError
+ );
+});
diff --git a/apps/web/src/features/activity/core/activity-dates.ts b/apps/web/src/features/activity/core/activity-dates.ts
index 3c5be89f40..f74a4c6995 100644
--- a/apps/web/src/features/activity/core/activity-dates.ts
+++ b/apps/web/src/features/activity/core/activity-dates.ts
@@ -1,12 +1,12 @@
-import { tz } from '@date-fns/tz';
+import { utc } from '@date-fns/utc';
import { format, parseISO } from 'date-fns';
/** Calendar dates from the overview are already local `YYYY-MM-DD`. Treat them
* as UTC so `date-fns` never applies a second viewer time zone. */
-export const OVERVIEW_TZ = tz('UTC');
+export const OVERVIEW_TZ = utc;
export function parseOverviewDate(date: string): Date {
- return parseISO(`${date}T00:00:00Z`);
+ return utc(parseISO(`${date}T00:00:00Z`));
}
export function formatOverviewDate(date: Date): string {
diff --git a/bun.lock b/bun.lock
index fff2f17cad..7ceaadcc3b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -57,6 +57,7 @@
"@corvu/dialog": "^0.2.4",
"@corvu/drawer": "^0.2.4",
"@date-fns/tz": "^1.4.1",
+ "@date-fns/utc": "^2.1.1",
"@effect/platform-browser": "4.0.0-rc.111",
"@floating-ui/dom": "^1.7.4",
"@fontsource-variable/inter": "^5.2.8",
@@ -899,6 +900,8 @@
"@date-fns/tz": ["@date-fns/[email protected]", "", {}, "sha512-lwYN/vDPeNRULcepoE/LO2Pgx+7/RV+S9ARfbc9lr2DtGkOD7pAiruHvbR1RX3Qyf6ja47EWJDMsNK5vK08DJg=="],
+ "@date-fns/utc": ["@date-fns/[email protected]", "", {}, "sha512-SlJDfG6RPeEX8wEVv6ZB3kak4MmbtyiI2qX/5zuKdordbrhB/iaJ58GVMZgJ6P1sJaM1gMgENFYYeg1JWrCFrA=="],
+
"@effect/platform-browser": ["@effect/[email protected]", "", { "peerDependencies": { "effect": "^4.0.0-rc.111" } }, "sha512-4SmaYB4zWsmuM82V8Dgida2yupzEWlv6/QoDL2Ogj1jOPq65KUx3VjQKcNn2NenOR6SFRWaWsUWrnxwA2IPFzg=="],
"@emnapi/core": ["@emnapi/[email protected]", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.2", "tslib": "^2.4.0" } }, "sha512-TC8MkTuZUtcTSiFeuC0ksCh9QIJ5+F21MvZ4Wn4ORfYaFJ/0dsiudv5tVkejgwZlwQ39jL9WWDe2lz8x0WglOA=="],
diff --git a/docs/agent-guide/activity.md b/docs/agent-guide/activity.md
index 19e81bf73b..944782cce2 100644
--- a/docs/agent-guide/activity.md
+++ b/docs/agent-guide/activity.md
@@ -44,6 +44,12 @@ reconnecting the websocket, verify recovery without requiring another action.
Hidden tabs defer refresh until visible; purges refresh all mounted activity
queries through the normal access checks.
+Overview dates retain their server calendar day in every viewer timezone. Check
+the year grid, tooltips and streaks across a daylight-saving transition and leap
+day; mounting the same cached overview must not shift or omit a day. The shared
+activity date owner (`activity/core/activity-dates.ts`) uses UTC calendar
+arithmetic, without a timezone lookup per cell; test it in a DST timezone.
+
GitHub-style actions heatmap (one a11y node per day — makes snapshots huge; prefer saving the
snapshot to a file), then a `Most active` section header (styled like the feed's day headers)
over a wrapping row of pill chips (entity icon, name, action count; click opens the entity,
diff --git a/nix-support/node_modules-hashes.json b/nix-support/node_modules-hashes.json
index c1ba977cd7..7c53c56576 100644
--- a/nix-support/node_modules-hashes.json
+++ b/nix-support/node_modules-hashes.json
@@ -1,6 +1,6 @@
{
"nodeModules": {
"aarch64-darwin": "sha256-Yr8MJXW9kkp2gpFoQxI4Or1jEfTRTvHQx47Sqc/vKJM=",
- "x86_64-linux": "sha256-nZmPnf0bY0FvGNhvUx2n/rIwPXRo7L+XJgcu4LSXSLo="
+ "x86_64-linux": "sha256-ZOjZ7sbRJseZxD20EqOMvt+9QUh4O48EOt6ZmGRNiYc="
}
}