From 4ae32994ddee3d707376f8106bb4c5b83849be26 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Mon, 20 Jun 2022 14:34:42 -0700 Subject: [PATCH 1/8] Add support for encoded report metadata, Use it for initial timezone updates Still a lot left to do --- resources/views/base-web.blade.php | 26 ++++++++++++++-- src/BaseFeatures/Filters/EqualsFilter.php | 30 ++++++++++++------- .../Filters/LessThanOrEqualFilter.php | 2 +- src/ReportBase.php | 6 ++++ 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/resources/views/base-web.blade.php b/resources/views/base-web.blade.php index aa0ecb0..7e79fdb 100644 --- a/resources/views/base-web.blade.php +++ b/resources/views/base-web.blade.php @@ -105,6 +105,19 @@ function popupConfirm(row, title, body, routeTemplate, routeReplacements, routeH }) } + function addMetaDataToUrl(url) + { + let metaData = { + timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, + } + + let encodedMetaData = btoa(JSON.stringify(metaData)) + + url.searchParams.append('metaData', encodedMetaData) + + return url + } + (() => { $('#filterContainer .custom-select').change() @@ -177,8 +190,17 @@ function popupConfirm(row, title, body, routeTemplate, routeReplacements, routeH } }) - history.replaceState(null, '', endpoint.replace('.json', '') + '?' + filterParams.toString()); - table.setData(endpoint + '?' + filterParams.toString()); + let viewReportUrl = endpoint.replace('.json', '') + '?' + filterParams.toString() + let dataReportUrl = endpoint + '?' + filterParams.toString() + + viewReportUrlObject = new URL(viewReportUrl) + dataReportUrlObject = new URL(dataReportUrl) + + viewReportUrlObject = addMetaDataToUrl(viewReportUrlObject) + dataReportUrlObject = addMetaDataToUrl(dataReportUrlObject) + + history.replaceState(null, '', viewReportUrlObject.toString()); + table.setData(dataReportUrlObject.toString()); }); @if($autoloadInitialData) { diff --git a/src/BaseFeatures/Filters/EqualsFilter.php b/src/BaseFeatures/Filters/EqualsFilter.php index 1161cd4..5a8d7bd 100644 --- a/src/BaseFeatures/Filters/EqualsFilter.php +++ b/src/BaseFeatures/Filters/EqualsFilter.php @@ -3,6 +3,8 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; class EqualsFilter extends BaseFilter { @@ -12,20 +14,26 @@ class EqualsFilter extends BaseFilter * * @return Builder */ - public function apply(Builder $builder, array $options = []) : Builder - { - if ($this->valueIsDate()) { - $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $this->getValue()); - $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $this->getValue()); - $builder = $greaterThanEqual->apply($builder); + public function apply(Builder $builder, array $options = []) : Builder + { + if ($this->valueIsDate()) { + $value = Carbon::parse($this->getValue()); - return $lessThanEqual->apply($builder); - } + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } - $action = $this->getAction(); + $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $value); + $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $value); + $builder = $greaterThanEqual->apply($builder); - return $builder->$action($this->getField(), $this->getValue()); - } + return $lessThanEqual->apply($builder); + } + + $action = $this->getAction(); + + return $builder->$action($this->getField(), $this->getValue()); + } /** * @return string diff --git a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php index f14e98a..4f0ca59 100644 --- a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php @@ -25,7 +25,7 @@ public function apply(Builder $builder, array $options = []) : Builder public function getValue() { if ($this->valueIsDate()) { - return parent::getValue()->endOfDay()->toDateTimeString(); + return parent::getValue()->addDay()->toDateTimeString(); } return parent::getValue(); diff --git a/src/ReportBase.php b/src/ReportBase.php index 1c9aae8..a67cf79 100644 --- a/src/ReportBase.php +++ b/src/ReportBase.php @@ -481,4 +481,10 @@ public static function rendersFilters(Collection $filterColumns, int $columnsWid return $output; } + + public function getMetaData() : array + { + $encodedData = $this->currentRequest->get('metaData', ''); + return json_decode(base64_decode($encodedData)); + } } From dc8b31aa52c569c3c9b8b3891baf46fb5b47aece Mon Sep 17 00:00:00 2001 From: solflare Date: Mon, 20 Jun 2022 21:35:52 +0000 Subject: [PATCH 2/8] Fix styling --- src/BaseFeatures/Filters/EqualsFilter.php | 30 +++++++++++------------ src/ReportBase.php | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/BaseFeatures/Filters/EqualsFilter.php b/src/BaseFeatures/Filters/EqualsFilter.php index 5a8d7bd..7519dd1 100644 --- a/src/BaseFeatures/Filters/EqualsFilter.php +++ b/src/BaseFeatures/Filters/EqualsFilter.php @@ -14,26 +14,26 @@ class EqualsFilter extends BaseFilter * * @return Builder */ - public function apply(Builder $builder, array $options = []) : Builder - { - if ($this->valueIsDate()) { - $value = Carbon::parse($this->getValue()); + public function apply(Builder $builder, array $options = []) : Builder + { + if ($this->valueIsDate()) { + $value = Carbon::parse($this->getValue()); - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } - $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $value); - $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $value); - $builder = $greaterThanEqual->apply($builder); + $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $value); + $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $value); + $builder = $greaterThanEqual->apply($builder); - return $lessThanEqual->apply($builder); - } + return $lessThanEqual->apply($builder); + } - $action = $this->getAction(); + $action = $this->getAction(); - return $builder->$action($this->getField(), $this->getValue()); - } + return $builder->$action($this->getField(), $this->getValue()); + } /** * @return string diff --git a/src/ReportBase.php b/src/ReportBase.php index a67cf79..8d79691 100644 --- a/src/ReportBase.php +++ b/src/ReportBase.php @@ -485,6 +485,7 @@ public static function rendersFilters(Collection $filterColumns, int $columnsWid public function getMetaData() : array { $encodedData = $this->currentRequest->get('metaData', ''); + return json_decode(base64_decode($encodedData)); } } From 201db693d6817ceb964beeaffc1f1a65bb257ca4 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Mon, 27 Jun 2022 16:54:32 -0700 Subject: [PATCH 3/8] Update filter timezone handling, Other various improvements --- src/BaseFeatures/Filters/EqualsFilter.php | 16 ++++------------ .../Filters/GreaterThanFilter.php | 19 +++++++++++++++++-- .../Filters/GreaterThanOrEqualFilter.php | 18 ++++++++++++++++-- src/BaseFeatures/Filters/LessThanFilter.php | 18 ++++++++++++++++-- .../Filters/LessThanOrEqualFilter.php | 18 ++++++++++++++++-- src/BaseFeatures/Traits/Filterable.php | 8 +++++--- src/ReportBase.php | 2 +- 7 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/BaseFeatures/Filters/EqualsFilter.php b/src/BaseFeatures/Filters/EqualsFilter.php index 7519dd1..81a3b83 100644 --- a/src/BaseFeatures/Filters/EqualsFilter.php +++ b/src/BaseFeatures/Filters/EqualsFilter.php @@ -3,8 +3,6 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; use Illuminate\Database\Query\Builder; -use Illuminate\Support\Arr; -use Illuminate\Support\Carbon; class EqualsFilter extends BaseFilter { @@ -17,17 +15,11 @@ class EqualsFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { if ($this->valueIsDate()) { - $value = Carbon::parse($this->getValue()); + $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $this->getValue()); + $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $this->getValue()); + $builder = $greaterThanEqual->apply($builder, $options); - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } - - $greaterThanEqual = new GreaterThanOrEqualFilter($this->getColumn(), $value); - $lessThanEqual = new LessThanOrEqualFilter($this->getColumn(), $value); - $builder = $greaterThanEqual->apply($builder); - - return $lessThanEqual->apply($builder); + return $lessThanEqual->apply($builder, $options); } $action = $this->getAction(); diff --git a/src/BaseFeatures/Filters/GreaterThanFilter.php b/src/BaseFeatures/Filters/GreaterThanFilter.php index 05211a1..fba2512 100644 --- a/src/BaseFeatures/Filters/GreaterThanFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanFilter.php @@ -2,7 +2,9 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; +use Carbon\Carbon; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Arr; class GreaterThanFilter extends BaseFilter { @@ -15,8 +17,21 @@ class GreaterThanFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); + $value = $this->getValue(); - return $builder->$action($this->getField(), '>', $this->getValue()); + if ($this->valueIsDate()) { + + /** + * @var Carbon $value + */ + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + $value = $value->utc()->toDateTimeString(); + } + + return $builder->$action($this->getField(), '>', $value); } /** @@ -25,7 +40,7 @@ public function apply(Builder $builder, array $options = []) : Builder public function getValue() { if ($this->valueIsDate()) { - return parent::getValue()->endOfDay()->toDateTimeString(); + return parent::getValue()->endOfDay(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php index a730be1..ae055c5 100644 --- a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php @@ -2,7 +2,9 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; +use Carbon\Carbon; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Arr; class GreaterThanOrEqualFilter extends BaseFilter { @@ -15,8 +17,20 @@ class GreaterThanOrEqualFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); + $value = $this->getValue(); - return $builder->$action($this->getField(), '>=', $this->getValue()); + if ($this->valueIsDate()) { + /** + * @var Carbon $value + */ + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + $value = $value->utc()->toDateTimeString(); + } + + return $builder->$action($this->getField(), '>=', $value); } /** @@ -25,7 +39,7 @@ public function apply(Builder $builder, array $options = []) : Builder public function getValue() { if ($this->valueIsDate()) { - return parent::getValue()->startOfDay()->toDateTimeString(); + return parent::getValue()->startOfDay(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/LessThanFilter.php b/src/BaseFeatures/Filters/LessThanFilter.php index 687cda6..d87a1d3 100644 --- a/src/BaseFeatures/Filters/LessThanFilter.php +++ b/src/BaseFeatures/Filters/LessThanFilter.php @@ -2,7 +2,9 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; +use Carbon\Carbon; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Arr; class LessThanFilter extends BaseFilter { @@ -15,8 +17,20 @@ class LessThanFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); + $value = $this->getValue(); - return $builder->$action($this->getField(), '<', $this->getValue()); + if ($this->valueIsDate()) { + /** + * @var Carbon $value + */ + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + $value = $value->utc()->toDateTimeString(); + } + + return $builder->$action($this->getField(), '<', $value); } /** @@ -25,7 +39,7 @@ public function apply(Builder $builder, array $options = []) : Builder public function getValue() { if ($this->valueIsDate()) { - return parent::getValue()->startOfDay()->toDateTimeString(); + return parent::getValue()->startOfDay(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php index 4f0ca59..d24606f 100644 --- a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php @@ -2,7 +2,9 @@ namespace BluefynInternational\ReportEngine\BaseFeatures\Filters; +use Carbon\Carbon; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Arr; class LessThanOrEqualFilter extends BaseFilter { @@ -15,8 +17,20 @@ class LessThanOrEqualFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); + $value = $this->getValue(); - return $builder->$action($this->getField(), '<=', $this->getValue()); + if ($this->valueIsDate()) { + /** + * @var Carbon $value + */ + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + $value = $value->utc()->toDateTimeString(); + } + + return $builder->$action($this->getField(), '<=', $value); } /** @@ -25,7 +39,7 @@ public function apply(Builder $builder, array $options = []) : Builder public function getValue() { if ($this->valueIsDate()) { - return parent::getValue()->addDay()->toDateTimeString(); + return parent::getValue()->endOfDay(); } return parent::getValue(); diff --git a/src/BaseFeatures/Traits/Filterable.php b/src/BaseFeatures/Traits/Filterable.php index b67522c..daa0223 100755 --- a/src/BaseFeatures/Traits/Filterable.php +++ b/src/BaseFeatures/Traits/Filterable.php @@ -21,10 +21,12 @@ trait Filterable */ protected function applyFilters(array $params, Builder $builder) : Builder { + $options = $this->getMetaData(); + $this->getAppliedfilters($params) - ->each(function ($fields) use (&$builder) { - $fields->each(function ($filter) use (&$builder) { - $builder = $this->filter($filter, $builder); + ->each(function ($fields) use ($options, &$builder) { + $fields->each(function ($filter) use ($options, &$builder) { + $builder = $this->filter($filter, $builder, $options); }); }); diff --git a/src/ReportBase.php b/src/ReportBase.php index 8d79691..befb82c 100644 --- a/src/ReportBase.php +++ b/src/ReportBase.php @@ -486,6 +486,6 @@ public function getMetaData() : array { $encodedData = $this->currentRequest->get('metaData', ''); - return json_decode(base64_decode($encodedData)); + return json_decode(json: base64_decode($encodedData), associative: true) ?? []; } } From 30ca5b4843f42ecef0130197a6912e9b9f9e3abb Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Mon, 27 Jun 2022 17:02:45 -0700 Subject: [PATCH 4/8] BaseFilter: Update constructor type hint/annotation --- src/BaseFeatures/Filters/BaseFilter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/BaseFeatures/Filters/BaseFilter.php b/src/BaseFeatures/Filters/BaseFilter.php index fa67d93..bce4f3f 100755 --- a/src/BaseFeatures/Filters/BaseFilter.php +++ b/src/BaseFeatures/Filters/BaseFilter.php @@ -24,10 +24,10 @@ abstract class BaseFilter implements Arrayable /** * BaseFilter constructor. * - * @param Column $column - * @param null $value + * @param Column $column + * @param mixed|null $value */ - public function __construct(Column $column, $value = null) + public function __construct(Column $column, mixed $value = null) { $this->setColumn($column); $this->setValue($value); From 04fa7c3292598d6f464ffb26e79da7d49a8c8038 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Fri, 1 Jul 2022 11:22:39 -0700 Subject: [PATCH 5/8] Move date conversion into getValue functions --- .../Filters/GreaterThanFilter.php | 26 ++++++++----------- .../Filters/GreaterThanOrEqualFilter.php | 25 ++++++++---------- src/BaseFeatures/Filters/LessThanFilter.php | 25 ++++++++---------- .../Filters/LessThanOrEqualFilter.php | 25 ++++++++---------- 4 files changed, 44 insertions(+), 57 deletions(-) diff --git a/src/BaseFeatures/Filters/GreaterThanFilter.php b/src/BaseFeatures/Filters/GreaterThanFilter.php index fba2512..81705b2 100644 --- a/src/BaseFeatures/Filters/GreaterThanFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanFilter.php @@ -17,19 +17,7 @@ class GreaterThanFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); - $value = $this->getValue(); - - if ($this->valueIsDate()) { - - /** - * @var Carbon $value - */ - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } - - $value = $value->utc()->toDateTimeString(); - } + $value = $this->getValue($options); return $builder->$action($this->getField(), '>', $value); } @@ -37,10 +25,18 @@ public function apply(Builder $builder, array $options = []) : Builder /** * @return null|string|mixed */ - public function getValue() + public function getValue(array $options = []) { if ($this->valueIsDate()) { - return parent::getValue()->endOfDay(); + /** + * @var Carbon $value + */ + $value = parent::getValue(); + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + return $value->endOfDay()->utc()->toDateTimeString(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php index ae055c5..45459b2 100644 --- a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php @@ -17,18 +17,7 @@ class GreaterThanOrEqualFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); - $value = $this->getValue(); - - if ($this->valueIsDate()) { - /** - * @var Carbon $value - */ - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } - - $value = $value->utc()->toDateTimeString(); - } + $value = $this->getValue($options); return $builder->$action($this->getField(), '>=', $value); } @@ -36,10 +25,18 @@ public function apply(Builder $builder, array $options = []) : Builder /** * @return null|string */ - public function getValue() + public function getValue(array $options = []) { if ($this->valueIsDate()) { - return parent::getValue()->startOfDay(); + /** + * @var Carbon $value + */ + $value = parent::getValue(); + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + return $value->startOfDay()->utc()->toDateTimeString(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/LessThanFilter.php b/src/BaseFeatures/Filters/LessThanFilter.php index d87a1d3..cc3a372 100644 --- a/src/BaseFeatures/Filters/LessThanFilter.php +++ b/src/BaseFeatures/Filters/LessThanFilter.php @@ -17,18 +17,7 @@ class LessThanFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); - $value = $this->getValue(); - - if ($this->valueIsDate()) { - /** - * @var Carbon $value - */ - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } - - $value = $value->utc()->toDateTimeString(); - } + $value = $this->getValue($options); return $builder->$action($this->getField(), '<', $value); } @@ -36,10 +25,18 @@ public function apply(Builder $builder, array $options = []) : Builder /** * @return null|string */ - public function getValue() + public function getValue(array $options = []) { if ($this->valueIsDate()) { - return parent::getValue()->startOfDay(); + /** + * @var Carbon $value + */ + $value = parent::getValue(); + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + return $value->startOfDay()->utc()->toDateTimeString(); } return parent::getValue(); diff --git a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php index d24606f..8d79057 100644 --- a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php @@ -17,18 +17,7 @@ class LessThanOrEqualFilter extends BaseFilter public function apply(Builder $builder, array $options = []) : Builder { $action = $this->getAction(); - $value = $this->getValue(); - - if ($this->valueIsDate()) { - /** - * @var Carbon $value - */ - if ($timeZoneString = Arr::get($options, 'timezone')) { - $value->shiftTimezone($timeZoneString); - } - - $value = $value->utc()->toDateTimeString(); - } + $value = $this->getValue($options); return $builder->$action($this->getField(), '<=', $value); } @@ -36,10 +25,18 @@ public function apply(Builder $builder, array $options = []) : Builder /** * @return null|string */ - public function getValue() + public function getValue(array $options = []) { if ($this->valueIsDate()) { - return parent::getValue()->endOfDay(); + /** + * @var Carbon $value + */ + $value = parent::getValue(); + if ($timeZoneString = Arr::get($options, 'timezone')) { + $value->shiftTimezone($timeZoneString); + } + + return $value->endOfDay()->utc()->toDateTimeString(); } return parent::getValue(); From 03b3427b9c31f6826bd6eb3710fbce961b128974 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Tue, 5 Jul 2022 17:38:14 -0700 Subject: [PATCH 6/8] DateTime: Allow setting formatter This was previously locked down to datetime --- src/BaseFeatures/Data/Types/DateTime.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/BaseFeatures/Data/Types/DateTime.php b/src/BaseFeatures/Data/Types/DateTime.php index 54c3975..b9fde13 100755 --- a/src/BaseFeatures/Data/Types/DateTime.php +++ b/src/BaseFeatures/Data/Types/DateTime.php @@ -23,6 +23,8 @@ class DateTime extends BaseType protected string $outputFormat = 'L'; + protected ?string $formatter = 'datetime'; + public function __construct( string|null $outputFormat = null, string|null $placeholder = null, @@ -64,7 +66,7 @@ public function setOutputTimezone(string|null $timezone) : self public function formatter(): string { - return 'datetime'; + return $this->formatter; } public function formatterParams(): array From e92f1c4c85c62c4b838003deb052f86c76c306e4 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Fri, 8 Jul 2022 17:08:11 -0700 Subject: [PATCH 7/8] DateTime Filters: Allow column override of timezone --- src/BaseFeatures/Data/Types/DateTime.php | 5 ++++ .../Filters/DoesNotEqualFilter.php | 25 +++++++++++++++++++ .../Filters/GreaterThanFilter.php | 5 +++- .../Filters/GreaterThanOrEqualFilter.php | 5 +++- src/BaseFeatures/Filters/LessThanFilter.php | 5 +++- .../Filters/LessThanOrEqualFilter.php | 5 +++- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/BaseFeatures/Data/Types/DateTime.php b/src/BaseFeatures/Data/Types/DateTime.php index b9fde13..f682f7c 100755 --- a/src/BaseFeatures/Data/Types/DateTime.php +++ b/src/BaseFeatures/Data/Types/DateTime.php @@ -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; diff --git a/src/BaseFeatures/Filters/DoesNotEqualFilter.php b/src/BaseFeatures/Filters/DoesNotEqualFilter.php index 609e033..7a1644c 100644 --- a/src/BaseFeatures/Filters/DoesNotEqualFilter.php +++ b/src/BaseFeatures/Filters/DoesNotEqualFilter.php @@ -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 { @@ -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(); + } } diff --git a/src/BaseFeatures/Filters/GreaterThanFilter.php b/src/BaseFeatures/Filters/GreaterThanFilter.php index 81705b2..d5f894d 100644 --- a/src/BaseFeatures/Filters/GreaterThanFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanFilter.php @@ -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); } diff --git a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php index 45459b2..12f8c40 100644 --- a/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/GreaterThanOrEqualFilter.php @@ -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); } diff --git a/src/BaseFeatures/Filters/LessThanFilter.php b/src/BaseFeatures/Filters/LessThanFilter.php index cc3a372..9767835 100644 --- a/src/BaseFeatures/Filters/LessThanFilter.php +++ b/src/BaseFeatures/Filters/LessThanFilter.php @@ -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); } diff --git a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php index 8d79057..8ccdd20 100644 --- a/src/BaseFeatures/Filters/LessThanOrEqualFilter.php +++ b/src/BaseFeatures/Filters/LessThanOrEqualFilter.php @@ -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); } From a11b65c3d6ad7979873e4f2bc4c3fb95baef1982 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Mon, 11 Jul 2022 10:31:47 -0700 Subject: [PATCH 8/8] DateTime: Fix return type of getOutputTimezone --- src/BaseFeatures/Data/Types/DateTime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseFeatures/Data/Types/DateTime.php b/src/BaseFeatures/Data/Types/DateTime.php index f682f7c..259f633 100755 --- a/src/BaseFeatures/Data/Types/DateTime.php +++ b/src/BaseFeatures/Data/Types/DateTime.php @@ -57,7 +57,7 @@ public function setInputFormat(string|null $format) : self return $this; } - public function getOutputTimezone() : string + public function getOutputTimezone() : ?string { return $this->outputTzName; }