Extend fiscal year relative options to better match other periods #12137
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.
Overview
Adds relative date handling for fiscal_year.previous_before, fiscal_year.previous_2, fiscal_year.previous_3, fiscal_year.previous_n at the function level and adds unit tests (but does not expose)
Before
CRM_Utils_Date::relativeToAbsolute cannot parse previous.before et al
After
CRM_Utils_Date::relativeToAbsolute can parse previous.before et al, unit tests
Technical Details
This comes out of my effort to review #11592 and to see if it is mergeable. In digging I concluded I would NOT be comfortable merging additional handling options without unit tests (I'm undecided on adding new options to the core option value set & I note there is an extension proposal in the mix).
I do agree it's logical for the CRM_Utils_Date::relativeToAbsolute function to handle the same options for fiscal_year as for others and I added 3 of the proposed options with unit tests :
(based on a current date of ie. in May 2018 & financial year end 30 June)
fiscal_year.previous_before - the fiscal year before the previous one - 1 Jul 2015 to 30 June 2016
fiscal_year.previous_2 - the 2 fiscal years before this one - ie. 1 Jul 2015 to 30 June 2017
fiscal_year.previous_3 - the 3 fiscal years before this one - 1 Jul 2014 to 30 June 2017
(fiscal_year.previous_205 could also be handled by the code loop but I only test to previous_4)
Comments
I think this is mergeable as a partial of #11592 and because it enhances the code by adding unit tests. However, I will only keep it open for a month if not merged as it is a reviewer's commit.
I don't feel comfortable adding more options without more unit tests.