+U_CAPI const char * U_EXPORT2
+ucal_getTZDataVersion(UErrorCode* status)
+{
+ return TimeZone::getTZDataVersion(*status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
+ UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status) {
+ if(status == 0 || U_FAILURE(*status)) {
+ return 0;
+ }
+ if (isSystemID) {
+ *isSystemID = FALSE;
+ }
+ if (id == 0 || len == 0 || result == 0 || resultCapacity <= 0) {
+ *status = U_ILLEGAL_ARGUMENT_ERROR;
+ return 0;
+ }
+ int32_t reslen = 0;
+ UnicodeString canonical;
+ UBool systemID = FALSE;
+ TimeZone::getCanonicalID(UnicodeString(id, len), canonical, systemID, *status);
+ if (U_SUCCESS(*status)) {
+ if (isSystemID) {
+ *isSystemID = systemID;
+ }
+ reslen = canonical.extract(result, resultCapacity, *status);
+ }
+ return reslen;
+}
+
+U_CAPI const char * U_EXPORT2
+ucal_getType(const UCalendar *cal, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return NULL;
+ }
+ return ((Calendar*)cal)->getType();
+}
+
+U_CAPI UCalendarWeekdayType U_EXPORT2
+ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return UCAL_WEEKDAY;
+ }
+ return ((Calendar*)cal)->getDayOfWeekType(dayOfWeek, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return ((Calendar*)cal)->getWeekendTransition(dayOfWeek, *status);
+}
+
+U_CAPI UBool U_EXPORT2
+ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ return ((Calendar*)cal)->isWeekend(date, *status);
+}
+
+U_CAPI int32_t U_EXPORT2
+ucal_getFieldDifference(UCalendar* cal, UDate target,
+ UCalendarDateFields field,
+ UErrorCode* status )
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ return ((Calendar*)cal)->fieldDifference(target, field, *status);
+}
+
+
+static const UEnumeration defaultKeywordValues = {
+ NULL,
+ NULL,
+ ulist_close_keyword_values_iterator,
+ ulist_count_keyword_values,
+ uenum_unextDefault,
+ ulist_next_keyword_value,
+ ulist_reset_keyword_values_iterator
+};
+
+static const char * const CAL_TYPES[] = {
+ "gregorian",
+ "japanese",
+ "buddhist",
+ "roc",
+ "persian",
+ "islamic-civil",
+ "islamic",
+ "hebrew",
+ "chinese",
+ "indian",
+ "coptic",
+ "ethiopic",
+ "ethiopic-amete-alem",
+ NULL
+};
+
+U_CAPI UEnumeration* U_EXPORT2
+ucal_getKeywordValuesForLocale(const char * /* key */, const char* locale, UBool commonlyUsed, UErrorCode *status) {
+ // Resolve region
+ char prefRegion[ULOC_FULLNAME_CAPACITY] = "";
+ int32_t prefRegionLength = 0;
+ prefRegionLength = uloc_getCountry(locale, prefRegion, sizeof(prefRegion), status);
+ if (prefRegionLength == 0) {
+ char loc[ULOC_FULLNAME_CAPACITY] = "";
+ int32_t locLength = 0;
+ locLength = uloc_addLikelySubtags(locale, loc, sizeof(loc), status);
+
+ prefRegionLength = uloc_getCountry(loc, prefRegion, sizeof(prefRegion), status);
+ }
+
+ // Read preferred calendar values from supplementalData calendarPreference
+ UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", status);
+ ures_getByKey(rb, "calendarPreferenceData", rb, status);
+ UResourceBundle *order = ures_getByKey(rb, prefRegion, NULL, status);
+ if (*status == U_MISSING_RESOURCE_ERROR && rb != NULL) {
+ *status = U_ZERO_ERROR;
+ order = ures_getByKey(rb, "001", NULL, status);
+ }
+
+ // Create a list of calendar type strings
+ UList *values = NULL;
+ if (U_SUCCESS(*status)) {
+ values = ulist_createEmptyList(status);
+ if (U_SUCCESS(*status)) {
+ for (int i = 0; i < ures_getSize(order); i++) {
+ int32_t len;
+ const UChar *type = ures_getStringByIndex(order, i, &len, status);
+ char *caltype = (char*)uprv_malloc(len + 1);
+ if (caltype == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ u_UCharsToChars(type, caltype, len);
+ *(caltype + len) = 0;
+
+ ulist_addItemEndList(values, caltype, TRUE, status);
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ }
+
+ if (U_SUCCESS(*status) && !commonlyUsed) {
+ // If not commonlyUsed, add other available values
+ for (int32_t i = 0; CAL_TYPES[i] != NULL; i++) {
+ if (!ulist_containsString(values, CAL_TYPES[i], (int32_t)uprv_strlen(CAL_TYPES[i]))) {
+ ulist_addItemEndList(values, CAL_TYPES[i], FALSE, status);
+ if (U_FAILURE(*status)) {
+ break;
+ }
+ }
+ }
+ }
+ if (U_FAILURE(*status)) {
+ ulist_deleteList(values);
+ values = NULL;
+ }
+ }
+ }
+
+ ures_close(order);
+ ures_close(rb);
+
+ if (U_FAILURE(*status) || values == NULL) {
+ return NULL;
+ }
+
+ // Create string enumeration
+ UEnumeration *en = (UEnumeration*)uprv_malloc(sizeof(UEnumeration));
+ if (en == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ ulist_deleteList(values);
+ return NULL;
+ }
+ ulist_resetList(values);
+ memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
+ en->context = values;
+ return en;
+}
+