Add daybefore date formatter#1292
Merged
Merged
Conversation
Adds a `daybefore` formatter that renders a date shifted back by one calendar day, using the same pattern argument as `datetime`. Useful for displaying the exclusive end of a date range as an inclusive value, e.g. a period ending at 2021-01-01 shown as "Dec 2020". Registered as `dayBefore` with a `daybefore` alias in both the basic (util/Format.ts) and culture-sensitive (ui/Format.ts) formatter sets. Closes #1290
✅ 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
daybeforeformatter that renders a date shifted back by one calendar day, using the same pattern argument asdatetime.It's handy for displaying the exclusive end of a date range as an inclusive value — e.g. a period running from
2020-01-01up to (but not including)2021-01-01can be shown asDec 2020.Changes
util/date/dayBefore.ts(new) —dayBefore(date: Date): Datehelper returning the previous calendar day (no mutation; accepts an already-parsedDate).util/Format.ts— basicdayBeforeformatter +daybeforealias, mirroring basicdatetime.ui/Format.ts— culture-sensitivedayBefore/daybeforeformatter, same pattern argument and"yyyyMd hhmm"default asdatetime.util/Format.spec.ts— tests for the day shift and month/year boundary crossing.homedocs/.../formatting.mdx— a "Day-Before Format" docs subsection.Testing
Formattest suite: 13 passing (including 2 newdaybeforecases).yarn check-types: clean.Closes #1290