static Variant HHVM_STATIC_METHOD(IntlTimeZone, getCanonicalID, const String& zoneId, VRefParam isSystemID) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, zoneId, error)) { s_intl_error->set(error, "intltz_get_canonical_id: could not convert " "time zone id to UTF-16"); return false; } icu::UnicodeString result; UBool system; error = U_ZERO_ERROR; icu::TimeZone::getCanonicalID(id, result, system, error); if (U_FAILURE(error)) { s_intl_error->set(error, "intltz_get_canonical_id: " "error obtaining canonical ID"); return false; } isSystemID = (bool)system; error = U_ZERO_ERROR; String ret(u8(result, error)); if (U_FAILURE(error)) { s_intl_error->set(error, "intltz_get_canonical_id: could not convert " "time zone id to UTF-8"); return false; } return ret; }
static Variant HHVM_STATIC_METHOD(IntlTimeZone, countEquivalentIDs, const String& zoneId) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, zoneId, error)) { s_intl_error->set(error, "intltz_count_equivalent_ids: could not convert " "time zone id to UTF-16"); return false; } return icu::TimeZone::countEquivalentIDs(id); }
static Object HHVM_STATIC_METHOD(IntlTimeZone, createTimeZone, const String& zoneId) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, zoneId, error)) { s_intl_error->set(error, "intltz_count_equivalent_ids: could not convert " "time zone id to UTF-16"); return null_object; } return IntlTimeZone::newInstance(icu::TimeZone::createTimeZone(id)); }
icu::TimeZone* IntlTimeZone::ParseArg(const Variant& arg, const String& funcname, IntlError* err) { String tzstr; if (arg.isNull()) { tzstr = f_date_default_timezone_get(); } else if (arg.isObject()) { auto objarg = arg.toObject(); auto cls = objarg->getVMClass(); auto IntlTimeZone_Class = Unit::lookupClass(s_IntlTimeZone.get()); if (IntlTimeZone_Class && ((cls == IntlTimeZone_Class) || cls->classof(IntlTimeZone_Class))) { return IntlTimeZone::Get(objarg.get())->timezone()->clone(); } if (objarg.instanceof(DateTimeZoneData::getClass())) { auto* dtz = Native::data<DateTimeZoneData>(objarg.get()); tzstr = dtz->getName(); } else { tzstr = arg.toString(); } } else { tzstr = arg.toString(); } UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, tzstr, error)) { err->setError(error, "%s: Time zone identifier given is not a " "valid UTF-8 string", funcname.c_str()); return nullptr; } auto ret = icu::TimeZone::createTimeZone(id); if (!ret) { err->setError(U_MEMORY_ALLOCATION_ERROR, "%s: could not create time zone", funcname.c_str()); return nullptr; } icu::UnicodeString gottenId; if (ret->getID(gottenId) != id) { err->setError(U_ILLEGAL_ARGUMENT_ERROR, "%s: no such time zone: '%s'", funcname.c_str(), arg.toString().c_str()); delete ret; return nullptr; } return ret; }
static Variant HHVM_STATIC_METHOD(IntlTimeZone, getRegion, const String& str) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, str, error)) { s_intl_error->set(error, "intltz_get_region: could not convert " "time zone id to UTF-16"); return false; } char outbuf[3]; error = U_ZERO_ERROR; int32_t len = icu::TimeZone::getRegion(id, outbuf, sizeof(outbuf), error); if (U_FAILURE(error)) { s_intl_error->set(error, "intltz_get_region: Error obtaining region"); return false; } return String(outbuf, len, CopyString); }
static Variant HHVM_STATIC_METHOD(IntlTimeZone, getEquivalentID, const String& zoneId, int64_t index) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!ustring_from_char(id, zoneId, error)) { s_intl_error->set(error, "intltz_get_canonical_id: could not convert " "time zone id to UTF-16"); return false; } auto result = icu::TimeZone::getEquivalentID(id, (int32_t)index); error = U_ZERO_ERROR; String ret(u8(result, error)); if (U_FAILURE(error)) { s_intl_error->set(error, "intltz_get_equivalent_id: " "could not convert resulting time zone id " "to UTF-16"); return false; } return ret; }