/** * Returns the names of the time zones that are known for a specified country. * * If the country's code is not recognized for any reason, the entire list of the known time zone names is * returned. * * @param string $countryCode The two-letter code of the country, as provided by ISO 3166. * * @return CArrayObject The known time zone names for the country specified, of type `CUStringObject`. */ public static function knownNamesForCountry($countryCode) { assert('is_cstring($countryCode)', vs(isset($this), get_defined_vars())); $paNames = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countryCode); $paNames = CMap::filter($paNames, "CTimeZone::isNameIcuCompatible"); $names = CArray::fromPArray($paNames); if (is_cmap($paNames) && !CArray::isEmpty($names)) { return oop_a($names); } else { return oop_a(self::knownNames()); } }
/** * Filters the key-value pairs in a map by calling a function or method on each value and returns a new map with * only those key-value pairs that were let through by the filter. * * The map is not modified by this method. * * @param callable $filter The function or method to be used for filtering. The filter should take a value as a * parameter and return `true` if the corresponding key-value pair should make its way into the resulting map and * `false` if not. * * @return CMapObject The filtered map. */ public function filter($filter) { return self::fromPArray(CMap::filter($this->m_map, $filter)); }
public function testFilter() { $map = ["one" => 1, "two" => 2, "three" => 3, "four" => 4, "five" => 5, "six" => 6, "seven" => 7, "eight" => 8, "nine" => 9, "ten" => 10]; $map = CMap::filter($map, function ($value) { return CMathi::isEven($value); }); $this->assertTrue(CMap::equals($map, ["two" => 2, "four" => 4, "six" => 6, "eight" => 8, "ten" => 10])); }