jiff: Days in month rangeint should always have range 28-31 #85
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.
I noticed that the
days_in_month
function returns constant rangeints where the range of the value is just the exact value, so for examplev: 31, min: 31, max: 31
. If the idea of the tracked min and max values (in debug builds) is to ensure that the code will work with all possible values of the function in question, then this means we don't actually check the computation for all possible responses todays_in_month
.By changing the return values to always have a range with min 28 and max 31 we can ensure that all calculations will work with every month and year, instead of the specific one they are tested with.
A sidenote is that if one returns just a common
Day
value fromdays_in_month
, which has min of 1 and max of 31, this will end up throwing an error from thenth_weekday_in_month
tests, as the algorithms there only stay in the correct range if the values returned bydays_in_month
are actually what they are commonly.Not sure if I've figured out the situation correctly here – so feel free to just close this pull if it's a mistake.
And to be clear to anybody reading this – the changes here only affect debug builds and the internal safety checks in
jiff
. There are no external effects to these changes.