Skip to content

Commit

Permalink
Update docs with new timezone option in sylius.grid_field.datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
coldic3 committed Apr 8, 2024
1 parent 18bb970 commit 451f720
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/field_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ DateTime
This column type works exactly the same way as *string*, but expects
*DateTime* instance and outputs a formatted date and time string.

Available options:
* `format` - default is `Y:m:d H:i:s`, you can modify it with any supported format (see https://www.php.net/manual/en/datetime.format.php)
* `timezone` - default is `%timezone%` parameter, null if such a parameter does not exist, you can modify it with any supported timezone (see https://www.php.net/manual/en/timezones.php)

<details open><summary>Yaml</summary>

```yaml
Expand All @@ -115,7 +119,8 @@ sylius_grid:
type: datetime
label: app.ui.birthday
options:
format: 'Y:m:d H:i:s' # this is the default value, but you can modify it
format: 'Y:m:d H:i:s'
timezone: null
```
</details>
Expand All @@ -133,7 +138,7 @@ use Sylius\Bundle\GridBundle\Config\GridConfig;
return static function (GridConfig $grid): void {
$grid->addGrid(GridBuilder::create('app_user', '%app.model.user.class%')
->addField(
DateTimeField::create('birthday', 'Y:m:d H:i:s') // this format is the default value, but you can modify it
DateTimeField::create('birthday', 'Y:m:d H:i:s', null) // this format and timezone are the default value, but you can modify it
->setLabel('app.ui.birthday')
)
)
Expand Down Expand Up @@ -167,7 +172,7 @@ final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface
{
$gridBuilder
->addField(
DateTimeField::create('birthday', 'Y:m:d H:i:s') // this format is the default value, but you can modify it
DateTimeField::create('birthday', 'Y:m:d H:i:s', null) // this format and timezone are the default value, but you can modify it
->setLabel('app.ui.birthday')
)
;
Expand All @@ -184,13 +189,15 @@ final class UserGrid extends AbstractGrid implements ResourceAwareGridInterface

### *Warning*

You have to pass the `'format'` again if you want to call the `setOptions` function. Otherwise it will be unset:
You have to pass `'format'` and `'timezone'` again if you want to call the `setOptions` function.
Otherwise, it will be unset:

Example:

```php
$field->setOptions([
'format' => 'Y-m-d H:i:s',
'timezone' => 'null'

// Your options here
]);
Expand Down

0 comments on commit 451f720

Please sign in to comment.