@@ -9,11 +9,12 @@ Validates that a value is a valid timezone identifier (e.g. ``Europe/Paris``).
9
9
10
10
========== ======================================================================
11
11
Applies to :ref: `property or method <validation-property-target >`
12
- Options - `groups `_
12
+ Options - `countryCode `_
13
+ - `groups `_
14
+ - `intlCompatible `_
13
15
- `message `_
14
16
- `payload `_
15
17
- `zone `_
16
- - `countryCode `_
17
18
Class :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Timezone `
18
19
Validator :class: `Symfony\\ Component\\ Validator\\ Constraints\\ TimezoneValidator `
19
20
========== ======================================================================
@@ -22,7 +23,7 @@ Basic Usage
22
23
-----------
23
24
24
25
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 ``):
26
27
27
28
.. configuration-block ::
28
29
@@ -85,8 +86,34 @@ string meant to contain a timezone identifier (e.g. ``America/New_York``):
85
86
Options
86
87
-------
87
88
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
+
88
101
.. include :: /reference/constraints/_groups-option.rst.inc
89
102
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
+
90
117
message
91
118
~~~~~~~
92
119
@@ -131,17 +158,6 @@ In addition, there are some special zone values:
131
158
* ``\DateTimeZone::PER_COUNTRY `` restricts the valid timezones to a certain
132
159
country (which is defined using the ``countryCode `` option).
133
160
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
146
162
.. _`DateTimeZone` : https://www.php.net/datetimezone
147
163
.. _`ISO 3166-1 alpha-2` : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
0 commit comments