Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TimezoneValidator.php

function TimezoneValidator::getIntlTimezones

1 call to TimezoneValidator::getIntlTimezones()
TimezoneValidator::validate in vendor/symfony/validator/Constraints/TimezoneValidator.php
Checks if the passed value is valid.

File

vendor/symfony/validator/Constraints/TimezoneValidator.php, line 88

Class

TimezoneValidator
Validates whether a value is a valid timezone identifier.

Namespace

Symfony\Component\Validator\Constraints

Code

private static function getIntlTimezones(int $zone, ?string $countryCode = null) : array {
    if (!class_exists(Timezones::class)) {
        return [];
    }
    if (null !== $countryCode) {
        try {
            return Timezones::forCountryCode($countryCode);
        } catch (MissingResourceException) {
            return [];
        }
    }
    $timezones = Timezones::getIds();
    if (\DateTimeZone::ALL === (\DateTimeZone::ALL & $zone)) {
        return $timezones;
    }
    $filtered = [];
    foreach ((new \ReflectionClass(\DateTimeZone::class))->getConstants() as $const => $flag) {
        if ($flag !== ($flag & $zone)) {
            continue;
        }
        $filtered[] = array_filter($timezones, static fn($id) => 0 === stripos($id, $const . '/'));
    }
    return $filtered ? array_merge(...$filtered) : [];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal