Log message #4265895

# At Username Text
# Jun 20th 2021, 12:51 kevin.pfeifer so datetime fields for e.g. created and modified should be saved in UTC (therefore looking into the database via sql cli or phpmyadmin should show UTC values). But where in cakephp (in a multilingual setup) do I have to add the logic to show different formats and/or timezones? Is there a guide somewhere?
# Jun 20th 2021, 12:46 slackebot1 required, even if it's more work. I never not ran into a hot steaming pile of trouble when doing timezone conversions for saving/reading.
# Jun 20th 2021, 12:46 slackebot1 imagine that this can make things extra annoying :) `TIMESTAMP` is converted from server/connection timezone to UTC on save, and from UTC to server/connection timezone on read (this is what the datasource config timezone would be used for). As always when this topic comes up, I'd like to mention that from my personal experience, I can only suggest to go UTC all the way, and convert to specific timezones on PHP/frontend level when
# Jun 20th 2021, 12:46 ndm @kevin.pfeifer `DATETIME` columns can hold a timezone offset (not a timezone name) as of MySQL 8. CakePHP accepts such formats even for the default `DateTimeType` class, but it won't save it like that, only the `DateTimeTimezoneType` does, which however isn't automatically mapped. Also MySQL will not return the offset when doing a select, instead it will return the date with the offset subtracted. I haven't tried it yet, but I could
# Jun 20th 2021, 10:36 kevin.pfeifer i guess i am mixing up the `datetime` mysql field with the `timestamp` field timestamp is always utc, datetime can "save" timezones
# Jun 20th 2021, 10:31 kevin.pfeifer As far as I know there are • the timezone the data is saved in the database (in a datetime column, or is this always UTC?) • the timezone setting present in the datasource config (which should be the same as the data saved in the database as far as I know) • the `setToStringFormat` from above • and there are view helpers as well to change the format for php datetime objects
# Jun 20th 2021, 10:20 dereuromark localized output vs default (code/iso) output
# Jun 20th 2021, 10:20 kevin.pfeifer Guess I have to go a bit deeper here to fully understand where date formats (and maybe timezones as well( are present and can/should be changed
# Jun 20th 2021, 10:18 kevin.pfeifer I am sorry but what do you mean by "both" here?
# Jun 20th 2021, 10:14 dereuromark at least when local date format != code one
# Jun 20th 2021, 10:13 dereuromark because you are using it for both (which works, but is maybe not the best idea)
# Jun 20th 2021, 10:10 kevin.pfeifer but then why does the `setToStringFormat` work for me without that helper?
# Jun 20th 2021, 09:43 dereuromark most bake templates have that properly built in, though, https://github.com/dereuromark/cakephp-setup/blob/master/templates/bake/Template/view.twig#L95 etc
# Jun 20th 2021, 09:42 dereuromark the string casting default format is mainly for code output (e.g. in json formatting)
# Jun 20th 2021, 09:39 dereuromark if you want to format it, you should use Time helper here
# Jun 20th 2021, 04:45 alamnaryab In view `<td><?= h($entityRow->created) ?></td>`
# Jun 19th 2021, 23:59 greg138 They are being formatted incorrectly in your views? If so, please show an example of how you are outputting it. Or it's formatted incorrectly in the data (e.g. entities) you're loading from the database?
# Jun 19th 2021, 21:18 kevin.pfeifer well one thing I can tell you is the fact, that your datetime output above is ISO8601 (which I guess is the default format being outputted by cakephp)
# Jun 19th 2021, 21:04 alamnaryab yes, it is default ar, I have multilangual site but datetime I need in `yyy-MM-dd HH:mm:ss` format from database fields
# Jun 19th 2021, 20:58 kevin.pfeifer have you set your `App.defaultLocale` to something special in your `config/app_local.php` (or the `config/.env` file if you are using it)
# Jun 19th 2021, 20:52 alamnaryab yes
# Jun 19th 2021, 20:50 kevin.pfeifer so like the outputted `$entity->created` datetime in your frontend didn’t change?
# Jun 19th 2021, 20:46 alamnaryab I wrote this at end of bootstrap.php ``` Time::setToStringFormat('HH:mm:ss'); FrozenTime::setToStringFormat('HH:mm:ss'); Date::setToStringFormat('yyyy-MM-dd HH:mm:ss'); FrozenDate::setToStringFormat('yyyy-MM-dd HH:mm:ss'); ``` but still date from database is showing like `2015-09-26T18:58:40+04:00`
# Jun 19th 2021, 20:30 kevin.pfeifer but be aware if you want to set the date format yourself (not using the preconfigured constants) with something like `'Y-m-d H:i:s'` because these “letters” are not your typically PHP date variables. Instead this is used here: http://userguide.icu-project.org/formatparse/datetime
# Jun 19th 2021, 20:25 kevin.pfeifer this should be added to your `config/bootstrap.php` at the bottom
# Jun 19th 2021, 20:23 kevin.pfeifer https://book.cakephp.org/4/en/core-libraries/time.html#setting-the-default-locale-and-format-string
# Jun 19th 2021, 20:15 alamnaryab Using Cakephp 4 what is better way to change dateformat, datetimeformat at project level?
# Jun 19th 2021, 18:51 admad yes
# Jun 19th 2021, 18:46 angelxmoreno @admad did i get that right ?
# Jun 19th 2021, 18:46 angelxmoreno @kupe3b the issue is for the instructions being bad. You should still have `$this->addPlugin('Authentication');` in your Application.php file.
# Jun 19th 2021, 03:14 admad You should open an issue on the repo.
# Jun 19th 2021, 03:13 admad No
# Jun 19th 2021, 03:13 kupe3b so i dont need to add anything in bootstrap.php?
# Jun 19th 2021, 03:12 admad @kupe3b those docs are outdated.
# Jun 19th 2021, 01:41 kupe3b if i type `bin/cake plugin load pluginname` it adds `$this->addPlugin('Authentication');` in Application.php, but reading the CakeDC Users plugin i see beside addPlugin in Application.pht it also instructs adding ` ```Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);``` in bootstrap.php so i'm cofused. why do i have to add plugin twice? what is this needed?
# Jun 18th 2021, 20:35 japerlman it's because my fields are pascalCase it looks, I made a new table in all lower case and it works perfectly
# Jun 18th 2021, 19:42 japerlman PATCH url of http://x.x.x.x/roles/3
# Jun 18th 2021, 19:42 japerlman ```{ "data": { "type": "roles", "id": "3", "attributes": { "roleDescription": "My new name" } } }```
# Jun 18th 2021, 19:41 japerlman I have the json api accepting my PATCH requests now and it's returning a '200' but it's not actually updating the field in the DB with the new value, any thoughts? I've looked through the docs at https://crud-json-api.readthedocs.io/en/latest/ a few times now and it seems like my json data is valid/correct.
# Jun 18th 2021, 18:49 kevin.pfeifer well if you are happy with a search result like neon1024 explained above sure, go for that
# Jun 18th 2021, 18:40 alamnaryab @admad this datatype specification worked as I am dynamically populating conditions array, so I have made every fields string.