Fix date format example in reading settings#1352
Conversation
🦋 Changeset detectedLatest commit: 880e564 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 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 ✍️ ✅ |
0362dd5 to
e37a31b
Compare
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
There was a problem hiding this comment.
Approach
This is a small, well-scoped bug fix and the approach is sound. The Reading settings "Date Format" example was hard-coded to January 23, 2026 regardless of the configured format string — genuinely misleading, since e.g. yyyy-MM-dd previewed as January 23, 2026. Rendering a preview from a token-string format (MMMM d, yyyy, yyyy-MM-dd) requires a token-based formatter, which native Intl/toLocaleDateString can't do — the rest of the admin uses Intl for display dates, but those take an options object, not token strings. So introducing a token formatter here is justified, and date-fns is the standard, tree-shakeable choice whose Unicode-token dialect matches the setting's documented "date format token string" contract (and the backend default "MMMM d, yyyy"). As a nice side effect, the PR also wraps the previously untranslated description in t, fixing a Lingui leak that existed on main.
One thing for the maintainer to consciously accept: this is the first date library in the repo and a new runtime dependency on a published package (@emdash-cms/admin), adding supply-chain surface in a repo that is deliberately strict about deps (minimumReleaseAge, strictDepBuilds, blockExoticSubdeps). I judge it warranted here, but it's the one taste call worth a deliberate nod rather than a silent merge.
What I checked
- Helper logic (
date-format-example.ts):formatis wrapped in try/catch →nullon bad input; the reference datenew Date(2026, 0, 23, 12)is well-chosen (day=23 disambiguatesMM/ddvsdd/MM; noon local can't roll the date across a TZ boundary, so date-only previews are TZ-stable). The internaldateFormat || DEFAULT_DATE_FORMATis redundant given the caller already guards, but it's harmless defensiveness. - Component (
GeneralSettings.tsx):value={dateFormat}is behaviorally identical to the oldformData.dateFormat || "MMMM d, yyyy"(default shown but not persisted into state — same as before, not a regression). Thedescriptionnow has a valid/invalid branch, both correctly wrapped withtand using interpolation (not concatenation), so word order is translator-safe. ICU-injection from user-typed format strings isn't a concern — interpolated values are runtime args, not part of the message pattern. - i18n / RTL: no new untranslated strings; no
messages.poincluded (correct — the workflow extracts on merge). The→arrow is pre-existing and now translatable, so translators can adapt it for RTL; not a regression. - Consistency:
DEFAULT_DATE_FORMAT = "MMMM d, yyyy"matches the backend default asserted inpackages/core/tests/unit/settings/settings.test.ts. No other call sites referenced the old hard-coded example. - Changeset: present,
@emdash-cms/admin: patch, appropriate for a pre-1.0 bug fix.date-fnsis correctly independencies(it's bundled into the shippeddist). - Tests: a reproducing test exists covering the default, an ISO variant, and the
nullpath.
I could not run the test/build myself (date-fns isn't installed in the sandbox and I review statically), so the build/typecheck/test-pass claims are taken on the author's report. My static reading of date-fns format — it throws on unknown letter sequences (e.g. the n in "nope") — is consistent with the "yyyy-MM-dd nope" → null assertion, so the test is not obviously false-confidence.
Conclusion
Clean, correct, well-tested fix that also tightens i18n. Mergeable as-is; the only actionable note is a minor test-placement convention nit.
| @@ -0,0 +1,17 @@ | |||
| import { describe, expect, it } from "vitest"; | |||
There was a problem hiding this comment.
[suggestion] Pure src/lib/* helper tests live in tests/lib/ (e.g. datetime-local.test.ts, url.test.ts, utils.test.ts, markdown.test.ts — 14 files mirroring src/lib/). This test for src/lib/date-format-example.ts is placed at the top level of tests/ instead, where the only other top-level tests (router.test.tsx, editor-focus.test.tsx, byline-form-customfields.test.tsx) cover cross-cutting features rather than a single src/lib module. Move it to tests/lib/date-format-example.test.ts to match the mirror-source convention; the import would then become from "../../src/lib/date-format-example". (It still matches the tests/**/*.test.{ts,tsx} glob either way, so this is placement only — no runtime impact.)
e37a31b to
461a71a
Compare
461a71a to
880e564
Compare
What does this PR do?
Fixes the Reading settings date format example in the admin UI so it is rendered from the configured date format string instead of always showing the hard-coded
January 23, 2026example.For example,
yyyy-MM-ddnow previews as2026-01-23.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
Validated with:
I did not run the full repository lint or full test suite; this PR is scoped to the admin date format preview helper and its targeted test.