[$175] In Insights, the custom date range year picker lists about 100 future years before any past year
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
Version Number: 9.5.53-0 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @abzokhattab Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
- Go to Insights (any tab, e.g. Compliance)
- Click Date > Custom range
- In the From calendar, click the year (2026) to open the year picker
- Scroll the year list
Expected Result:
Insights only covers past dates, so the list should show the current year and then earlier years, nearest first (2026, 2025, 2024, …). Future years shouldn’t appear.
Actual Result:
The list shows 2026 pinned at the top, then 2027 through 2126 in ascending order, and only then 2025, 2024 … 1926. To pick a past year, you have to scroll past about 100 future years or search for it.
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/7a3718e7-90e2-4bd8-b88c-d8e4489e2247
https://github.com/user-attachments/assets/f8e23cc5-9b41-4059-a395-edd1f7932500
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022125210834804254856
- Upwork Job ID: 2125210834804254856
- Last Price Increase: 2026-11-24
Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)
Job added to Upwork: https://www.upwork.com/jobs/~022125210834804254856
Proposal
What is the root cause of that problem?
Insights inherits the shared calendar’s 100-years-back/100-years-forward bounds without restricting future years. For long lists, the year picker intentionally places future years before past years, then moves the initially displayed year to the top.
Together, these produce exactly the reported sequence: 2026 → 2027…2126 → 2025…1926.
Confidence: Medium. The code explains the complete sequence, and existing tests explicitly expect this ordering. Browser reproduction was not performed.
Code evidence
- Insights opens the shared date control through
InsightsDateControl.tsx:29–39. - Both range calendars omit explicit date bounds. Their day-selection predicates do not remove years from the picker:
RangeDatePicker.tsx:32–59. - Default year bounds are current year ±100:
CONST/index.ts:743–748. - Year generation, future-first sorting, and initial-year pinning are explicit:
YearPickerModal.tsx:45–68. - Existing tests assert this same ordering pattern:
YearPickerModalTest.tsx:103–120.
This is client-side option generation; server logs are not needed to explain the reported list.
What changes do you think we should make in order to solve the problem?
Add Insights-only configuration that:
- Limits custom-range year options to the current year and earlier.
- Orders years strictly descending.
- Keeps the selected year highlighted without moving it ahead of newer years.
Pass this configuration through the shared date controls to both From and To calendars, including wide and narrow layouts. Preserve existing defaults for Search and other calendar consumers.
Implementation scope and regression coverage
Forward the configuration from Insights through both responsive branches of DateSelectPopup, its narrow-layout branch, and the range branch in DatePresetFilterBase.tsx:479–493.
Why a maximum date alone is insufficient: reopening on a selected year such as 2020 would still produce 2020, 2021…2026, 2019…. Strict descending mode must bypass both around-selection sorting and initial-year pinning.
Regression coverage should verify:
- From and To show
2026, 2025, 2024…, with no future years. - Selecting an older year and reopening does not change that order.
- Year search and From ≤ To validation still work.
- Both responsive layouts receive the configuration.
- Unconfigured shared consumers retain their current behavior.
If the requirement also forbids future days, cap at today; excluding future years alone does not require that broader behavior change.
What alternative solutions did you explore?
Changing the shared defaults globally would affect unrelated date pickers. Restricting selectable days alone would leave the unwanted year rows visible.
Related issues—not confirmed duplicates:
- Move pre-selected list items to top of list throughout the app: relevant shared selection-ordering behavior.
- Stop plotting future periods and future-dated expenses on the Spend dashboard: related Insights requirement, but concerns chart data rather than picker ordering.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107841) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
@abdulrahuman5196 Melvin's fix forwards the year cap only to the From and To calendars of the Custom range branch, but the Insights Date control also offers Custom date (INSIGHTS_ALLOWED_CUSTOM_DATE_MODIFIERS is [ON]), and that path renders a separate CalendarPicker with no maxDate:
https://github.com/Expensify/App/blob/b7bd2e60a86738b411cb0b766ecabd0b34c6351c/src/components/Search/FilterComponents/DatePresetFilterBase.tsx#L497-L503
So after that fix, opening the year picker from Insights > Date > Custom date still lists 2026, then 2027 through 2126, then 2025. Passing a current-year maxDate from InsightsDateControl down to every CalendarPicker in DatePresetFilterBase caps both entry points, since CalendarPicker already derives maxYear from maxDate.
Happy to put up a full proposal for this if that's useful.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Insights, opening the year picker for the date control (the Custom date option, and the From / To calendars of a Custom range) shows about 100 future years before any past year: the list starts at 2026, then runs upward to 2126, and only after that runs downward through the past years. The user has to scroll through a century of future years to reach a year they can actually use, because Insights only covers past dates. The expected behavior is a list that starts at the current year and runs downward through past years only.
What is the root cause of that problem?
Two interacting causes, both verified on baseline e91964cb:
-
The shared calendar picker has no year cap on the Insights path, so it defaults to a 201-year window.
CONST.CALENDAR_PICKER.MIN_YEARis the current year minus 100 andMAX_YEARis the current year plus 100 (src/CONST/index.ts:736-737).CalendarPicker(src/components/DatePicker/CalendarPicker/index.tsx:88-89) builds its bounds withgetBound(maxDateProp, CONST.CALENDAR_PICKER.MAX_YEAR), and Insights passes nomaxDateat all, so the picker shows 1926 to 2126.DatePresetFilterBase(src/components/Search/FilterComponents/DatePresetFilterBase.tsx) forwards nomaxDateto either the Custom range branch (RangeDatePicker) or the Custom single-date branch (the singleCalendarPicker), andRangeDatePicker(src/components/Search/FilterComponents/RangeDatePicker.tsx) has nomaxDateprop to forward in the first place. -
Even with a cap, the list would still open in the wrong order.
YearPickerModal(src/components/DatePicker/CalendarPicker/YearPickerModal.tsx:70-71) sorts withcompareAroundInitialYearand then pins the initial selection to the top whenevershouldMoveInitialSelectionToTop(years.length)is true, which it is for any list of 12 or more years. A capped list of 101 years (1926 to 2026) still has 12 or more entries, so on reopening after selecting 2020 it would show 2020 first, then 2021 upward to 2026, then 2019 downward. Capping the years alone does not produce a newest-first list.
What changes do you think we should make in order to solve the problem?
Two changes, plumbed through the whole Insights date chain so all three pickers (From, To, and the single Custom date picker) behave the same way:
-
Cap the year list at the end of the current year.
InsightsDateControl(src/pages/Insights/controls/InsightsDateControl.tsx:28) computesINSIGHTS_MAX_DATE = endOfYear(new Date())once at module load and passes it asmaxDate. The value is the last day of the current year, not today: using today would wrongly disable future days inside the current year, while end of year keeps every day inside the current year selectable. Days in later years become unselectable, which is intended because Insights covers past dates.maxDateis forwarded throughDateSelectPopup(both the wide and narrow branches,src/components/Search/FilterDropdowns/DateSelectPopup/index.tsx:163,227),DatePresetFilterBase(both the range branch and the single-date branch,:466,478), andRangeDatePicker(both the From and To calendars,:49,64) intoCalendarPicker, where the existinggetBoundlogic turns it intomaxYearequal to the current year. The list becomes exactly 101 years: current year down to current year minus 100. -
Add an explicit opt-in prop
shouldSortYearsDescendingthat sorts the year list newest-first and skips the pin-to-top step. InYearPickerModal(:70-71), when the prop is true the list is sorted withcompareNewestFirstandmoveInitialSelectionToTopis skipped entirely, so reopening after selecting 2020 still shows the strict newest-first order. The prop defaults to false everywhere and is passed only byInsightsDateControl, so every other consumer keeps its current ordering: the date-of-birth picker keeps its pinned initial selection, and any other picker that already passes its ownmaxDateis untouched. The prop is forwarded along the same four levels asmaxDate.
The fix is on branch fix-107841-insights-year-picker (baseline e91964cb), 6 source files, +54/-4. No schema change, no new Onyx subscriptions, and no change to any other date control.
What alternative solutions did you explore? (Optional)
- Capping
maxDateonly, with no sort change: rejected. As shown in root cause (2), a 101-year list still triggers the pin-to-top ordering, so reopening the picker after a selection would not show a newest-first list. - Setting
maxDateto today instead of end of year: rejected. Today would disable every day after today inside the current year, even though those dates are valid for Insights. End of year caps only the year list. - Sorting descending automatically whenever the capped
maxYearis at or below the current year: rejected. That trigger is global, so it would also reorder every other picker whosemaxDatecaps at or below the current year. The date-of-birth picker, for example, passesmaxDateequal to today minus 18 years; a global trigger would silently change its pinned ordering and break the behavior its tests assert. An explicit opt-in prop passed only on the Insights path avoids that. - Inferring the sort from the
maxDatevalue instead of adding a prop: rejected for the same reason as (3). The sort is a display choice for one screen, not a property of the cap, so it should be an explicit prop rather than a side effect of the date value.
Tests added and run on baseline e91964cb (all passing):
tests/ui/YearPickerModalTest.tsx(3 new tests): with the opt-in on, the list is exactly the current year down to current year minus 100 when reopened after selecting 2020; the same descending order holds under search; with the prop off, a DOB-style picker (min 1876, max 2008, current 1990) keeps its pinned ordering. 11/11 pass in the suite.tests/unit/CalendarPickerTest.tsx(4 new tests): passingmaxDatecaps the year list at the current year; the sort prop is forwarded to the modal; the list is not sorted descending by default; Dec 31 of the current year stays selectable. 79/79 pass in the suite.tests/unit/RangeDatePickerTest.tsx(3 new tests): both the From and To calendars are capped at the current year and both receive the sort prop. 15/15 pass in the suite.tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx(3 new tests): the range branch and the single-date branch are both capped and sorted, and the uncapped default is unchanged. 8/8 pass in the suite.
113/113 tests pass across the four suites. 8 of the 13 new tests fail on the clean baseline, which confirms they exercise the new behavior; the 5 that pass on baseline are by-design regression guards (DOB pinning, the uncapped default, the pre-existing CalendarPicker maxDate cap, Dec 31 selectability, and the default no-sort behavior).
Lint: direct oxlint on all 10 touched files reports 8 errors, all pre-existing on lines outside this diff (pre-existing new Date() calls, a restricted import, a setState-in-effect, and deprecated MenuItem usages); this change adds zero new lint errors. The React Compiler compliance concern on the first version of the change (new Date() during render) was fixed by moving the computation to a module-level constant, which matches the existing module-level CONST.CALENDAR_PICKER.MIN_YEAR / MAX_YEAR pattern.
Full typecheck was attempted once on this machine and did not finish (the run was interrupted before producing diagnostics); it was not retried. The changed files pass the type-aware lint rules, and the changes add no any and no new type assertions.
Peer review: independent reviewer, PASS 92/100. The reviewer traced the full prop chain, verified that no non-Insights consumer receives either prop, verified the exact 101-year list and the pinned-ordering regression guard, and confirmed the lint result. Its only findings were non-blocking: an end-to-end test through InsightsDateControl would be stronger than the current composition of plumbing tests plus the exact-list modal test, and the day-selectability wording above is the tightened version it asked for.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue?
In Insights, opening the year picker for the date filter (both for the Custom date option and the From/To calendars of Custom range) displays ~100 future years (e.g. 2026, then 2027 through 2126) before any past years. Users must scroll past a century of irrelevant future years or type to search to select past years, even though Insights is an analytical reporting dashboard that only covers past/existing expenses.
What is the root cause of that problem?
In src/pages/Insights/controls/InsightsDateControl.tsx and src/components/Search/FilterComponents/DatePresetFilterBase.tsx:
-
InsightsDateControlrendersDateSelectPopupwithout passing an explicitmaxDateprop. -
In
DatePresetFilterBase.tsx(lines 481–503), neither theRangeDatePicker(From/To calendars) nor the single-dateCalendarPickerreceives amaxDateconstraint. -
In
CalendarPicker/index.tsx(line 85), whenmaxDatePropis omitted, it falls back to:
const maxDate = getBound(maxDateProp, CONST.CALENDAR_PICKER.MAX_YEAR);
where CONST.CALENDAR_PICKER.MAX_YEAR is currentYear + 100 (e.g. 2126).
-
CalendarPickerpassesminYear = 1926andmaxYear = 2126toYearPickerModal.tsx. -
In
YearPickerModal.tsx(lines 45–68), becauseyears.length(201) exceedsCONST.CALENDAR_PICKER.SHORT_YEAR_LIST_THRESHOLD(10),shouldMoveInitialSelectionToTopappliescompareAroundInitialYear:
const compareAroundInitialYear = (a: CalendarPickerListItem, b: CalendarPickerListItem) => {
const isAUpcoming = a.value > initialYear;
const isBUpcoming = b.value > initialYear;
if (isAUpcoming !== isBUpcoming) {
return isAUpcoming ? -1 : 1;
}
return isAUpcoming ? a.value - b.value : b.value - a.value;
};
This intentionally sorts all upcoming future years (value > 2026: 2027...2126) first in ascending order, followed by past years descending (2025...1926), and pins the selected year (2026) at the top. This produces the exact sequence: 2026 → 2027...2126 → 2025...1926.
What changes do you think we should make in order to solve the problem?
- In
src/pages/Insights/controls/InsightsDateControl.tsx: PassmaxDatetoDateSelectPopup. Because Insights only applies to past dates up to the end of the current year (or today), passmaxDate:
const maxDate = endOfYear(new Date());
(or a memoized/module-level date instance).
- Forward
maxDate?: Datethrough the component chain:
- In
src/components/Search/FilterDropdowns/DateSelectPopup/index.tsx: acceptmaxDate?: Dateand pass it toDatePresetFilterBase. - In
src/components/Search/FilterComponents/DatePresetFilterBase.tsx: acceptmaxDate?: Dateand forward it to both<RangeDatePicker maxDate={maxDate} ... />and<CalendarPicker maxDate={maxDate} ... />. - In
src/components/Search/FilterComponents/RangeDatePicker.tsx: acceptmaxDate?: Dateand pass it to both theFromandTo<CalendarPicker maxDate={maxDate} ... />instances.
- Natural sorting resolution in
YearPickerModal.tsx: WhenmaxDateis capped at the current year (maxYear === currentYear):
yearscontains only years1926...2026.- There are no future years (
value > initialYearis alwaysfalse). - In
compareAroundInitialYear,isAUpcomingisfalsefor all years, so the comparison naturally sorts descending:b.value - a.value. moveInitialSelectionToToppins the current year (2026) at the top, followed naturally by2025, 2024, 2023, ... 1926.
This elegantly solves the issue using standard maxDate props already supported by CalendarPicker, without requiring custom sort flags, without breaking DOB pickers, and covering both Custom range and Custom date paths.
What alternative solutions did you explore? (Optional)?
- Adding an explicit
shouldSortDescendingboolean prop: Rejected as unnecessary overhead.CalendarPickeralready natively supportsmaxDate. CappingmaxDateto the current year naturally eliminates future years and produces the desired newest-first ordering across all years.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Insights, opening the year picker from the Date control (both Custom range From/To calendars and Custom date) shows ~100 future years before any past year (2026, 2027..2126, then 2025..1926). Because Insights only covers past dates, the list should omit future years and display years strictly newest-first starting with the current year (2026, 2025, 2024, ...).
What is the root cause of that problem?
Two separate pieces of logic combine to produce the bug:
- No upper year bound on the Insights date chain:
InsightsDateControldoes not pass amaxDateintoDateSelectPopup, and neitherDateSelectPopup,DatePresetFilterBase, norRangeDatePickerforwardsmaxDatetoCalendarPicker. As a result,CalendarPickerfalls back toCONST.CALENDAR_PICKER.MAX_YEAR(currentYear + 100, e.g.2126). - Default year ordering pins and groups around
initialYearfor lists ≥ 12 years: Insrc/components/DatePicker/CalendarPicker/YearPickerModal.tsx, whenevershouldMoveInitialSelectionToTop(years.length)is true, the list sorts withcompareAroundInitialYearand callsmoveInitialSelectionToTop. Even after cappingmaxYearto the current year, the list still has 101 years (>= 12), so reopening the picker after choosing a past year (e.g.2020) would still display2020, 2021..2026, 2019..1926instead of2026, 2025, ....
What changes do you think we should make in order to solve the problem?
- Compute a fresh current-year cap in
src/pages/Insights/controls/InsightsDateControl.tsx- Inside the
datePopoverrender callback, passmaxDate={endOfYear(new Date())}and an opt-inshouldSortYearsDescendingflag toDateSelectPopup. - Computing
endOfYear(new Date())when the popover opens avoids freezing a stale year in a module-level constant across a year rollover (Dec 31 → Jan 1), while keeping all days within the current year selectable and disabling navigation beyond the current year (isAtMaxYearinCalendarPicker).
- Inside the
- Forward
maxDateandshouldSortYearsDescendingthrough the shared Insights date controlssrc/components/Search/FilterDropdowns/DateSelectPopup/index.tsx: accept both optional props and forward them toDatePresetFilterBasein both the wide (!isSmallScreenWidth) and narrow (isSmallScreenWidth) render branches.src/components/Search/FilterComponents/DatePresetFilterBase.tsx: accept both optional props and forward them to both<RangeDatePicker />(Custom range) and the single<CalendarPicker />(Custom dateONmodifier).src/components/Search/FilterComponents/RangeDatePicker.tsx: accept both optional props and forward them to both theFromandTo<CalendarPicker />instances.src/components/DatePicker/CalendarPicker/index.tsx: acceptshouldSortYearsDescending?: boolean(defaultfalse) and forward it to<YearPickerModal />(wheremaxDatealready derivesmaxYear).
- Add strict descending mode in
src/components/DatePicker/CalendarPicker/YearPickerModal.tsx- Accept
shouldSortYearsDescending = false. - When
shouldSortYearsDescendingistrue, sort withcompareNewestFirstand skipmoveInitialSelectionToTop(leavingisSelectedhighlighted oncurrentYearand keepingshouldScrollToFocusedIndexOnMount={false}so the list always opens at the current year at the top). - When
false(default), preserve the existingcompareAroundInitialYear+moveInitialSelectionToTopbehavior untouched for all other consumers (such as Search and DOB pickers).
- Accept
What specific scenarios should we cover in automated tests?
YearPickerModal: withshouldSortYearsDescending, verify2026, 2025, ...order holds even when reopening withcurrentYear={2020}and while searching; with defaultfalse, verify existing pinned ordering (e.g. DOB picker) is unchanged.CalendarPicker,RangeDatePicker,DatePresetFilterBase, andDateSelectPopup(wide + narrow): verifymaxDateandshouldSortYearsDescendingreach From, To, and Custom date calendars, no future years appear, and non-Insights callers keep their defaults.
What alternative solutions did you explore? (Optional)
- Only passing
maxDatewithout updatingYearPickerModal: Incomplete — reopening after selecting a past year like2020still shows2020, 2021..2026, 2019...because 101 years still exceeds the pin-to-top threshold. - Using a module-level
endOfYear(new Date())constant: Goes stale if a long-lived web/desktop session stays open past midnight on Dec 31. - Using
endOfDay(new Date())instead ofendOfYear(new Date()): Would also block selecting future days inside the current year; if product wants future days in the current year disabled too, switchingendOfYeartoendOfDayis a one-line adjustment.
@abdulrahuman5196 Whoops! This issue is 2 days overdue. Let's get this updated quick!
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Insights, opening the year picker inside the date filter (both the Custom range From/To calendars and the single Custom date calendar) shows ~100 future years (2027..2126) in ascending order before past years (2025..1926). Because Insights only covers historical/current-year expense data, users must scroll past a century of unusable future years to pick an earlier year.
What is the root cause of that problem?
InsightsDateControlpasses no explicitmaxDatetoDateSelectPopup, and neitherDateSelectPopup,DatePresetFilterBase, norRangeDatePickerforwardsmaxDatetoCalendarPicker. As a result,CalendarPickerfalls back toCONST.CALENDAR_PICKER.MAX_YEAR(currentYear + 100).- Even with
maxDatecapped at the current year (leaving 101 years),YearPickerModalsorts withcompareAroundInitialYear+moveInitialSelectionToTopwheneveryears.length > SHORT_YEAR_LIST_THRESHOLD(10), which pins a previously chosen earlier year (e.g.2020) to the top and lists2021..2026ahead of2019..1926.
What changes do you think we should make in order to solve the problem?
- In
src/pages/Insights/controls/InsightsDateControl.tsx, passmaxDate={endOfYear(new Date())}insidedatePopover(avoiding a stale module-level constant across year rollover while keeping all days in the current year selectable) along withshouldSortYearsDescendingtoDateSelectPopup. - Forward
maxDate?: DateandshouldSortYearsDescending?: booleanthroughDateSelectPopup(both desktop and narrow-screen branches),DatePresetFilterBase(bothRangeDatePickerand singleCalendarPickerbranches),RangeDatePicker(both From and To calendars), andCalendarPicker(toYearPickerModal). - In
src/components/DatePicker/CalendarPicker/YearPickerModal.tsx, whenshouldSortYearsDescendingistrue, sort strictly withcompareNewestFirstand skipmoveInitialSelectionToTop, keeping the selected year highlighted viaisSelectedwhile leaving default behavior unchanged for non-Insights callers (e.g. DOB pickers). - Add unit tests in
tests/ui/YearPickerModalTest.tsxverifying strict descending order when reopening on an earlier year and while filtering via search.
What alternative solutions did you explore?
- Passing
maxDatealone withoutshouldSortYearsDescending: leaves reopening after selecting an earlier year (e.g.2020) showing2020, 2021..2026, 2019..1926. - Freezing
endOfYear(new Date())at module load: would go stale if a long-lived session stays open across midnight on Dec 31.
📣 @ryancooper312! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>