Repository navigation
Description
Summary
apps/builder/__tests__/broadcasts-calendar.test.tsx builds every schedulesAt fixture from a UTC instant (new Date("2026-08-31T00:00:00Z")), while BroadcastsCalendar buckets rows by the local calendar day. On a machine whose offset moves those instants across a local day boundary, the rows land in a different cell than the assertions expect and the file fails — 3 tests west of UTC, a different 2 tests at +12.
The component is not at fault. calendar-grid.ts's dayKey is format(date, DAY_KEY_FORMAT) and the cells use getDate() / isSameMonth — local throughout, with no getUTC* or toISOString anywhere in either file. Grouping by the viewer's local day is the correct behaviour: someone in Auckland should see a broadcast on their own calendar day. It is the fixtures that encode an assumption the component never made.
The practical cost is that pnpm test is red for any contributor outside roughly UTC+0…+9, on a file they did not touch. CI does not catch it because GitHub Actions runners are UTC.
This repository already has a convention for exactly this, written down in apps/builder/__tests__/ads-date-key.test.ts — it just is not applied here.
Environment
| Measured against | upstream/main @ 96032013e2313891f816fcf8400412b44cf158a2 |
| How | by running the repository's own test file — not against a deployed instance |
| Command | cd apps/builder && TZ=<zone> pnpm exec vitest run __tests__/broadcasts-calendar.test.tsx |
| Node / pnpm / vitest | v24.11.0 / 10.33.2 / 4.1.8 |
| OS | Darwin 22.6.0 arm64 |
| Date of the runs | 2026-09-11 |
Steps to reproduce
- Check out
96032013e. cd apps/builderTZ=UTC pnpm exec vitest run __tests__/broadcasts-calendar.test.tsx→ passes.TZ=America/New_York pnpm exec vitest run __tests__/broadcasts-calendar.test.tsx
Expected: the same result. Nothing in the file depends on where it runs.
Actual: Tests 3 failed | 24 passed (27).
Evidence
Seven zones, same file, same machine, same commit:
TZ |
Offset | Result |
|---|---|---|
America/Hermosillo |
−07:00 | 3 failed / 24 passed (27) |
America/New_York |
−04:00 | 3 failed / 24 passed |
America/Sao_Paulo |
−03:00 | 3 failed / 24 passed |
UTC |
00:00 | 27 passed |
Europe/Madrid |
+02:00 | 27 passed |
Asia/Tokyo |
+09:00 | 27 passed |
Pacific/Auckland |
+12:00 | 2 failed / 25 passed |
The two sides fail differently, and that matters — it is not one bad constant.
West of UTC, the three failures are all in BroadcastsCalendar month view:
× renders at most 3 chips for 08-31 and the overflow label
AssertionError: expected +0 to be 3 (:359)
× clicking the first chip opens the detail dialog for that row
TypeError: Cannot read properties of undefined (reading 'click') (:379)
× a row with an unknown status renders a chip without a status dot
AssertionError: expected null to be truthy (:444)
At +12, those three pass and two different ones fail, in custom range and day view:
× BroadcastsCalendar custom range > lists day sections sorted, skipping days without rows
× BroadcastsCalendar day view > lists rows sorted by time and opens the dialog on click
AssertionError: expected [ '09:00Earlier' ] to deeply equal [ StringContaining "Earlier", …(1) ]
- Expected
+ Received
- StringContaining "Later",
❯ __tests__/broadcasts-calendar.test.tsx:775:50
❯ __tests__/broadcasts-calendar.test.tsx:1098:50
Note what that says: the Later row does not move, it disappears. Its instant falls on the next local day, outside the range under test, so groupByDay never files it under any rendered day.
The fixtures behind each group are different literals:
| Failing at | Test group | Fixture lines |
|---|---|---|
| negative offsets | month view |
:319 AUG_31, :320 SEP_2, :432 |
| +12 | custom range, day view |
:761-762, :1084-1085 |
| neither (yet) | week view |
:1014-1017 |
week view uses the same UTC-instant pattern but only counts chips across the grid without asserting which cell each lands in, so it does not catch the shift today. Same fragility, weaker assertions.
Where it comes from
The component groups by local day. Nothing in it touches UTC:
$ git show 96032013e:apps/builder/src/features/broadcasts/components/broadcasts-calendar.tsx \
| grep -n 'getUTC\|toISOString\|UTC'
(no matches)
calendar-grid.ts:244-245—dayKeyisformat(date, DAY_KEY_FORMAT), andDAY_KEY_FORMAT = "yyyy-MM-dd"(:31);groupByDay(:248-257) keys every row through it. date-fnsformatreads local getters.broadcasts-calendar.tsx:309—day.getDate();:305,:341,:416—isToday,isSameMonth.calendar-grid.ts:36-95—parseDateParam/parseEndDateParamuseparse()/startOfDay().
The fixtures pin absolute instants instead:
$ git show 96032013e:apps/builder/__tests__/broadcasts-calendar.test.tsx | sed -n '319,320p'
const AUG_31 = new Date("2026-08-31T00:00:00Z")
const SEP_2 = new Date("2026-09-02T00:00:00Z")
At −07:00, 2026-08-31T00:00:00Z is August 30, 17:00 locally, so the chips the test expects on the 31st are filed under the 30th and the 31st counts zero. At +12:00, 2026-09-06T14:00:00Z is September 7 locally, which is why Later leaves the visible range entirely.
$ TZ=Pacific/Auckland node -e "const {format}=require('date-fns'); \
const d=new Date('2026-09-02T14:00:00Z'); \
console.log(d.toISOString(), format(d,'yyyy-MM-dd'), d.getDate())"
2026-09-02T14:00:00.000Z 2026-09-03 3
Why we think this is a defect rather than the intended design
Local-day grouping is deliberate and should stay: a broadcast scheduled for the operator's Monday belongs on their Monday, not on UTC's. The timezone handling in calendar-grid.ts:52 ("today" is a per-zone notion) says as much.
So this is not a request to change the component's semantics. It is that the test file asserts against a different notion of day than the code under test, and the discrepancy only shows up depending on where the suite runs. A test that passes or fails on the runner's location is not testing the component.
Suggested fix
Build the fixtures with the local-time constructor, so fixture and component agree on what day means by construction:
-const AUG_31 = new Date("2026-08-31T00:00:00Z")
-const SEP_2 = new Date("2026-09-02T00:00:00Z")
+const AUG_31 = new Date(2026, 7, 31)
+const SEP_2 = new Date(2026, 8, 2)The schedulesAt literals to convert, all in broadcasts-calendar.test.tsx:
| Line | Now | Becomes |
|---|---|---|
| 319 | new Date("2026-08-31T00:00:00Z") |
new Date(2026, 7, 31) |
| 320 | new Date("2026-09-02T00:00:00Z") |
new Date(2026, 8, 2) |
| 432 | new Date("2026-08-05T00:00:00Z") |
new Date(2026, 7, 5) |
| 761 | new Date("2026-09-06T14:00:00Z") |
new Date(2026, 8, 6, 14, 0) |
| 762 | new Date("2026-08-31T09:00:00Z") |
new Date(2026, 7, 31, 9, 0) |
| 1084 | new Date("2026-09-02T14:00:00Z") |
new Date(2026, 8, 2, 14, 0) |
| 1085 | new Date("2026-09-02T09:00:00Z") |
new Date(2026, 8, 2, 9, 0) |
| 1014-1017 | four …T09:15:00Z … T20:00:00Z |
local equivalents |
The first seven fix the failures above. 1014-1017 fails in none of the offsets we measured, but carries the same pattern; converting it is consistency, not necessity.
This is the convention this repository already chose. apps/builder/__tests__/ads-date-key.test.ts:7-11 says so explicitly, and builds its fixtures with new Date(2026, 7, 11, 0, 0, 0) (:17):
These tests are deliberately TIMEZONE-AGNOSTIC: they must pass on a UTC CI runner AND on a developer machine in any offset. Mutating
process.env.TZinside a test file is unreliable (V8 caches the zone per isolate; Windows ignores it entirely) and leaks into sibling tests in the same worker — so expectations are derived from the runtime offset instead of pinning one.
We considered pinning TZ=UTC in apps/builder/vitest.config.ts and think it is the worse option, for two reasons. It would make fixture and component agree by force, so the suite could no longer catch a real regression where the component started bucketing by UTC — which would be a product bug. And that config is export { default } from "@chatbotx.io/vitest-config/nextjs", the preset for all of apps/builder, so the change would silently alter every other test in the app that depends on local time rather than the one file that has the problem.
Happy to send the patch if you want it.
What we did not verify
- We measured seven zones. Offsets +10 and +11 were not measured, so "passes between UTC+0 and UTC+9" is what we observed, not a proven boundary. Likewise we did not test a half-hour offset (e.g.
Asia/Kolkata) or a DST transition date. - We did not establish that the component is correct in general — only that it is internally consistent about using local time, and that it never calls a UTC getter. Whether its local-day grouping is right for a user whose profile
timezonediffers from their machine's is a separate question we did not look into. - We did not check whether other test files in
apps/buildershare this pattern. This is not searched, not proven absent. - We run on
Darwin arm64; we did not reproduce on Linux or Windows.
Related issues
We searched open and closed issues and PRs for timezone test, broadcasts calendar, and autosave, and found nothing describing this. #1146 (resolve replies-by-date timezone) is a different layer — it resolves IANA zone names for Postgres AT TIME ZONE, not local-vs-UTC in JS Date.
Activity
rawdaymx commentedon Sep 12, 2026
Correction to the suggested fix: converting the fixtures alone is not enough, and we would rather say so than let you find out in review.
We built the patch and ran it. Converting the 11
schedulesAtliterals takes the file from 3 failures west / 2 at +12 down to 1 failure in every zone except UTC — better, but still broken, and now broken in places that used to pass (Europe/Madrid,Asia/Tokyo):The cause is the
useFormattermock at the top of the file (:13-21), which renders throughtoISOString():That is UTC. While the fixtures were also UTC instants the two cancelled out; once a fixture is a local
09:15, the mock prints its UTC projection (07:15at +02:00). The realuseFormatterformats in the viewer's zone, so the mock was the second half of the same mismatch — the file had one foot in each convention.The mock has to move to local as well.
formatfromdate-fnsis already imported in the file:dateTime: (date: Date, options?: Record<string, unknown>) => { if (options?.hour) { - return date.toISOString().slice(11, 16) + return format(date, "HH:mm") } - return date.toISOString().slice(0, 10) + return format(date, "yyyy-MM-dd") }, dateTimeRange: (from: Date, to: Date) => - `${from.toISOString().slice(0, 10)}..${to.toISOString().slice(0, 10)}`, + `${format(from, "yyyy-MM-dd")}..${format(to, "yyyy-MM-dd")}`,With both halves, measured on the same seven zones as the report:
TZAmerica/HermosilloAmerica/New_YorkAmerica/Sao_PauloUTCEurope/MadridAsia/TokyoPacific/AucklandThe patch is 84 lines across that one file, applies cleanly on
be7234b93, and passesultracite check. Say the word and we will open it.test(broadcasts): make calendar tests timezone-independent (#1176)
test(broadcasts): make calendar tests timezone-independent (#1176)