Fix Week formatting issue when date range spans across two years #86
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.
This PR addresses a bug occurring when:
• The selected interval is "week",
• The date range spans across two years (e.g. from December 23, 2024 to January 12, 2025).
Problem
In such a case, PHP’s $date->format('Y-W') can return “2024-01” for the week starting on Monday, December 30, 2024 and ending on Sunday, January 5, 2025.
Although the date is still in 2024, the ISO week number is 1, which typically refers to the first week of the following year. This leads to inconsistent keys when compared to those returned by MySQL.
Example returned by mapValuesToDates():
Quick test :
Fix
This PR ensures $placeholders uses consistent week-year formatting that aligns with ISO 8601 and MySQL outputs.
Now, for a week that starts on Dec 30, 2024, the returned key will be “2024-53”, not “2024-01”.
It is worth noting that MySQL may return two distinct keys for the same week: "2024-53" and "2025-01".
As a result, we end up with two items in the collection for what is essentially the same week.
This is particularly problematic when rendering data in line charts, as it leads to data duplication and visual inconsistencies.
➡️ A separate pull request will be created to address this specific issue.