The Bootstrap admin dashboard has to juggle with different date and time formats depending on the situation. Here's how it works.
List of the date, datetime and time formats used in PHP CRUD Generator
Pages | Usage | Language | Format |
---|---|---|---|
READ lists | Human readable date translated according to the user language | PHP with intl extension enabled | ICU * |
READ lists | Human readable date NOT translated | PHP without intl extension enabled | PHP date format ** |
CREATE / UPDATE forms | Datepicker plugins | Javascript | Pickadate plugin formats *** |
PHP Objects | Database date, time and datetime fields | PHP/MySQL | Y-m-d H:i:s |
*ICU - https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details
**PHP date formats list: https://www.php.net/manual/en/function.date.php
***Pickadate date formats list: https://amsul.ca/pickadate.js/date/
The Generator and Admin panel date & time formats
When you set a date / time format in a generator READ list, your choice is stored in internal file (generator/database/phpcg/[your_table].json).
The format stored is the Javascript format
The admin form's date & time pickers will use this format, + an hidden field with a "_submit" suffix to send the values in MySQL date / time format.
The TWIG READ list template will later need to convert the date / time from the MySQL value to the human readable format.
For this purpose, the Javascript format is converted by the generator to PHP ICU by generator/class/generator/TemplatesUtilities.php. The generated PHP ICU format will be passed as argument in the TWIG template to convert the MySQL date / time to the human readable format.
The function is pickerdateToPhpdate($pickerdate)
The item class builds the object value using the PHP/MySQL format (no format conversion)
the READ list TWIG template calls the formatDate($date, $format)
function in vendor/twig/twig/lib/Twig/Extension/CrudTwigExtension.php
The given $date
is in PHP/MySQL format and can be a date, a time or a datetime.
The given $format
is the ICU format.
IntlDateFormatter::formatObject()
using Locale::getDefault()
The datetimes below are generated from a random format using the same logic as the CRUD Generator.