From 70a57bf254f3375303fac0382493399909f43876 Mon Sep 17 00:00:00 2001 From: Bryan Nielsen Date: Mon, 5 Aug 2024 14:53:37 -0400 Subject: [PATCH] Update graphql formattable date field to handle integer dates --- CHANGELOG.md | 4 ++++ src/Api/Graph/Fields/FormattableDate.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d076f63..6db8165 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Bug where integer dates were not handled properly when used as a GraphQL FormattableDate + ## [1.3.2] - 2024-07-03 ### Fixed diff --git a/src/Api/Graph/Fields/FormattableDate.php b/src/Api/Graph/Fields/FormattableDate.php index 96d64e5..f76b96a 100644 --- a/src/Api/Graph/Fields/FormattableDate.php +++ b/src/Api/Graph/Fields/FormattableDate.php @@ -40,6 +40,10 @@ protected function resolve($root, array $args): ?string { $date = $root->{$this->getProperty()}; + if (is_int($date) && $date !== 0) { + $date = \Carbon\Carbon::createFromTimestamp($date); + } + if (! $date instanceof \Carbon\Carbon) { return null; }