calendar_class.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | http://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Gustavo Lopes <cataphract@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "../intl_cppshims.h"
  20. #include <unicode/calendar.h>
  21. #include <unicode/gregocal.h>
  22. extern "C" {
  23. #define USE_TIMEZONE_POINTER 1
  24. #include "../timezone/timezone_class.h"
  25. #define USE_CALENDAR_POINTER 1
  26. #include "calendar_class.h"
  27. #include "calendar_methods.h"
  28. #include "gregoriancalendar_methods.h"
  29. #include <zend_exceptions.h>
  30. #include <assert.h>
  31. }
  32. using icu::GregorianCalendar;
  33. using icu::Locale;
  34. /* {{{ Global variables */
  35. zend_class_entry *Calendar_ce_ptr;
  36. zend_class_entry *GregorianCalendar_ce_ptr;
  37. zend_object_handlers Calendar_handlers;
  38. /* }}} */
  39. U_CFUNC void calendar_object_create(zval *object,
  40. Calendar *calendar)
  41. {
  42. UClassID classId = calendar->getDynamicClassID();
  43. zend_class_entry *ce;
  44. //if (dynamic_cast<GregorianCalendar*>(calendar) != NULL) {
  45. if (classId == GregorianCalendar::getStaticClassID()) {
  46. ce = GregorianCalendar_ce_ptr;
  47. } else {
  48. ce = Calendar_ce_ptr;
  49. }
  50. object_init_ex(object, ce);
  51. calendar_object_construct(object, calendar);
  52. }
  53. U_CFUNC Calendar *calendar_fetch_native_calendar(zval *object)
  54. {
  55. Calendar_object *co = Z_INTL_CALENDAR_P(object);
  56. return co->ucal;
  57. }
  58. U_CFUNC void calendar_object_construct(zval *object,
  59. Calendar *calendar)
  60. {
  61. Calendar_object *co;
  62. CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; //populate to from object
  63. assert(co->ucal == NULL);
  64. co->ucal = (Calendar*)calendar;
  65. }
  66. /* {{{ clone handler for Calendar */
  67. static zend_object *Calendar_clone_obj(zval *object)
  68. {
  69. Calendar_object *co_orig,
  70. *co_new;
  71. zend_object *ret_val;
  72. intl_error_reset(NULL);
  73. co_orig = Z_INTL_CALENDAR_P(object);
  74. intl_error_reset(INTL_DATA_ERROR_P(co_orig));
  75. ret_val = Calendar_ce_ptr->create_object(Z_OBJCE_P(object));
  76. co_new = php_intl_calendar_fetch_object(ret_val);
  77. zend_objects_clone_members(&co_new->zo, &co_orig->zo);
  78. if (co_orig->ucal != NULL) {
  79. Calendar *newCalendar;
  80. newCalendar = co_orig->ucal->clone();
  81. if (!newCalendar) {
  82. zend_string *err_msg;
  83. intl_errors_set_code(CALENDAR_ERROR_P(co_orig),
  84. U_MEMORY_ALLOCATION_ERROR);
  85. intl_errors_set_custom_msg(CALENDAR_ERROR_P(co_orig),
  86. "Could not clone IntlCalendar", 0);
  87. err_msg = intl_error_get_message(CALENDAR_ERROR_P(co_orig));
  88. zend_throw_exception(NULL, ZSTR_VAL(err_msg), 0);
  89. zend_string_free(err_msg);
  90. } else {
  91. co_new->ucal = newCalendar;
  92. }
  93. } else {
  94. zend_throw_exception(NULL, "Cannot clone unconstructed IntlCalendar", 0);
  95. }
  96. return ret_val;
  97. }
  98. /* }}} */
  99. static const struct {
  100. UCalendarDateFields field;
  101. const char *name;
  102. } debug_info_fields[] = {
  103. {UCAL_ERA, "era"},
  104. {UCAL_YEAR, "year"},
  105. {UCAL_MONTH, "month"},
  106. {UCAL_WEEK_OF_YEAR, "week of year"},
  107. {UCAL_WEEK_OF_MONTH, "week of month"},
  108. {UCAL_DAY_OF_YEAR, "day of year"},
  109. {UCAL_DAY_OF_MONTH, "day of month"},
  110. {UCAL_DAY_OF_WEEK, "day of week"},
  111. {UCAL_DAY_OF_WEEK_IN_MONTH, "day of week in month"},
  112. {UCAL_AM_PM, "AM/PM"},
  113. {UCAL_HOUR, "hour"},
  114. {UCAL_HOUR_OF_DAY, "hour of day"},
  115. {UCAL_MINUTE, "minute"},
  116. {UCAL_SECOND, "second"},
  117. {UCAL_MILLISECOND, "millisecond"},
  118. {UCAL_ZONE_OFFSET, "zone offset"},
  119. {UCAL_DST_OFFSET, "DST offset"},
  120. {UCAL_YEAR_WOY, "year for week of year"},
  121. {UCAL_DOW_LOCAL, "localized day of week"},
  122. {UCAL_EXTENDED_YEAR, "extended year"},
  123. {UCAL_JULIAN_DAY, "julian day"},
  124. {UCAL_MILLISECONDS_IN_DAY, "milliseconds in day"},
  125. {UCAL_IS_LEAP_MONTH, "is leap month"},
  126. };
  127. /* {{{ get_debug_info handler for Calendar */
  128. static HashTable *Calendar_get_debug_info(zval *object, int *is_temp)
  129. {
  130. zval zv,
  131. zfields;
  132. Calendar_object *co;
  133. const Calendar *cal;
  134. HashTable *debug_info;
  135. *is_temp = 1;
  136. debug_info = zend_new_array(8);
  137. co = Z_INTL_CALENDAR_P(object);
  138. cal = co->ucal;
  139. if (cal == NULL) {
  140. ZVAL_FALSE(&zv);
  141. zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &zv);
  142. return debug_info;
  143. }
  144. ZVAL_TRUE(&zv);
  145. zend_hash_str_update(debug_info, "valid", sizeof("valid") - 1, &zv);
  146. ZVAL_STRING(&zv, const_cast<char*>(cal->getType()));
  147. zend_hash_str_update(debug_info, "type", sizeof("type") - 1, &zv);
  148. {
  149. zval ztz,
  150. ztz_debug;
  151. int is_tmp;
  152. HashTable *debug_info_tz;
  153. timezone_object_construct(&cal->getTimeZone(), &ztz , 0);
  154. debug_info_tz = Z_OBJ_HANDLER(ztz, get_debug_info)(&ztz, &is_tmp);
  155. assert(is_tmp == 1);
  156. array_init(&ztz_debug);
  157. zend_hash_copy(Z_ARRVAL(ztz_debug), debug_info_tz, zval_add_ref);
  158. zend_hash_destroy(debug_info_tz);
  159. FREE_HASHTABLE(debug_info_tz);
  160. zend_hash_str_update(debug_info, "timeZone", sizeof("timeZone") - 1, &ztz_debug);
  161. }
  162. {
  163. UErrorCode uec = U_ZERO_ERROR;
  164. Locale locale = cal->getLocale(ULOC_VALID_LOCALE, uec);
  165. if (U_SUCCESS(uec)) {
  166. ZVAL_STRING(&zv, const_cast<char*>(locale.getName()));
  167. zend_hash_str_update(debug_info, "locale", sizeof("locale") - 1, &zv);
  168. } else {
  169. ZVAL_STRING(&zv, const_cast<char*>(u_errorName(uec)));
  170. zend_hash_str_update(debug_info, "locale", sizeof("locale") - 1, &zv);
  171. }
  172. }
  173. array_init_size(&zfields, UCAL_FIELD_COUNT);
  174. for (int i = 0;
  175. i < sizeof(debug_info_fields) / sizeof(*debug_info_fields);
  176. i++) {
  177. UErrorCode uec = U_ZERO_ERROR;
  178. const char *name = debug_info_fields[i].name;
  179. int32_t res = cal->get(debug_info_fields[i].field, uec);
  180. if (U_SUCCESS(uec)) {
  181. add_assoc_long(&zfields, name, (zend_long)res);
  182. } else {
  183. add_assoc_string(&zfields, name, const_cast<char*>(u_errorName(uec)));
  184. }
  185. }
  186. zend_hash_str_update(debug_info, "fields", sizeof("fields") - 1, &zfields);
  187. return debug_info;
  188. }
  189. /* }}} */
  190. /* {{{ void calendar_object_init(Calendar_object* to)
  191. * Initialize internals of Calendar_object not specific to zend standard objects.
  192. */
  193. static void calendar_object_init(Calendar_object *co)
  194. {
  195. intl_error_init(CALENDAR_ERROR_P(co));
  196. co->ucal = NULL;
  197. }
  198. /* }}} */
  199. /* {{{ Calendar_objects_free */
  200. static void Calendar_objects_free(zend_object *object)
  201. {
  202. Calendar_object* co = php_intl_calendar_fetch_object(object);
  203. if (co->ucal) {
  204. delete co->ucal;
  205. co->ucal = NULL;
  206. }
  207. intl_error_reset(CALENDAR_ERROR_P(co));
  208. zend_object_std_dtor(&co->zo);
  209. }
  210. /* }}} */
  211. /* {{{ Calendar_object_create */
  212. static zend_object *Calendar_object_create(zend_class_entry *ce)
  213. {
  214. Calendar_object* intern;
  215. intern = (Calendar_object*)ecalloc(1, sizeof(Calendar_object) + sizeof(zval) * (ce->default_properties_count - 1));
  216. zend_object_std_init(&intern->zo, ce);
  217. object_properties_init(&intern->zo, ce);
  218. calendar_object_init(intern);
  219. intern->zo.handlers = &Calendar_handlers;
  220. return &intern->zo;
  221. }
  222. /* }}} */
  223. /* {{{ Calendar methods arguments info */
  224. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_void, 0, 0, 0)
  225. ZEND_END_ARG_INFO()
  226. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field, 0, 0, 1)
  227. ZEND_ARG_INFO(0, field)
  228. ZEND_END_ARG_INFO()
  229. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_dow, 0, 0, 1)
  230. ZEND_ARG_INFO(0, dayOfWeek)
  231. ZEND_END_ARG_INFO()
  232. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_other_cal, 0, 0, 1)
  233. ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0)
  234. ZEND_END_ARG_INFO()
  235. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date, 0, 0, 1)
  236. ZEND_ARG_INFO(0, date)
  237. ZEND_END_ARG_INFO()
  238. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_date_optional, 0, 0, 0)
  239. ZEND_ARG_INFO(0, date)
  240. ZEND_END_ARG_INFO()
  241. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_createInstance, 0, 0, 0)
  242. ZEND_ARG_INFO(0, timeZone)
  243. ZEND_ARG_INFO(0, locale)
  244. ZEND_END_ARG_INFO()
  245. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_keyword_values_for_locale, 0, 0, 3)
  246. ZEND_ARG_INFO(0, key)
  247. ZEND_ARG_INFO(0, locale)
  248. ZEND_ARG_INFO(0, commonlyUsed)
  249. ZEND_END_ARG_INFO()
  250. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_add, 0, 0, 2)
  251. ZEND_ARG_INFO(0, field)
  252. ZEND_ARG_INFO(0, amount)
  253. ZEND_END_ARG_INFO()
  254. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setTimeZone, 0, 0, 1)
  255. ZEND_ARG_INFO(0, timeZone)
  256. ZEND_END_ARG_INFO()
  257. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set, 0, 0, 2)
  258. ZEND_ARG_INFO(0, fieldOrYear)
  259. ZEND_ARG_INFO(0, valueOrMonth)
  260. ZEND_ARG_INFO(0, dayOfMonth)
  261. ZEND_ARG_INFO(0, hour)
  262. ZEND_ARG_INFO(0, minute)
  263. ZEND_ARG_INFO(0, second)
  264. ZEND_END_ARG_INFO()
  265. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_roll, 0, 0, 2)
  266. ZEND_ARG_INFO(0, field)
  267. ZEND_ARG_INFO(0, amountOrUpOrDown)
  268. ZEND_END_ARG_INFO()
  269. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_clear, 0, 0, 0)
  270. ZEND_ARG_INFO(0, field)
  271. ZEND_END_ARG_INFO()
  272. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_field_difference, 0, 0, 2)
  273. ZEND_ARG_INFO(0, when)
  274. ZEND_ARG_INFO(0, field)
  275. ZEND_END_ARG_INFO()
  276. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_get_locale, 0, 0, 1)
  277. ZEND_ARG_INFO(0, localeType)
  278. ZEND_END_ARG_INFO()
  279. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_setLenient, 0, 0, 1)
  280. ZEND_ARG_INFO(0, isLenient)
  281. ZEND_END_ARG_INFO()
  282. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_set_minimal_days_in_first_week, 0, 0, 1)
  283. ZEND_ARG_INFO(0, numberOfDays)
  284. ZEND_END_ARG_INFO()
  285. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_from_date_time, 0, 0, 1)
  286. ZEND_ARG_INFO(0, dateTime)
  287. ZEND_END_ARG_INFO()
  288. ZEND_BEGIN_ARG_INFO_EX(ainfo_cal_wall_time_option, 0, 0, 1)
  289. ZEND_ARG_INFO(0, wallTimeOption)
  290. ZEND_END_ARG_INFO()
  291. /* Gregorian Calendar */
  292. ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal___construct, 0, 0, 0)
  293. ZEND_ARG_INFO(0, timeZoneOrYear)
  294. ZEND_ARG_INFO(0, localeOrMonth)
  295. ZEND_ARG_INFO(0, dayOfMonth)
  296. ZEND_ARG_INFO(0, hour)
  297. ZEND_ARG_INFO(0, minute)
  298. ZEND_ARG_INFO(0, second)
  299. ZEND_END_ARG_INFO()
  300. ZEND_BEGIN_ARG_INFO_EX(ainfo_gregcal_isLeapYear, 0, 0, 1)
  301. ZEND_ARG_INFO(0, year)
  302. ZEND_END_ARG_INFO()
  303. /* }}} */
  304. /* {{{ Calendar_class_functions
  305. * Every 'IntlCalendar' class method has an entry in this table
  306. */
  307. static const zend_function_entry Calendar_class_functions[] = {
  308. PHP_ME(IntlCalendar, __construct, ainfo_cal_void, ZEND_ACC_PRIVATE)
  309. PHP_ME_MAPPING(createInstance, intlcal_create_instance, ainfo_cal_createInstance, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  310. #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42
  311. PHP_ME_MAPPING(getKeywordValuesForLocale, intlcal_get_keyword_values_for_locale, ainfo_cal_get_keyword_values_for_locale, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  312. #endif
  313. PHP_ME_MAPPING(getNow, intlcal_get_now, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  314. PHP_ME_MAPPING(getAvailableLocales, intlcal_get_available_locales, ainfo_cal_void, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  315. PHP_ME_MAPPING(get, intlcal_get, ainfo_cal_field, ZEND_ACC_PUBLIC)
  316. PHP_ME_MAPPING(getTime, intlcal_get_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
  317. PHP_ME_MAPPING(setTime, intlcal_set_time, ainfo_cal_date, ZEND_ACC_PUBLIC)
  318. PHP_ME_MAPPING(add, intlcal_add, ainfo_cal_add, ZEND_ACC_PUBLIC)
  319. PHP_ME_MAPPING(setTimeZone, intlcal_set_time_zone, ainfo_cal_setTimeZone, ZEND_ACC_PUBLIC)
  320. PHP_ME_MAPPING(after, intlcal_after, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
  321. PHP_ME_MAPPING(before, intlcal_before, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
  322. PHP_ME_MAPPING(set, intlcal_set, ainfo_cal_set, ZEND_ACC_PUBLIC)
  323. PHP_ME_MAPPING(roll, intlcal_roll, ainfo_cal_roll, ZEND_ACC_PUBLIC)
  324. PHP_ME_MAPPING(clear, intlcal_clear, ainfo_cal_clear, ZEND_ACC_PUBLIC)
  325. PHP_ME_MAPPING(fieldDifference, intlcal_field_difference, ainfo_cal_field_difference, ZEND_ACC_PUBLIC)
  326. PHP_ME_MAPPING(getActualMaximum, intlcal_get_actual_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  327. PHP_ME_MAPPING(getActualMinimum, intlcal_get_actual_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  328. #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
  329. PHP_ME_MAPPING(getDayOfWeekType, intlcal_get_day_of_week_type, ainfo_cal_dow, ZEND_ACC_PUBLIC)
  330. #endif
  331. PHP_ME_MAPPING(getFirstDayOfWeek, intlcal_get_first_day_of_week, ainfo_cal_void, ZEND_ACC_PUBLIC)
  332. PHP_ME_MAPPING(getGreatestMinimum, intlcal_get_greatest_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  333. PHP_ME_MAPPING(getLeastMaximum, intlcal_get_least_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  334. PHP_ME_MAPPING(getLocale, intlcal_get_locale, ainfo_cal_get_locale, ZEND_ACC_PUBLIC)
  335. PHP_ME_MAPPING(getMaximum, intlcal_get_maximum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  336. PHP_ME_MAPPING(getMinimalDaysInFirstWeek, intlcal_get_minimal_days_in_first_week, ainfo_cal_void, ZEND_ACC_PUBLIC)
  337. PHP_ME_MAPPING(getMinimum, intlcal_get_minimum, ainfo_cal_field, ZEND_ACC_PUBLIC)
  338. PHP_ME_MAPPING(getTimeZone, intlcal_get_time_zone, ainfo_cal_void, ZEND_ACC_PUBLIC)
  339. PHP_ME_MAPPING(getType, intlcal_get_type, ainfo_cal_void, ZEND_ACC_PUBLIC)
  340. #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
  341. PHP_ME_MAPPING(getWeekendTransition,intlcal_get_weekend_transition, ainfo_cal_dow, ZEND_ACC_PUBLIC)
  342. #endif
  343. PHP_ME_MAPPING(inDaylightTime, intlcal_in_daylight_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
  344. PHP_ME_MAPPING(isEquivalentTo, intlcal_is_equivalent_to, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
  345. PHP_ME_MAPPING(isLenient, intlcal_is_lenient, ainfo_cal_void, ZEND_ACC_PUBLIC)
  346. PHP_ME_MAPPING(isSet, intlcal_is_set, ainfo_cal_field, ZEND_ACC_PUBLIC)
  347. #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
  348. PHP_ME_MAPPING(isWeekend, intlcal_is_weekend, ainfo_cal_date_optional, ZEND_ACC_PUBLIC)
  349. #endif
  350. PHP_ME_MAPPING(setFirstDayOfWeek, intlcal_set_first_day_of_week, ainfo_cal_dow, ZEND_ACC_PUBLIC)
  351. PHP_ME_MAPPING(setLenient, intlcal_set_lenient, ainfo_cal_setLenient, ZEND_ACC_PUBLIC)
  352. PHP_ME_MAPPING(setMinimalDaysInFirstWeek,intlcal_set_minimal_days_in_first_week,ainfo_cal_set_minimal_days_in_first_week,ZEND_ACC_PUBLIC)
  353. PHP_ME_MAPPING(equals, intlcal_equals, ainfo_cal_other_cal, ZEND_ACC_PUBLIC)
  354. #if U_ICU_VERSION_MAJOR_NUM >= 49
  355. PHP_ME_MAPPING(getRepeatedWallTimeOption,intlcal_get_repeated_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC)
  356. PHP_ME_MAPPING(getSkippedWallTimeOption,intlcal_get_skipped_wall_time_option,ainfo_cal_void, ZEND_ACC_PUBLIC)
  357. PHP_ME_MAPPING(setRepeatedWallTimeOption,intlcal_set_repeated_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
  358. PHP_ME_MAPPING(setSkippedWallTimeOption,intlcal_set_skipped_wall_time_option,ainfo_cal_wall_time_option,ZEND_ACC_PUBLIC)
  359. #endif
  360. PHP_ME_MAPPING(fromDateTime, intlcal_from_date_time, ainfo_cal_from_date_time, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
  361. PHP_ME_MAPPING(toDateTime, intlcal_to_date_time, ainfo_cal_void, ZEND_ACC_PUBLIC)
  362. PHP_ME_MAPPING(getErrorCode, intlcal_get_error_code, ainfo_cal_void, ZEND_ACC_PUBLIC)
  363. PHP_ME_MAPPING(getErrorMessage, intlcal_get_error_message, ainfo_cal_void, ZEND_ACC_PUBLIC)
  364. PHP_FE_END
  365. };
  366. /* }}} */
  367. /* {{{ GregorianCalendar_class_functions
  368. */
  369. static const zend_function_entry GregorianCalendar_class_functions[] = {
  370. PHP_ME(IntlGregorianCalendar, __construct, ainfo_gregcal___construct, ZEND_ACC_PUBLIC)
  371. PHP_ME_MAPPING(setGregorianChange, intlgregcal_set_gregorian_change, ainfo_cal_date, ZEND_ACC_PUBLIC)
  372. PHP_ME_MAPPING(getGregorianChange, intlgregcal_get_gregorian_change, ainfo_cal_void, ZEND_ACC_PUBLIC)
  373. PHP_ME_MAPPING(isLeapYear, intlgregcal_is_leap_year, ainfo_gregcal_isLeapYear, ZEND_ACC_PUBLIC)
  374. PHP_FE_END
  375. };
  376. /* }}} */
  377. /* {{{ calendar_register_IntlCalendar_class
  378. * Initialize 'IntlCalendar' class
  379. */
  380. void calendar_register_IntlCalendar_class(void)
  381. {
  382. zend_class_entry ce;
  383. /* Create and register 'IntlCalendar' class. */
  384. INIT_CLASS_ENTRY(ce, "IntlCalendar", Calendar_class_functions);
  385. ce.create_object = Calendar_object_create;
  386. Calendar_ce_ptr = zend_register_internal_class(&ce);
  387. memcpy( &Calendar_handlers, &std_object_handlers,
  388. sizeof Calendar_handlers);
  389. Calendar_handlers.offset = XtOffsetOf(Calendar_object, zo);
  390. Calendar_handlers.clone_obj = Calendar_clone_obj;
  391. Calendar_handlers.get_debug_info = Calendar_get_debug_info;
  392. Calendar_handlers.free_obj = Calendar_objects_free;
  393. /* Declare 'IntlCalendar' class constants */
  394. #define CALENDAR_DECL_LONG_CONST(name, val) \
  395. zend_declare_class_constant_long(Calendar_ce_ptr, name, sizeof(name) - 1, \
  396. val)
  397. CALENDAR_DECL_LONG_CONST("FIELD_ERA", UCAL_ERA);
  398. CALENDAR_DECL_LONG_CONST("FIELD_YEAR", UCAL_YEAR);
  399. CALENDAR_DECL_LONG_CONST("FIELD_MONTH", UCAL_MONTH);
  400. CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_YEAR", UCAL_WEEK_OF_YEAR);
  401. CALENDAR_DECL_LONG_CONST("FIELD_WEEK_OF_MONTH", UCAL_WEEK_OF_MONTH);
  402. CALENDAR_DECL_LONG_CONST("FIELD_DATE", UCAL_DATE);
  403. CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_YEAR", UCAL_DAY_OF_YEAR);
  404. CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK", UCAL_DAY_OF_WEEK);
  405. CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_WEEK_IN_MONTH", UCAL_DAY_OF_WEEK_IN_MONTH);
  406. CALENDAR_DECL_LONG_CONST("FIELD_AM_PM", UCAL_AM_PM);
  407. CALENDAR_DECL_LONG_CONST("FIELD_HOUR", UCAL_HOUR);
  408. CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY", UCAL_HOUR_OF_DAY);
  409. CALENDAR_DECL_LONG_CONST("FIELD_MINUTE", UCAL_MINUTE);
  410. CALENDAR_DECL_LONG_CONST("FIELD_SECOND", UCAL_SECOND);
  411. CALENDAR_DECL_LONG_CONST("FIELD_MILLISECOND", UCAL_MILLISECOND);
  412. CALENDAR_DECL_LONG_CONST("FIELD_ZONE_OFFSET", UCAL_ZONE_OFFSET);
  413. CALENDAR_DECL_LONG_CONST("FIELD_DST_OFFSET", UCAL_DST_OFFSET);
  414. CALENDAR_DECL_LONG_CONST("FIELD_YEAR_WOY", UCAL_YEAR_WOY);
  415. CALENDAR_DECL_LONG_CONST("FIELD_DOW_LOCAL", UCAL_DOW_LOCAL);
  416. CALENDAR_DECL_LONG_CONST("FIELD_EXTENDED_YEAR", UCAL_EXTENDED_YEAR);
  417. CALENDAR_DECL_LONG_CONST("FIELD_JULIAN_DAY", UCAL_JULIAN_DAY);
  418. CALENDAR_DECL_LONG_CONST("FIELD_MILLISECONDS_IN_DAY", UCAL_MILLISECONDS_IN_DAY);
  419. CALENDAR_DECL_LONG_CONST("FIELD_IS_LEAP_MONTH", UCAL_IS_LEAP_MONTH);
  420. CALENDAR_DECL_LONG_CONST("FIELD_FIELD_COUNT", UCAL_FIELD_COUNT);
  421. CALENDAR_DECL_LONG_CONST("FIELD_DAY_OF_MONTH", UCAL_DAY_OF_MONTH);
  422. CALENDAR_DECL_LONG_CONST("DOW_SUNDAY", UCAL_SUNDAY);
  423. CALENDAR_DECL_LONG_CONST("DOW_MONDAY", UCAL_MONDAY);
  424. CALENDAR_DECL_LONG_CONST("DOW_TUESDAY", UCAL_TUESDAY);
  425. CALENDAR_DECL_LONG_CONST("DOW_WEDNESDAY", UCAL_WEDNESDAY);
  426. CALENDAR_DECL_LONG_CONST("DOW_THURSDAY", UCAL_THURSDAY);
  427. CALENDAR_DECL_LONG_CONST("DOW_FRIDAY", UCAL_FRIDAY);
  428. CALENDAR_DECL_LONG_CONST("DOW_SATURDAY", UCAL_SATURDAY);
  429. #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 44
  430. CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKDAY", UCAL_WEEKDAY);
  431. CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND", UCAL_WEEKEND);
  432. CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_OFFSET", UCAL_WEEKEND_ONSET);
  433. CALENDAR_DECL_LONG_CONST("DOW_TYPE_WEEKEND_CEASE", UCAL_WEEKEND_CEASE);
  434. #endif
  435. #if U_ICU_VERSION_MAJOR_NUM >= 49
  436. CALENDAR_DECL_LONG_CONST("WALLTIME_FIRST", UCAL_WALLTIME_FIRST);
  437. CALENDAR_DECL_LONG_CONST("WALLTIME_LAST", UCAL_WALLTIME_LAST);
  438. CALENDAR_DECL_LONG_CONST("WALLTIME_NEXT_VALID", UCAL_WALLTIME_NEXT_VALID);
  439. #endif
  440. /* Create and register 'IntlGregorianCalendar' class. */
  441. INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", GregorianCalendar_class_functions);
  442. GregorianCalendar_ce_ptr = zend_register_internal_class_ex(&ce,
  443. Calendar_ce_ptr);
  444. }
  445. /* }}} */