8000 minor #12057 [Validation] Documented the intlCompatible option in Tim… · symfony/symfony-docs@c80c38f · GitHub
[go: up one dir, main page]

Skip to content

Commit c80c38f

Browse files
committed
minor #12057 [Validation] Documented the intlCompatible option in Timezone constraint (javiereguiluz)
This PR was squashed before being merged into the 4.3 branch (closes #12057). Discussion ---------- [Validation] Documented the intlCompatible option in Timezone constraint Fixes #11502. In addition to documenting the `intlCompatible` option, it sorts all the options alphabetically, like we always do for constraints. Commits ------- 6440a37 [Validation] Documented the intlCompatible option in Timezone constraint
2 parents 12a07e0 + 6440a37 commit c80c38f

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

components/intl.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ to catching the exception, you can also check if a given currency code is valid:
254254

255255
The ``Currencies`` class was introduced in Symfony 4.3.
256256

257+
.. _component-intl-timezones:
258+
257259
Timezones
258260
~~~~~~~~~
259261

reference/constraints/Timezone.rst

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ Validates that a value is a valid timezone identifier (e.g. ``Europe/Paris``).
99

1010
========== ======================================================================
1111
Applies to :ref:`property or method <validation-property-target>`
12-
Options - `groups`_
12+
Options - `countryCode`_
13+
- `groups`_
14+
- `intlCompatible`_
1315
- `message`_
1416
- `payload`_
1517
- `zone`_
16-
- `countryCode`_
1718
Class :class:`Symfony\\Component\\Validator\\Constraints\\Timezone`
1819
Validator :class:`Symfony\\Component\\Validator\\Constraints\\TimezoneValidator`
1920
========== ======================================================================
@@ -22,7 +23,7 @@ Basic Usage
2223
-----------
2324

2425
Suppose you have a ``UserSettings`` class, with a ``timezone`` field that is a
25-
string meant to contain a timezone identifier (e.g. ``America/New_York``):
26+
string which contains any of the `PHP timezone identifiers`_ (e.g. ``America/New_York``):
2627

2728
.. configuration-block::
2829

@@ -85,8 +86,34 @@ string meant to contain a timezone identifier (e.g. ``America/New_York``):
8586
Options
8687
-------
8788

89+
countryCode
90+
~~~~~~~~~~~
91+
92+
**type**: ``string`` **default**: ``null``
93+
94+
If the ``zone`` option is set to ``\DateTimeZone::PER_COUNTRY``, this option
95+
restricts the valid timezone identifiers to the ones that belong to the given
96+
country.
97+
98+
The value of this option must be a valid `ISO 3166-1 alpha-2`_ country code
99+
(e.g. ``CN`` for China).
100+
88101
.. include:: /reference/constraints/_groups-option.rst.inc
89102

103+
intlCompatible
104+
~~~~~~~~~~~~~~
105+
106+
**type**: ``boolean`` **default**: ``false``
107+
108+
This constraint considers valid both the `PHP timezone identifiers`_ and the
109+
:ref:`ICU timezones <component-intl-timezones>` provided by Symfony's
110+
:doc:`Intl component </components/intl>`
111+
112+
However, the timezones provided by the Intl component can be different from the
113+
timezones provided by PHP's Intl extension (because they use different ICU
114+
versions). If this option is set to ``true``, this constraint only considers
115+
valid the values created with the PHP ``\IntlTimeZone::createTimeZone()`` method.
116+
90117
message
91118
~~~~~~~
92119

@@ -131,17 +158,6 @@ In addition, there are some special zone values:
131158
* ``\DateTimeZone::PER_COUNTRY`` restricts the valid timezones to a certain
132159
country (which is defined using the ``countryCode`` option).
133160

134-
countryCode
135-
~~~~~~~~~~~
136-
137-
**type**: ``string`` **default**: ``null``
138-
139-
If the ``zone`` option is set to ``\DateTimeZone::PER_COUNTRY``, this option
140-
restricts the valid timezone identifiers to the ones that belong to the given
141-
country.
142-
143-
The value of this option must be a valid `ISO 3166-1 alpha-2`_ country code
144-
(e.g. ``CN`` for China).
145-
161+
.. _`PHP timezone identifiers`: https://www.php.net/manual/en/timezones.php
146162
.. _`DateTimeZone`: https://www.php.net/datetimezone
147163
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

0 commit comments

Comments
 (0)
0