Skip to content

Add quarter date formatter#1293

Merged
mstijak merged 2 commits into
masterfrom
feature/quarter-formatter
May 19, 2026
Merged

Add quarter date formatter#1293
mstijak merged 2 commits into
masterfrom
feature/quarter-formatter

Conversation

@mstijak
Copy link
Copy Markdown
Member

@mstijak mstijak commented May 19, 2026

Summary

Adds a quarter formatter that renders the calendar quarter of a date — a companion to the daybefore formatter from #1292.

quarter              2020-02-15  ->  "Q1 2020"
quarter;{yy}Q{q}     2020-02-15  ->  "20Q1"
quarter;{q}Q{yy}     2020-02-15  ->  "1Q20"

The pattern is a StringTemplate with {q} (quarter number), {yyyy} and {yy} (year) placeholders — case-insensitive, so {Q}/{YYYY}/{YY} work too. Anything else is literal. Default pattern: Q{q} {yyyy}.

Exclusive range ends

An exclusive flag (short forms ex / e) steps the date back one calendar day before computing the quarter — for displaying the exclusive end of a half-open range:

{from : quarter;{yy}Q{q}}            ->  20Q1
{to   : quarter;{yy}Q{q};exclusive}  ->  20Q4

So a range 2020-01-01 … 2021-01-01 displays as 20Q1 - 20Q4.

Changes

  • util/date/dateQuarter.ts (new) — dateQuarter(date: Date): number.
  • ui/Format.tsquarter formatter, registered eagerly. It lives in ui/Format (not util/Format) because it relies on StringTemplate from the data layer, which util/ cannot import.
  • ui/Format.spec.ts (new) — 5 tests, including quarter;;e (empty pattern falls back to the default while the exclusive flag still applies).
  • Docs — a "Quarter Format" section in formatting.mdx, plus new utility pages for dayBefore and dateQuarter in docs/utilities/ (registered in the docs navigation).

Testing

  • Format test suite: 18 passing (13 existing + 5 new quarter cases).
  • yarn check-types: clean.

mstijak added 2 commits May 19, 2026 10:06
Adds a `quarter` formatter that renders the calendar quarter of a date
using a string-template pattern with `{q}`, `{yyyy}` and `{yy}`
placeholders (case-insensitive). Defaults to `Q{q} {yyyy}`, e.g. "Q1 2020".

An `exclusive` flag (short forms `ex` / `e`) steps the date back one day
before computing the quarter, so a half-open range 2020-01-01 .. 2021-01-01
renders as "20Q1 - 20Q4".

The formatter is registered in ui/Format because it relies on
StringTemplate from the data layer, which util/ cannot import.
Adds documentation pages for the dayBefore and dateQuarter utility
functions and lists them in the Date section of the docs navigation.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for cxjs-docs ready!

Name Link
🔨 Latest commit b15baa3
🔍 Latest deploy log https://app.netlify.com/projects/cxjs-docs/deploys/6a0c1b119afa4c0008d608df
😎 Deploy Preview https://deploy-preview-1293--cxjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mstijak mstijak merged commit f570350 into master May 19, 2026
6 checks passed
@mstijak mstijak deleted the feature/quarter-formatter branch May 19, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant