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.
Closes #232
This PR adds
date_start()
anddate_end()
, powered bycalendar_start()
andcalendar_end()
.Some notes on how we got here:
#232 suggested giving
date_group()
some way to return the end of the interval. This ends up being a little tricky to compute, and in some cases is tough to define - especially with pre-existing invalid dates. For example,calendar_group()
currently handles invalid dates fairly intuitively, by choosing the left-hand side of the interval, valid dates always result in another valid date, and invalid dates result in either another invalid date or a valid date (if the left-hand side of the interval is a valid date).But what if the right hand side of the interval was chosen here? In the second example, I imagine that
2019-04-30
would stay2019-04-30
, as that is the last valid date in the month (i.e. we couldn't return2019-04-32
even though that is the theoretical end of the interval). But what would the pre-existing invalid date of2019-04-31
return? I feel like returning2019-04-30
would be odd here, since that is less than the current invalid date (returning the left-hand side of the interval never has this problem). But we also can't return2019-04-32
, because that isn't even an invalid date. Returning2019-04-31
as is feels just as weird, because it isn't the left or right hand side of any interval.If we didn't have to consider these edge cases, then the implementation would be somewhat straightforward. It's just the
lower_bound + (n - 1)
then capped at the maximum valid component (i.e. the day at the end of the month in this case). Something like:But again, the invalid date results are a little odd.
Looking back at the issue, it seems @pnacht is really looking for some way to compute the start/end of the month (or year). I think that providing a way to do this directly is a better solution than tweaking
date_group()
to be possibly inconsistent.