Skip to content

Commit

Permalink
add dateFrom and dateTo methods for filtering by date range
Browse files Browse the repository at this point in the history
  • Loading branch information
imahmood committed May 10, 2024
1 parent 19281f9 commit 58de97d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/BaseFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ protected function compare(string $field, string $operator, string $value): self
return $this;
}

protected function dateFrom(string $field, string $date): static

Check warning on line 88 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L88

Added line #L88 was not covered by tests
{
if ($date) {
$this->getQuery()->where($field, '>=', $date.' 00:00:00');

Check warning on line 91 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L90-L91

Added lines #L90 - L91 were not covered by tests
}

return $this;

Check warning on line 94 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L94

Added line #L94 was not covered by tests
}

protected function dateTo(string $field, string $date): static

Check warning on line 97 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L97

Added line #L97 was not covered by tests
{
if ($date) {
$this->getQuery()->where($field, '<=', $date.' 23:59:59');

Check warning on line 100 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L99-L100

Added lines #L99 - L100 were not covered by tests
}

return $this;

Check warning on line 103 in src/BaseFilter.php

View check run for this annotation

Codecov / codecov/patch

src/BaseFilter.php#L103

Added line #L103 was not covered by tests
}

public function setQuery(QueryBuilder $builder): void
{
$this->builder = $builder;
Expand Down

0 comments on commit 58de97d

Please sign in to comment.