Skip to content

Commit

Permalink
DateTime Filters: Allow column override of timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
solflare committed Jul 9, 2022
1 parent 03b3427 commit e92f1c4
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/BaseFeatures/Data/Types/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public function setInputFormat(string|null $format) : self
return $this;
}

public function getOutputTimezone() : string
{
return $this->outputTzName;
}

public function setOutputTimezone(string|null $timezone) : self
{
$this->outputTzName = $timezone;
Expand Down
25 changes: 25 additions & 0 deletions src/BaseFeatures/Filters/DoesNotEqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace BluefynInternational\ReportEngine\BaseFeatures\Filters;

use Carbon\Carbon;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;

class DoesNotEqualFilter extends BaseFilter
{
Expand Down Expand Up @@ -45,4 +47,27 @@ public static function key(): string
{
return 'does_not_equal';
}

/**
* @return null|string|Carbon
*/
public function getValue(array $options = [])
{
if ($this->valueIsDate()) {
/**
* @var Carbon $value
*/
$value = parent::getValue();
$timeZoneString = $this->getColumn()->type()->getOutputTimezone()
?? Arr::get($options, 'timezone');

if ($timeZoneString) {
$value->shiftTimezone($timeZoneString);
}

return $value->utc();
}

return parent::getValue();
}
}
5 changes: 4 additions & 1 deletion src/BaseFeatures/Filters/GreaterThanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getValue(array $options = [])
* @var Carbon $value
*/
$value = parent::getValue();
if ($timeZoneString = Arr::get($options, 'timezone')) {
$timeZoneString = $this->getColumn()->type()->getOutputTimezone()
?? Arr::get($options, 'timezone');

if ($timeZoneString) {
$value->shiftTimezone($timeZoneString);
}

Expand Down
5 changes: 4 additions & 1 deletion src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getValue(array $options = [])
* @var Carbon $value
*/
$value = parent::getValue();
if ($timeZoneString = Arr::get($options, 'timezone')) {
$timeZoneString = $this->getColumn()->type()->getOutputTimezone()
?? Arr::get($options, 'timezone');

if ($timeZoneString) {
$value->shiftTimezone($timeZoneString);
}

Expand Down
5 changes: 4 additions & 1 deletion src/BaseFeatures/Filters/LessThanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getValue(array $options = [])
* @var Carbon $value
*/
$value = parent::getValue();
if ($timeZoneString = Arr::get($options, 'timezone')) {
$timeZoneString = $this->getColumn()->type()->getOutputTimezone()
?? Arr::get($options, 'timezone');

if ($timeZoneString) {
$value->shiftTimezone($timeZoneString);
}

Expand Down
5 changes: 4 additions & 1 deletion src/BaseFeatures/Filters/LessThanOrEqualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getValue(array $options = [])
* @var Carbon $value
*/
$value = parent::getValue();
if ($timeZoneString = Arr::get($options, 'timezone')) {
$timeZoneString = $this->getColumn()->type()->getOutputTimezone()
?? Arr::get($options, 'timezone');

if ($timeZoneString) {
$value->shiftTimezone($timeZoneString);
}

Expand Down

0 comments on commit e92f1c4

Please sign in to comment.