Repository: EasyCorp/EasyAdminBundle (language: php)

Issue:
Can not set CRUD's default date/time format to a localized one for DateField and DateTimeField
**Describe the bug**
By default, the `\EasyCorp\Bundle\EasyAdminBundle\Dto\CrudDto::$datePattern` field uses the `medium` value which is in use by the `\EasyCorp\Bundle\EasyAdminBundle\Field\Configurator\DateTimeConfigurator::configure()` method. This date format uses the current locale to format the date by `\IntlDateFormatter::format()`. The only way I can influence the default date format is to call `\EasyCorp\Bundle\EasyAdminBundle\Config\Crud::setDateFormat()` in the `configureCrud` method. But inside the `setDateFormat` method, values `full`, `medium`, `short` are converted to predefined formats so localized formats can not longer be used as default ones. I have to configure the format in each field individually or invent my own field only for changing the default format. Fields are final and not extensible. This way is too weird.

I would be happy to avoid this line in the `\EasyCorp\Bundle\EasyAdminBundle\Config\Crud::setDateFormat()` method and use localized default formats like `short`, `medium`, `full`:

```php
        $datePattern = DateTimeField::INTL_DATE_PATTERNS[$formatOrPattern] ?? $formatOrPattern;
```

The array converts the localized format value to a predefined one breaking date localization support:

```php
    public const INTL_DATE_PATTERNS = [
        self::FORMAT_FULL => 'EEEE, MMMM d, y',
        self::FORMAT_LONG => 'MMMM d, y',
        self::FORMAT_MEDIUM => 'MMM d, y',
        self::FORMAT_SHORT => 'M/d/yy',
        self::FORMAT_NONE => '',
    ];
```


Discussion / hints:
I don't understand this issue report 😐 

The line you highlighted https://github.com/EasyCorp/EasyAdminBundle/blob/bb6ae0c3d3fa4c0dd2ca5778810f63ba86e106b3/src/Config/Crud.php#L148 ensures that you can use your own custom format in addition to the predefined patterns.

In #6393 I added some tests for date/time related methods in `Crud` config class to ensure that it behaves as expected.
@javiereguiluz The issue is that I want to pass the `short` format string down to the `Intl` formatter. But I can't do that because this value is replaced by the hardcoded US format. The `short` format value is a valid format for the `Intl` formatter but it is currently NOT possible to use it.
Now I understand the issue. Let me think about this and I'll try to submit a new PR.

Fix patch:
diff --git a/src/Config/Crud.php b/src/Config/Crud.php
index 1a93d7e758..e176f1c017 100644
--- a/src/Config/Crud.php
+++ b/src/Config/Crud.php
@@ -145,8 +145,7 @@ public function setDateFormat(string $formatOrPattern): self
             throw new \InvalidArgumentException(sprintf('The first argument of the "%s()" method cannot be "%s" or an empty string. Use either the special date formats (%s) or a datetime Intl pattern.', __METHOD__, DateTimeField::FORMAT_NONE, implode(', ', $validDateFormatsWithoutNone)));
         }
 
-        $datePattern = DateTimeField::INTL_DATE_PATTERNS[$formatOrPattern] ?? $formatOrPattern;
-        $this->dto->setDatePattern($datePattern);
+        $this->dto->setDatePattern($formatOrPattern);
 
         return $this;
     }
@@ -165,8 +164,7 @@ public function setTimeFormat(string $formatOrPattern): self
             throw new \InvalidArgumentException(sprintf('The first argument of the "%s()" method cannot be "%s" or an empty string. Use either the special time formats (%s) or a datetime Intl pattern.', __METHOD__, DateTimeField::FORMAT_NONE, implode(', ', $validTimeFormatsWithoutNone)));
         }
 
-        $timePattern = DateTimeField::INTL_TIME_PATTERNS[$formatOrPattern] ?? $formatOrPattern;
-        $this->dto->setTimePattern($timePattern);
+        $this->dto->setTimePattern($formatOrPattern);
 
         return $this;
     }
diff --git a/src/Field/DateTimeField.php b/src/Field/DateTimeField.php
index 4d573d0773..a4f8faaccd 100644
--- a/src/Field/DateTimeField.php
+++ b/src/Field/DateTimeField.php
@@ -21,6 +21,7 @@ final class DateTimeField implements FieldInterface
 
     public const VALID_DATE_FORMATS = [self::FORMAT_NONE, self::FORMAT_SHORT, self::FORMAT_MEDIUM, self::FORMAT_LONG, self::FORMAT_FULL];
 
