Handle date difference for ends of months #553
Merged
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.
Fixes #552
Description of the changes:
The incrementally calling
Window::Globalization::Calendar::AddMonths
resulted in a negative value for
GetDifferenceInDays
which was thenassigned to an unsigned variable
daysDiff
.One example of the issue when running the calculator in UTC+2 was the
difference between July 31st and December 30th.
The initial guess was 4 months which then landed on November 30th.
This date was stored and then in the loop incremeted by one month.
This then landed precisely on the end date December 30th.
After the loop the final value is then used July 31st + 5 months
which results in the 31st of December.
The resulting difference of -1 days is then assigned to the unsigned
value
daysDiff
.This commit makes the minimal changes to remedy this bug.
It makes sure to only ever call
AddMonths
with the same starting dateinstead of incrementally to different dates.
This commit makes the minimal changes to remedy this bug.
It makes sure to only ever call
AddMonths
with the same starting dateinstead of incrementally to different dates.
How changes were validated: