fix(admin): use local time for schedule minimum#2223
Conversation
🦋 Changeset detectedLatest commit: 0db4000 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
This is the right change for the stated problem. The bug is real: <input type="datetime-local"> interprets min as local wall time, but the code was feeding it a UTC wall-time string, which pushed the effective minimum into the future for operators west of UTC. The fix — subtract the timezone offset and slice the local ISO string — is the standard, idiomatic trick for this input type, and the change is appropriately scoped to the admin panel.
I checked the component change, the new regression test, the changeset, and AGENTS.md conventions. There are no backend/SQL/API, authorization, i18n, or RTL concerns in this diff. The changeset is well written.
The one real issue is in the new test: the assertion about the submitted ISO string is tautological with respect to the timezone scenario it claims to cover. The mock of Date.prototype.getTimezoneOffset only affects formatDatetimeLocalValue, not the new Date(scheduleDate).toISOString() path used by handleScheduleSubmit, and the expected value is computed with that same new Date(string).toISOString() call in the test runner's host timezone. That means the assertion will pass even if the UTC conversion were wrong for a UTC-4 operator. The min attribute and checkValidity() assertions are meaningful; the onSchedule assertion here gives false confidence.
| expect((scheduleInput.element() as HTMLInputElement).checkValidity()).toBe(true); | ||
|
|
||
| await screen.getByRole("button", { name: "Schedule" }).click(); | ||
| expect(onSchedule).toHaveBeenCalledWith(new Date("2026-07-23T12:30").toISOString()); |
There was a problem hiding this comment.
[needs fixing] This assertion claims to verify "submitted ISO conversion" for a UTC-4 operator, but it computes the expected value with the exact same new Date(string).toISOString() path the component uses, and the mocked getTimezoneOffset is never consulted by handleScheduleSubmit. The expected and actual values are therefore guaranteed to match in the test runner's host timezone regardless of whether the UTC conversion is correct for the mocked offset. The earlier min and checkValidity() assertions are the real regression test for this PR; this one is misleading. Drop the tautological toHaveBeenCalledWith assertion or replace it with a non-tautological check.
| expect(onSchedule).toHaveBeenCalledWith(new Date("2026-07-23T12:30").toISOString()); | |
| await screen.getByRole("button", { name: "Schedule" }).click(); | |
| expect(onSchedule).toHaveBeenCalled(); |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
|
Closing at the author's request. This upstream submission was opened without the repository owner's explicit approval. |
What does this PR do?
Fixes the scheduling control's
datetime-localminimum so it is generated from the operator's local wall time instead of UTC wall time. Operators in negative UTC offsets can schedule content in the near future, while submission still converts the selected local value to the correct ISO instant. A Toronto UTC-4 regression covers browser validity and submitted conversion.Closes #
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
ContentSettingsPaneltests: 19/19 passed.RegistryPluginDetailimplicit-any error outside this diff.@emdash-cms/admin.