+    /** @deprecated since EasyAdmin 4.11.1. We no longer transform the format names (e.g. 'short') into its pattern (e.g. 'M/d/yy'). We now pass the original format/pattern as is to the IntlFormatter to properly format it according to the current locale */
     public const INTL_DATE_PATTERNS = [
         self::FORMAT_FULL => 'EEEE, MMMM d, y',
         self::FORMAT_LONG => 'MMMM d, y',
@@ -29,6 +30,7 @@ final class DateTimeField implements FieldInterface
         self::FORMAT_NONE => '',
     ];
 
+    /** @deprecated since EasyAdmin 4.11.1. We no longer transform the format names (e.g. 'short') into its pattern (e.g. 'h:mm a'). We now pass the original format/pattern as is to the IntlFormatter to properly format it according to the current locale */
     public const INTL_TIME_PATTERNS = [
         self::FORMAT_FULL => 'h:mm:ss a zzzz',
         self::FORMAT_LONG => 'h:mm:ss a z',


Test patch:
diff --git a/tests/Config/CrudTest.php b/tests/Config/CrudTest.php
index 12fce102cf..6081482f33 100644
--- a/tests/Config/CrudTest.php
+++ b/tests/Config/CrudTest.php
@@ -60,21 +60,23 @@ public function testSetDecimalSeparator(string $separator)
     }
 
     /**
-     * @testWith ["short", "M/d/yy"]
-     *           ["medium", "MMM d, y"]
-     *           ["long", "MMMM d, y"]
-     *           ["full", "EEEE, MMMM d, y"]
-     *           ["EEEE", "EEEE"]
-     *           ["MMMM/d, EEEE", "MMMM/d, EEEE"]
-     *           // the following invalid format is used on purpose to test that the method accept any custom format
-     *           ["this is wrong", "this is wrong"]
+     * @testWith ["short"]
+     *           ["medium"]
+     *           ["long"]
+     *           ["full"]
+     *           // custom time pattern
+     *           ["EEEE"]
+     *           // custom time pattern
+     *           ["MMMM/d, EEEE"]
+     *           // invalid value used on purpose to test that the method accepts any custom pattern/format
+     *           ["this is wrong"]
      */
-    public function testSetDateFormat(string $dateFormat, string $parsedFormat)
+    public function testSetDateFormat(string $dateFormat)
     {
         $crudConfig = Crud::new();
         $crudConfig->setDateFormat($dateFormat);
 
-        $this->assertSame($parsedFormat, $crudConfig->getAsDto()->getDatePattern());
+        $this->assertSame($dateFormat, $crudConfig->getAsDto()->getDatePattern());
     }
 
     /**
@@ -90,21 +92,23 @@ public function testSetDateFormatWithInvalidFormat(string $dateFormat)
     }
 
     /**
-     * @testWith ["short", "h:mm a"]
-     *           ["medium", "h:mm:ss a"]
-     *           ["long", "h:mm:ss a z"]
-     *           ["full", "h:mm:ss a zzzz"]
-     *           ["zzzz", "zzzz"]
-     *           ["ss, a, mm", "ss, a, mm"]
-     *           // the following invalid format is used on purpose to test that the method accept any custom format
-     *           ["this is wrong", "this is wrong"]
+     * @testWith ["short"]
+     *           ["medium"]
+     *           ["long"]
+     *           ["full"]
+     *           // custom time pattern
+     *           ["zzzz"]
+     *           // custom time pattern
+     *           ["ss, a, mm"]
+     *           // invalid value used on purpose to test that the method accepts any custom pattern/format
+     *           ["this is wrong"]
      */
-    public function testSetTimeFormat(string $timeFormat, string $parsedFormat)
+    public function testSetTimeFormat(string $timeFormat)
     {
         $crudConfig = Crud::new();
         $crudConfig->setTimeFormat($timeFormat);
 
-        $this->assertSame($parsedFormat, $crudConfig->getAsDto()->getTimePattern());
+        $this->assertSame($timeFormat, $crudConfig->getAsDto()->getTimePattern());
     }
 
     /**
@@ -145,7 +149,7 @@ public function testSetTimeFormatWithInvalidFormat(string $timeFormat)
      *           ["full", "long"]
      *           ["full", "full"]
      *           ["MMMM/d, EEEE ss, a, mm", "none"]
-     *           // the following invalid formats are used on purpose to test that the method accept any custom formats
+     *           // the following invalid value are used on purpose to test that the method accepts any custom formats/patterns
      *           ["this is wrong", "this is wrong"]
      */
     public function testSetDateTimeFormat(string $dateFormat, string $timeFormat)