diff --git a/CHANGELOG.md b/CHANGELOG.md index 6db8165..523bcaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Timezone argument for GraphQL FormattableDate types + ### Fixed - Bug where integer dates were not handled properly when used as a GraphQL FormattableDate diff --git a/src/Api/Graph/Fields/FormattableDate.php b/src/Api/Graph/Fields/FormattableDate.php index f76b96a..48ed00f 100644 --- a/src/Api/Graph/Fields/FormattableDate.php +++ b/src/Api/Graph/Fields/FormattableDate.php @@ -33,6 +33,11 @@ public function args(): array 'type' => Type::boolean(), 'defaultValue' => false, ], + 'timezone' => [ + 'type' => Type::string(), + 'defaultValue' => null, + 'description' => 'Timezone defaults to UTC. Use "SYSTEM" for the value set in ExpressionEngine', + ], ]; } @@ -48,6 +53,16 @@ protected function resolve($root, array $args): ?string return null; } + if ($args['timezone']) { + if ($args['timezone'] === 'SYSTEM') { + $args['timezone'] = ee()->config->item('default_site_timezone') ?: date_default_timezone_get(); + } + + if (in_array($args['timezone'], \DateTimeZone::listIdentifiers())) { + $date->setTimezone($args['timezone']); + } + } + if ($args['relative']) { return $date->diffForHumans(); }