feat(DateRangePicker): add yesterday/quarter/year presets, expose helpers#231
Merged
Conversation
…pers Extend DateRangePresetKey with: yesterday, last-week, this-quarter, last-quarter, this-year, last-year, last-90-days, last-365-days. Each maps to a stable, end-of-day-inclusive range in calculateDateRange. Export calculateDateRange, getDefaultPresets, and a new getExtendedPresets helper so consumers can: - reuse the same range math when building custom UIs, - opt into the longer preset menu for analytics dashboards, - or compose their own list from the union of supported keys. The default preset list shown by DateRangePicker and DateRangeFilter is unchanged, so existing consumers see no behavior or visual diff. Adds unit tests with frozen system time covering every preset key, including the Q1 cross-year edge case.
There was a problem hiding this comment.
Pull request overview
Adds public DateRangePicker preset helpers and expands supported date-range preset keys for analytics-style ranges while keeping default preset lists unchanged.
Changes:
- Exposes
calculateDateRange,getDefaultPresets, andgetExtendedPresets. - Adds yesterday, last-week, quarter, year, last-90-days, and last-365-days preset support.
- Adds focused unit coverage for preset calculations and preset list helpers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/components/DateRangePicker/index.ts |
Re-exports the newly public helper functions. |
src/components/DateRangePicker/DateRangePicker.tsx |
Extends preset keys, labels, preset helper APIs, and date range calculations. |
src/components/DateRangePicker/DateRangePicker.test.tsx |
Adds unit tests covering preset math and helper lists. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Deploying ui with
|
| Latest commit: |
112020d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e4ca5cf9.ui-6d0.pages.dev |
| Branch Preview URL: | https://feat-date-range-picker-more.ui-6d0.pages.dev |
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
Extends
DateRangePicker/DateRangeFilterwith longer drill-down presets and exposes the range-math helpers so consumers can build their own preset menus on top of the same logic.While integrating the date picker into an analytics dashboard, I found I couldn't render presets like "Yesterday" or "This Quarter" without re-implementing the date math, because
calculateDateRangewas a private function — any preset key not in its built-inswitchreturned{ start: null, end: null }. This PR makes the helpers public and adds the obvious missing keys.Screenshots
New preset keys
Added to the
DateRangePresetKeyunion and implemented incalculateDateRange:yesterdaylast-weekthis-quarterlast-quarterthis-yearlast-yearlast-90-dayslast-365-daysAll bounded-day presets (
today,yesterday,this-week,last-week,this-month,last-month, the quarter/year keys) now end at23:59:59.999of the last day. Previously some used midnight, which excluded same-day events. The trailing-window keys (last-N-days,last-24-hours) continue to end atnow.New exports
This unlocks usage like:
Or for custom UIs that just need the math:
Backward compatibility
DateRangePicker/DateRangeFilterwhen nopresetsprop is passed is unchanged. Existing consumers see no visual or behavioral diff.labels?: { yesterday, lastWeek, thisQuarter, ... }keys are all optional with English defaults.Tests
Added
DateRangePicker.test.tsxwith 15 unit tests usingvi.useFakeTimers()to pin "now" to a stable date. Covers every preset key, including the Q1-rolls-back-across-year-boundary edge case forlast-quarter.Checks
pnpm typecheck— cleanpnpm lint— cleanpnpm test src/components/DateRangePicker— 15/15 pass