Variant HHVM_STATIC_METHOD(DateTimeZone, listIdentifiers, int64_t what, const String& country) { Array all = TimeZone::GetNamesToCountryCodes(); // This is the same check that PHP5 performs, no validation needed. // See ext/date/php_date.c lines 4496-4499 if (what == q_DateTimeZone$$PER_COUNTRY && country.length() != 2) { raise_notice("A two-letter ISO 3166-1 compatible country code is expected"); return false; } Array result = Array::Create(); for (ArrayIter iter(all); iter; ++iter) { const Variant& tzid = iter.first(); const Variant& tzcountry = iter.second(); if (what == q_DateTimeZone$$PER_COUNTRY && equal(country, tzcountry)) { result.append(tzid); } else if (what == q_DateTimeZone$$ALL_WITH_BC || check_id_allowed(tzid.toStrNR(), what)) { result.append(tzid); } } return result; }
Variant HHVM_STATIC_METHOD(DateTimeZone, listIdentifiers, int64_t what, const String& country) { // This is the same check that PHP5 performs, no validation needed. // See ext/date/php_date.c lines 4496-4499 if (what == DateTimeZoneData::PER_COUNTRY && country.length() != 2) { raise_notice("A two-letter ISO 3166-1 compatible country code is expected"); return false; } const timelib_tzdb *tzdb = timezone_get_builtin_tzdb(); int item_count = tzdb->index_size; const timelib_tzdb_index_entry *table = tzdb->index; Array ret = Array::Create(); for (int i = 0; i < item_count; ++i) { // This string is what PHP considers as "data" or "info" which is basically // the string of "PHP1xx" where xx is country code that uses this timezone. // When country code is unknown or not in use anymore, ?? is used instead. // There is no known better way to extract this information out. const char* infoString = (const char*)&tzdb->data[table[i].pos]; String countryCode = String(&infoString[5], 2, CopyString); if ((what == DateTimeZoneData::PER_COUNTRY && equal(country, countryCode)) || what == DateTimeZoneData::ALL_WITH_BC || (check_id_allowed(table[i].id, what) && tzdb->data[table[i].pos + 4] == '\1')) { ret.append(String(table[i].id, CopyString)); } } return ret; }