-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add relative date shorthands to Query Builder #54408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say, I like the naming, though. I'd prefer something like whereDateBefore
and whereDateAfter
or the like 🤔
It would be nice if there was a trait class for date relations like |
I am shocked that there is any resistance to this at all. The changes are small, solve a common paper cut, and don't impose any obvious performance penalties. I am definitely all for this. |
@selcukcukur There could be a trait for all
@nexxai It adds yet another |
For PostgreSQL this would have to use a full iso-8601 date with timezone. |
@tpetry, do you know if the underlying Follow-up: A quick dump shows that |
Yeah, its not correct currently for PG. I think the best approach would be copying the implementation of if ($value instanceof DateTimeInterface) {
$bindings[$key] = $value->format($grammar->getDateFormat());
} |
@tpetry, my humble vote would be to merge this and then address that in a separate PR for |
Most of the Not saying I'm against the feature per se, but I don't understand the need for complexity in the implementation. What's insufficient with the following? public function wherePast($column, $boolean = 'and', $not = false)
{
return $this->where($column, $not ? '>=' : '<', now(), $boolean);
}
public function whereFuture($column, $boolean = 'and', $not = false)
{
return $this->where($column, $not ? '>' : '<=', now(), $boolean);
}
public function whereToday($column, $boolean = 'and', $not = false)
{
return $this->whereDate($column, $not ? '<>' : '=', now(), $boolean);
} I'm also a bit afraid this would open up the next need for things like |
@tontonsb, many Yes, if multiple columns and micro-second precision is not needed, then as noted in several previous comments, the implementation could be streamlined. However, as is, they are not equivalent. I'm leaving it up to the team to decide which direction, if any, they want to take. PR comments can get a bit noisy of late. |
Looks like this got merged. Yay! I do my best to maintain and promote the "good vibes" of the Laravel community. But, I have to admit, of late, I have not wanted to endure the comments from submitting a PR. So, I have some specific and general feedback... @shaedrich, you seem to comment early and often on a lot of PRs. That's cool, but can create a lot of noise. @selcukcukur, you can always make your own PR to refactor something after it's merged. Leaving the same comment on PRs is also noise. Generally, I would suggest sharing your opinion, but remain encouraging and offer suggestions. If something is truly "not a good solution", trust it won't be merged. Don't kill the "good vibes". |
Taylor will most likely not reply to a PR when closing it other than a standard reply. He'll also not read much about thought processes and such. So, I think, its important to get into discussion with the community, offer a different angle, and help shape features. |
Lack of timezone support for the today related functions seems like a massive oversight. Could push people to move their app timezone away from UTC without understanding the implications of doing so. |
@DougSisk, yes, @tpetry commented on something similar for Postgres specifically. Since this simply delegates to the current builder, whatever "oversight" may exist would also exist for all date query builder methods. If you believe that to be the case, I encourage a PR to improve this for Laravel 12. |
I‘ll work on a PR this week |
This is awesome @jasonmccreary! I can immediately use this. Well done. ❤️ |
@jasonmccreary The Can you fix it or should i? |
@tpetry, I am not a core team member, so I can't speak to what (if any) changes will be made or who would make them. As I've noted, if you (or anyone) feel something about the framework can be improved I'd encourage you to open your own PR. This PR has been merged. I'm happy with the new functionality, and it matches how other similar methods currently behave. Again, if you feel that behavior should change, submit a PR. 👍 |
This will help in making our code more cleaner. Good to see the new feature. |
I PR'd a version of this almost 3 years ago and still reach for it. So I figured I'd give it another shot.
This adds a few relative, human readable shorthands for working with dates (cause dates are hard).
While I appreciate this adds weight to this ever growing class, there are dozens of other shorthands. Queries are something devs write everyday. As such, I believe any shorthand continues to improve the DX of Laravel.
All of these methods have their
where
,or
, andorWhereNot
counterparts. All methods also accept an array of column names as the first argument. ThewherePast
andwhereFuture
have an optional second argument to set$now
.