fix(kit): fix calendar range presets filtration #9777
Merged
+28
−1
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
I need to add a preset for the calendar: "Previous Period". This preset ensures that the selected period has the same length and directly precedes the current selection.
For example:
Implementation Details
Ensures that the previous period matches the
minLength
andmaxLength
of the current selection.Adjusts the range so the new period is directly adjacent to the current selection, maintaining its exact length.
Issue
https://stackblitz.com/edit/angular-ckrt12?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fapp.template.html
In the example at the link, the dates are different; it will always be Today - 2 days.
The length ends up being 3 days inclusive.
The preset will be:
from: today - (3 + 2)
andto: today - 3
The library's filtering logic rejects the preset dates in some cases.
However, I can select these dates manually, and in that case, the preset label is applied to the input.
For example:
When the selected range is 14–15, the preset suggests 12–13.
minLength = 2
, but12 + 2 = 14
.The library's mapper treats this as invalid because 14 does not satisfy
daySameOrBefore
with the "to" date, which is day 15.Proposed Fix
In the filtering logic, it seems necessary to include an adjustment like
append({ day: -1 })
to correctly validate the preset's range.