/*
*******************************************************************************
-* Copyright (C) 1996-2012, International Business Machines
+* Copyright (C) 1996-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
}
}
+U_CAPI int32_t U_EXPORT2
+ucal_getTimeZoneID(const UCalendar *cal,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status)
+{
+ if (U_FAILURE(*status)) {
+ return 0;
+ }
+ const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
+ UnicodeString id;
+ tz.getID(id);
+ return id.extract(result, resultLength, *status);
+}
+
U_CAPI int32_t U_EXPORT2
ucal_getTimeZoneDisplayName(const UCalendar* cal,
UCalendarDisplayNameType type,
/*
*******************************************************************************
- * Copyright (C) 1996-2012, International Business Machines Corporation and
+ * Copyright (C) 1996-2013, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
int32_t len,
UErrorCode* status);
+/**
+ * Get the ID of the UCalendar's time zone.
+ *
+ * @param cal The UCalendar to query.
+ * @param result Receives the UCalendar's time zone ID.
+ * @param resultLength The maximum size of result.
+ * @param status Receives the status.
+ * @return The total buffer size needed; if greater than resultLength, the output was truncated.
+ * @draft ICU 51
+ */
+U_DRAFT int32_t U_EXPORT2
+ucal_getTimeZoneID(const UCalendar *cal,
+ UChar *result,
+ int32_t resultLength,
+ UErrorCode *status);
+
/**
* Possible formats for a UCalendar's display name
* @stable ICU 2.0
/********************************************************************
- * Copyright (c) 1997-2012, International Business Machines
+ * Copyright (c) 1997-2013, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************
*
UChar temp[30];
double testMillis;
int32_t dateBit;
+ UChar id[4];
+ int32_t idLen;
log_verbose("\nOpening the calendars()\n");
u_strcpy(tzID, fgGMTID);
log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status));
return;
}
-
/*Testing getMillis and setMillis */
log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
ctest_setTimeZone(NULL, &status);
- /*testing ucal_setTimeZone() function*/
- log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
+ /*testing ucal_setTimeZone() and ucal_getTimeZoneID function*/
+ log_verbose("\nTesting if the function ucal_setTimeZone() and ucal_getTimeZoneID work fine\n");
+ idLen = ucal_getTimeZoneID(caldef2, id, sizeof(id)/sizeof(id[0]), &status);
+ if (U_FAILURE(status)) {
+ log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
+ } else if (u_strcmp(id, fgGMTID) != 0) {
+ log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id), austrdup(fgGMTID));
+ } else {
+ log_verbose("PASS: getTimeZoneID works fine\n");
+ }
+
ucal_setMillis(caldef2, d2, &status);
if(U_FAILURE(status)){
- log_err("Error in getMillis : %s\n", u_errorName(status));;
+ log_err("Error in getMillis : %s\n", u_errorName(status));
}
hour=ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status);
}
else
log_verbose("ucal_setTimeZone worked fine\n");
+
+ idLen = ucal_getTimeZoneID(caldef2, id, sizeof(id)/sizeof(id[0]), &status);
+ if (U_FAILURE(status)) {
+ log_err("Error in getTimeZoneID : %s\n", u_errorName(status));
+ } else if (u_strcmp(id, tzID) != 0) {
+ log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id), austrdup(tzID));
+ } else {
+ log_verbose("PASS: getTimeZoneID works fine\n");
+ }
+
if(hour == ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status))
log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
else if((hour-8 + 1) != ucal_get(caldef2, UCAL_HOUR_OF_DAY, &status)) /*because it is not in daylight savings time */