Calculation of relative date fiscal year previous_N is wrong
Meaning:
- previous => OK
- previous_1 => Not OK
- previous_2 => Not OK
- etc... Not OK
The problem is here: https://github.com/civicrm/civicrm-core/blob/5c890572f11b797acd19d2082697670440d8b1e0/CRM/Utils/Date.php#L1323 because that's always going to mean "ending in the current fiscal year", which isn't correct for "previous_N".
$to['Y'] = $fYear;
Came up during review of https://github.com/civicrm/civicrm-core/pull/24752. It hasn't been noticed to-date because while the code is present, you'd have to manually add a previous_N.fiscal_year to the option values to make it appear in the UI. Only previous.fiscal_year is shipped with a stock install, and that works because it enters the if
block above the above mentioned code, not the else
block.
Here's a table, looking at years only, which has some extra stuff just for comparison because the wordings of these relative dates is not always clear in english. The main thing to look at is previous should be equivalent to previous_1, and you can see this is not the case.
Type | Calendar | Fiscal |
---|---|---|
previous | 2020 | 2021 |
previous_1 | NOT DEFINED | 2021 & 2022 |
previous_2 | 2020 & 2021 | 2020 & 2021 & 2022 |
earlier | forever - 2021 | NOT DEFINED |
earlier_2 | NOT DEFINED | NOT DEFINED |
ending | 2022 | NOT DEFINED |
ending_2 | 2021 & 2022 | NOT DEFINED |