From 56b749d2057ead99e63c7db84c1aaddb49dd7db5 Mon Sep 17 00:00:00 2001 From: Bryan Nielsen Date: Thu, 10 Oct 2024 13:05:00 -0400 Subject: [PATCH] Cast file fieldtype date attributes to carbon instances --- CHANGELOG.md | 1 + src/Fieldtypes/File.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea7dc0..96306e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Default url for ExpressionEngine Control Panel is now `admin` instead of `admin.php`. This can be changed in `config/coilpack.php`. - TemplateOutput now implements the [Stringable](https://www.php.net/manual/en/class.stringable.php) interface - GraphQL query signature for the Range Slider Fieldtype to support querying `value`, `from`, and `to` fields +- Cast File fieldtype's date attributes to Carbon instances for easier manipulation and display ## [1.4.2] - 2024-09-26 diff --git a/src/Fieldtypes/File.php b/src/Fieldtypes/File.php index d1eb34a..20d9ba6 100644 --- a/src/Fieldtypes/File.php +++ b/src/Fieldtypes/File.php @@ -23,6 +23,12 @@ public function apply(FieldContent $content, array $parameters = []) $string = $handler->_wrap_it($data, $parameters['wrap'], $data['path'].$data['filename'].'.'.$data['extension']); } + $dates = ['upload_date', 'modified_date']; + + foreach($dates as $date) { + $data[$date] = (is_int($data[$date])) ? \Carbon\Carbon::createFromTimestamp($data[$date]) : $data[$date]; + } + return FieldtypeOutput::for($this)->value($data)->string($string); }