bool TestExtDatetime::test_date_default_timezone_set() { VERIFY(f_date_default_timezone_set("Asia/Shanghai")); VS(f_date_default_timezone_get(), "Asia/Shanghai"); VERIFY(f_date_default_timezone_set("America/Los_Angeles")); VS(f_date_default_timezone_get(), "America/Los_Angeles"); return Count(true); }
icu::TimeZone* IntlTimeZone::ParseArg(CVarRef arg, const String& funcname, intl_error &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)->timezone()->clone(); } if (auto dtz = objarg.getTyped<c_DateTimeZone>(true, true)) { tzstr = dtz->t_getname(); } else { tzstr = arg.toString(); } } else { tzstr = arg.toString(); } UErrorCode error = U_ZERO_ERROR; icu::UnicodeString id; if (!Intl::ustring_from_char(id, tzstr, error)) { err.code = error; err.custom_error_message = funcname + String(": Time zone identifier given is not a " "valid UTF-8 string", CopyString); return nullptr; } auto ret = icu::TimeZone::createTimeZone(id); if (!ret) { err.code = U_MEMORY_ALLOCATION_ERROR; err.custom_error_message = funcname + String(": could not create time zone", CopyString); return nullptr; } icu::UnicodeString gottenId; if (ret->getID(gottenId) != id) { err.code = U_ILLEGAL_ARGUMENT_ERROR; err.custom_error_message = funcname + String(": no such time zone: '", CopyString) + arg.toString() + "'"; delete ret; return nullptr; } return ret; }
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; }
bool TestExtDatetime::test_date_default_timezone_get() { VS(f_date_default_timezone_get(), "America/Los_Angeles"); return Count(true); }