@@ -311,6 +311,43 @@ to catching the exception, you can also check if a given currency code is valid:
311
311
312
312
$isValidCurrency = Currencies::exists($currencyCode);
313
313
314
+ If the currencies need to be filtered, there are also helpers to query and
315
+ validate currencies in relation to countries. These methods use ICU metadata
316
+ (``tender ``, ``from `` and ``to `` dates) to determine whether a currency is
317
+ `legal tender `_ and/or active at a given point in time::
318
+
319
+ use Symfony\Component\Intl\Currencies;
320
+
321
+ // Get the list of legal and active currencies for a country (defaults to "today")
322
+ $codes = Currencies::forCountry('FR');
323
+ // ['EUR']
324
+
325
+ // Include non-legal currencies too, and check them at a given date
326
+ $codesAll = Currencies::forCountry(
327
+ 'ES',
328
+ legalTender: null,
329
+ active: true,
330
+ date: new \DateTimeImmutable('1982-01-01')
331
+ );
332
+ // ['ESP', 'ESB']
333
+
334
+ // Validate a currency for a given country
335
+ $isOk = Currencies::isValidInCountry('CH', 'CHF');
336
+ // true
337
+
338
+ // Check if a currency is valid in *any* country on a specific date
339
+ $isGlobal = Currencies::isValidInAnyCountry(
340
+ 'USD',
341
+ legalTender: true,
342
+ active: true,
343
+ date: new \DateTimeImmutable('2005-01-01')
344
+ );
345
+ // true
346
+
347
+ Note that some currencies (especially non-legal-tender ones) do not have validity ranges defined.
348
+ In such cases, a ``RuntimeException `` will be thrown.
349
+ In addition, an ``InvalidArgumentException `` will be thrown if the specified currency is invalid.
350
+
314
351
.. _component-intl-timezones :
315
352
316
353
Timezones
@@ -429,6 +466,7 @@ Learn more
429
466
.. _`ISO 3166-1 alpha-2` : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
430
467
.. _`ISO 3166-1 alpha-3` : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
431
468
.. _`ISO 3166-1 numeric` : https://en.wikipedia.org/wiki/ISO_3166-1_numeric
469
+ .. _`legal tender` : https://en.wikipedia.org/wiki/Legal_tender
432
470
.. _`UTC/GMT time offsets` : https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
433
471
.. _`daylight saving time (DST)` : https://en.wikipedia.org/wiki/Daylight_saving_time
434
472
.. _`ISO 639-1 alpha-2` : https://en.wikipedia.org/wiki/ISO_639-1
0 commit comments