Пример #1
0
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;
}
Пример #2
0
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);
}
Пример #3
0
// 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;
  }
}
Пример #4
0
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;
}
Пример #5
0
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;
}
Пример #6
0
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;
}
Пример #7
0
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;
}
Пример #8
0
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;
}
Пример #9
0
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;
}
Пример #10
0
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;
}
Пример #11
0
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;
}
Пример #12
0
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;
}
Пример #13
0
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;
}
Пример #14
0
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;
}
Пример #15
0
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;
}
Пример #16
0
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;
}
Пример #17
0
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;
}
Пример #18
0
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;
}
Пример #19
0
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);
}
Пример #20
0
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;
}
Пример #21
0
static Object HHVM_METHOD(IntlCalendar, getTimeZone) {
  CAL_FETCH(data, this_, null_object);
  return IntlTimeZone::newInstance(
    data->calendar()->getTimeZone().clone());
}
Пример #22
0
static String HHVM_METHOD(IntlCalendar, getErrorMessage) {
  CAL_FETCH(data, this_, null_string);
  return data->getErrorMessage();
}
Пример #23
0
static Variant HHVM_METHOD(IntlCalendar, getType) {
  CAL_FETCH(data, this_, false);
  return String(data->calendar()->getType(), CopyString);
}
Пример #24
0
static bool HHVM_METHOD(IntlCalendar, setLenient, bool isLenient) {
  CAL_FETCH(data, this_, false);
  data->calendar()->setLenient((UBool)isLenient);
  return true;
}
Пример #25
0
static bool HHVM_METHOD(IntlCalendar, isLenient) {
  CAL_FETCH(data, this_, false);
  return data->calendar()->isLenient();
}
Пример #26
0
static Variant HHVM_METHOD(IntlCalendar, getMinimalDaysInFirstWeek) {
  CAL_FETCH(data, this_, false);
  uint64_t ret = data->calendar()->getMinimalDaysInFirstWeek();
  return ret;
}
Пример #27
0
static int64_t HHVM_METHOD(IntlCalendar, getSkippedWallTimeOption) {
  CAL_FETCH(data, this_, 0);
  return (int64_t)data->calendar()->getSkippedWallTimeOption();
}
Пример #28
0
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);
}
Пример #29
0
static bool HHVM_METHOD(IntlCalendar, isEquivalentTo, CObjRef other) {
  CAL_FETCH(obj1, this_, false);
  CAL_FETCH(obj2, other, false);
  return obj1->calendar()->isEquivalentTo(*obj2->calendar());
}
Пример #30
0
static int64_t HHVM_METHOD(IntlCalendar, getErrorCode) {
  CAL_FETCH(data, this_, 0);
  return data->getErrorCode();
}