Add quarter date formatter#1293
Merged
Merged
Conversation
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.
✅ Deploy Preview for cxjs-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
quarterformatter that renders the calendar quarter of a date — a companion to thedaybeforeformatter from #1292.The pattern is a
StringTemplatewith{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
exclusiveflag (short formsex/e) steps the date back one calendar day before computing the quarter — for displaying the exclusive end of a half-open range:So a range
2020-01-01 … 2021-01-01displays as20Q1 - 20Q4.Changes
util/date/dateQuarter.ts(new) —dateQuarter(date: Date): number.ui/Format.ts—quarterformatter, registered eagerly. It lives inui/Format(notutil/Format) because it relies onStringTemplatefrom thedatalayer, whichutil/cannot import.ui/Format.spec.ts(new) — 5 tests, includingquarter;;e(empty pattern falls back to the default while the exclusive flag still applies).formatting.mdx, plus new utility pages fordayBeforeanddateQuarterindocs/utilities/(registered in the docs navigation).Testing
Formattest suite: 18 passing (13 existing + 5 newquartercases).yarn check-types: clean.