Skip to content

Commit

Permalink
Cast file fieldtype date attributes to carbon instances
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannielsen committed Oct 17, 2024
1 parent 1f8ac0a commit 2ee7952
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3] - 2024-10-17

Expand Down
6 changes: 6 additions & 0 deletions src/Fieldtypes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2ee7952

Please sign in to comment.