static bool intlcal_compare(CObjRef this_, CObjRef that_, UBool (icu::Calendar::*func)(const icu::Calendar&, UErrorCode&) const) { CAL_FETCH(obj1, this_, false); CAL_FETCH(obj2, that_, false); UErrorCode error = U_ZERO_ERROR; UBool res = (obj1->calendar()->*func)(*obj2->calendar(), error); if (U_FAILURE(error)) { obj1->setError(error, "intlcal_before/after: Error calling ICU method"); return false; } return res; }
static Variant intlcal_field_method(CObjRef obj, int64_t field, int32_t (icu::Calendar::*func)(UCalendarDateFields) const, const char *method_name) { CAL_FETCH(data, obj, false); CAL_CHECK_FIELD(field, method_name); return (data->calendar()->*func)((UCalendarDateFields)field); }
// TODO: Switch to AcrRec API once it lands static bool HHVM_METHOD(IntlCalendar, __set_array, CArrRef args) { assert(args.size() == 6); CAL_FETCH(data, this_, false); // Assume at least two args because of PHP signature int32_t numargs; for (numargs = 2; numargs < 6; ++numargs) { if (args[numargs].isNull()) { break; } } if (numargs > 6) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: too many arguments"); return false; } if (numargs == 2) { int32_t field = args[0].toInt64(); CAL_CHECK_FIELD(field, "intcal_set"); data->calendar()->set((UCalendarDateFields)field, (int32_t)args[1].toInt64()); return true; } int32_t intargs[6]; assert(numargs <= 6); for (int i = 0; i < numargs; ++i) { int64_t arg = args[i].toInt64(); if ((arg < INT32_MIN) || (arg > INT32_MAX)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: at least one of the arguments has an " "absolute value that is too large"); return false; } intargs[i] = (int32_t)arg; } switch (numargs) { case 3: // year, month, day data->calendar()->set(intargs[0], intargs[1], intargs[2]); return true; case 4: data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: bad arguments"); return false; case 5: // ..., hour, minute data->calendar()->set(intargs[0], intargs[1], intargs[2], intargs[3], intargs[4]); return true; case 6: // ..., second data->calendar()->set(intargs[0], intargs[1], intargs[2], intargs[3], intargs[4], intargs[5]); return true; default: not_reached(); return false; } }
static bool HHVM_METHOD(IntlCalendar, clear, CVarRef field) { CAL_FETCH(data, this_, false); if (field.isNull()) { data->calendar()->clear(); } else { data->calendar()->clear((UCalendarDateFields)field.toInt64()); } return true; }
static bool HHVM_METHOD(IntlCalendar, setFirstDayOfWeek, int64_t dow) { CAL_FETCH(data, this_, false); if ((dow < UCAL_SUNDAY) || (dow > UCAL_SATURDAY)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_first_day_of_week: invalid day of week"); return false; } data->calendar()->setFirstDayOfWeek((UCalendarDaysOfWeek)dow); return true; }
static bool HHVM_METHOD(IntlCalendar, setTime, CVarRef date) { CAL_FETCH(data, this_, false); UErrorCode error = U_ZERO_ERROR; data->calendar()->setTime((UDate)date.toDouble(), error); if (U_FAILURE(error)) { data->setError(error, "Call to underlying method failed"); return false; } return true; }
static Variant HHVM_METHOD(IntlCalendar, getFirstDayOfWeek) { CAL_FETCH(data, this_, false); UErrorCode error = U_ZERO_ERROR; int64_t ret = data->calendar()->getFirstDayOfWeek(error); if (U_FAILURE(error)) { data->setError(error, "Call to ICU method has failed"); return false; } return ret; }
static bool HHVM_METHOD(IntlCalendar, setSkippedWallTimeOption, int64_t option) { CAL_FETCH(data, this_, false); if ((option != UCAL_WALLTIME_FIRST) && (option != UCAL_WALLTIME_LAST)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_repeated_wall_time_option: invalid option"); return false; } data->calendar()->setSkippedWallTimeOption((UCalendarWallTimeOption)option); return true; }
static bool HHVM_METHOD(IntlCalendar, setTimeZone, const Variant& timeZone) { CAL_FETCH(data, this_, false); auto tz = IntlTimeZone::ParseArg(timeZone, "intlcal_set_time_zone", data); if (!tz) { // error already set return false; } data->calendar()->adoptTimeZone(tz); return true; }
static bool HHVM_METHOD(IntlCalendar, inDaylightTime) { CAL_FETCH(data, this_, false); UErrorCode error = U_ZERO_ERROR; UBool ret = data->calendar()->inDaylightTime(error); if (U_FAILURE(error)) { data->setError(error, "intlcal_in_daylight_time: " "Error calling ICU method"); return false; } return ret; }
static Variant HHVM_METHOD(IntlCalendar, getTime) { CAL_FETCH(data, this_, false); UErrorCode error = U_ZERO_ERROR; UDate ret = data->calendar()->getTime(error); if (U_FAILURE(error)) { data->setError(error, "intlcal_get_time: error calling " "ICU Calendar::getTime"); return false; } return (double)ret; }
static bool HHVM_METHOD(IntlCalendar, setMinimalDaysInFirstWeek, int64_t days) { CAL_FETCH(data, this_, false); if ((days < 1) || (days > 7)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_minimal_days_in_first_week: " "invalid number of days; must be between 1 and 7"); return false; } data->calendar()->setMinimalDaysInFirstWeek((uint8_t)days); return true; }
static bool HHVM_METHOD(IntlCalendar, setTimeZone, CVarRef timeZone) { CAL_FETCH(data, this_, false); intl_error err; auto tz = IntlTimeZone::ParseArg(timeZone, "intlcal_set_time_zone", err); data->setError(err); if (!tz) { // error already set return false; } data->calendar()->adoptTimeZone(tz); return true; }
static Variant intlcal_field_method(CObjRef obj, int64_t field, int32_t (icu::Calendar::*func)(UCalendarDateFields, UErrorCode&) const, const char *method_name) { CAL_FETCH(data, obj, false); CAL_CHECK_FIELD(field, method_name); UErrorCode error = U_ZERO_ERROR; int64_t ret = (data->calendar()->*func)((UCalendarDateFields)field, error); if (U_FAILURE(error)) { data->setError(error, "Call to ICU method has failed"); return false; } return ret; }
static bool HHVM_METHOD(IntlCalendar, isWeekend, CVarRef date) { CAL_FETCH(data, this_, false); if (date.isNull()) { return data->calendar()->isWeekend(); } UErrorCode error = U_ZERO_ERROR; bool ret = data->calendar()->isWeekend((UDate)date.toDouble(), error); if (U_FAILURE(error)) { data->setError(error, "intlcal_is_weekend: Error calling ICU method"); return false; } return ret; }
static Variant HHVM_METHOD(IntlCalendar, fieldDifference, CVarRef when, int64_t field) { CAL_FETCH(data, this_, false); CAL_CHECK_FIELD(field, "intlcal_field_difference"); UErrorCode error = U_ZERO_ERROR; int64_t ret = data->calendar()->fieldDifference( (UDate)when.toDouble(), (UCalendarDateFields)field, error); if (U_FAILURE(error)) { data->setError(error, "intlcal_field_difference: " "Call to ICU method has failed"); return false; } return ret; }
static bool HHVM_METHOD(IntlCalendar, roll, int64_t field, CVarRef value) { CAL_FETCH(data, this_, false); CAL_CHECK_FIELD(field, "intlcal_roll"); UErrorCode error = U_ZERO_ERROR; if (value.isBoolean()) { data->calendar()->roll((UCalendarDateFields)field, (UBool)value.toBoolean(), error); } else { data->calendar()->roll((UCalendarDateFields)field, (int32_t)value.toInt64(), error); } if (U_FAILURE(error)) { data->setError(error, "intlcal_roll: Error calling ICU Calendar::roll"); return false; } return true; }
static Variant HHVM_METHOD(IntlCalendar, getDayOfWeekType, int64_t dow) { CAL_FETCH(data, this_, false); if ((dow < UCAL_SUNDAY) || (dow > UCAL_SATURDAY)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_day_of_week_type: invalid day of week"); return false; } UErrorCode error = U_ZERO_ERROR; int64_t ret = data->calendar()->getDayOfWeekType( (UCalendarDaysOfWeek)dow, error); if (U_FAILURE(error)) { data->setError(error, "intlcal_get_day_of_week_type: " "Call to ICU method has failed"); return false; } return ret; }
static Variant HHVM_METHOD(IntlCalendar, getLocale, int64_t localeType) { CAL_FETCH(data, this_, false); if (localeType != ULOC_ACTUAL_LOCALE && localeType != ULOC_VALID_LOCALE) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_locale: invalid locale type"); return false; } UErrorCode error = U_ZERO_ERROR; icu::Locale locale = data->calendar()->getLocale((ULocDataLocaleType)localeType, error); if (U_FAILURE(error)) { data->setError(error, "intlcal_get_locale: Call to ICU method has failed"); return false; } return String(locale.getName(), CopyString); }
static Variant HHVM_METHOD(IntlCalendar, getWeekendTransition, int64_t dow) { CAL_FETCH(data, this_, false); if ((dow < UCAL_SUNDAY) || (dow > UCAL_SATURDAY)) { data->setError(U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_weekend_transition: " "invalid day of week"); return false; } UErrorCode error = U_ZERO_ERROR; int64_t ret = data->calendar()->getWeekendTransition((UCalendarDaysOfWeek)dow, error); if (U_FAILURE(error)) { data->setError(error, "intlcal_get_weekend_transition: " "Error calling ICU method"); return false; } return ret; }
static Object HHVM_METHOD(IntlCalendar, getTimeZone) { CAL_FETCH(data, this_, null_object); return IntlTimeZone::newInstance( data->calendar()->getTimeZone().clone()); }
static String HHVM_METHOD(IntlCalendar, getErrorMessage) { CAL_FETCH(data, this_, null_string); return data->getErrorMessage(); }
static Variant HHVM_METHOD(IntlCalendar, getType) { CAL_FETCH(data, this_, false); return String(data->calendar()->getType(), CopyString); }
static bool HHVM_METHOD(IntlCalendar, setLenient, bool isLenient) { CAL_FETCH(data, this_, false); data->calendar()->setLenient((UBool)isLenient); return true; }
static bool HHVM_METHOD(IntlCalendar, isLenient) { CAL_FETCH(data, this_, false); return data->calendar()->isLenient(); }
static Variant HHVM_METHOD(IntlCalendar, getMinimalDaysInFirstWeek) { CAL_FETCH(data, this_, false); uint64_t ret = data->calendar()->getMinimalDaysInFirstWeek(); return ret; }
static int64_t HHVM_METHOD(IntlCalendar, getSkippedWallTimeOption) { CAL_FETCH(data, this_, 0); return (int64_t)data->calendar()->getSkippedWallTimeOption(); }
static bool HHVM_METHOD(IntlCalendar, _isSet, int64_t field) { CAL_FETCH(data, this_, false); CAL_CHECK_FIELD(field, "intlcal_is_set"); return data->calendar()->isSet((UCalendarDateFields)field); }
static bool HHVM_METHOD(IntlCalendar, isEquivalentTo, CObjRef other) { CAL_FETCH(obj1, this_, false); CAL_FETCH(obj2, other, false); return obj1->calendar()->isEquivalentTo(*obj2->calendar()); }
static int64_t HHVM_METHOD(IntlCalendar, getErrorCode) { CAL_FETCH(data, this_, 0); return data->getErrorCode(); }