/*
*******************************************************************************
-* Copyright (C) 1996-2011, International Business Machines
+* Copyright (C) 1996-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
*/
-#include <typeinfo> // for 'typeid' to work
+#include "utypeinfo.h" // for 'typeid' to work
#include "unicode/utypes.h"
#include "unicode/simpletz.h"
#include "unicode/ustring.h"
#include "unicode/strenum.h"
+#include "unicode/localpointer.h"
#include "cmemory.h"
#include "cstring.h"
#include "ustrenum.h"
return zone;
}
+U_CAPI UEnumeration* U_EXPORT2
+ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char* region,
+ const int32_t* rawOffset, UErrorCode* ec) {
+ return uenum_openFromStringEnumeration(TimeZone::createTimeZoneIDEnumeration(
+ zoneType, region, rawOffset, *ec), ec);
+}
+
U_CAPI UEnumeration* U_EXPORT2
ucal_openTimeZones(UErrorCode* ec) {
return uenum_openFromStringEnumeration(TimeZone::createEnumeration(), ec);
}
}
+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,
// Not if(gregocal == NULL) {
// because we really want to work only with a GregorianCalendar, not with
// its subclasses like BuddhistCalendar.
+ if (cpp_cal == NULL) {
+ // We normally don't check "this" pointers for NULL, but this here avoids
+ // compiler-generated exception-throwing code in case cal == NULL.
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return;
+ }
if(typeid(*cpp_cal) != typeid(GregorianCalendar)) {
*pErrorCode = U_UNSUPPORTED_ERROR;
return;
const GregorianCalendar *gregocal = dynamic_cast<const GregorianCalendar *>(cpp_cal);
// Not if(gregocal == NULL) {
// see comments in ucal_setGregorianChange().
+ if (cpp_cal == NULL) {
+ // We normally don't check "this" pointers for NULL, but this here avoids
+ // compiler-generated exception-throwing code in case cal == NULL.
+ *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+ return (UDate)0;
+ }
if(typeid(*cpp_cal) != typeid(GregorianCalendar)) {
*pErrorCode = U_UNSUPPORTED_ERROR;
return (UDate)0;
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
return ((Calendar*)cal)->getMinimalDaysInFirstWeek();
+ case UCAL_REPEATED_WALL_TIME:
+ return ((Calendar*)cal)->getRepeatedWallTimeOption();
+
+ case UCAL_SKIPPED_WALL_TIME:
+ return ((Calendar*)cal)->getSkippedWallTimeOption();
+
default:
break;
}
case UCAL_MINIMAL_DAYS_IN_FIRST_WEEK:
((Calendar*)cal)->setMinimalDaysInFirstWeek((uint8_t)newValue);
break;
+
+ case UCAL_REPEATED_WALL_TIME:
+ ((Calendar*)cal)->setRepeatedWallTimeOption((UCalendarWallTimeOption)newValue);
+ break;
+
+ case UCAL_SKIPPED_WALL_TIME:
+ ((Calendar*)cal)->setSkippedWallTimeOption((UCalendarWallTimeOption)newValue);
+ break;
}
}
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);
+ uloc_addLikelySubtags(locale, loc, sizeof(loc), status);
prefRegionLength = uloc_getCountry(loc, prefRegion, sizeof(prefRegion), status);
}
return en;
}
+U_CAPI UBool U_EXPORT2
+ucal_getTimeZoneTransitionDate(const UCalendar* cal, UTimeZoneTransitionType type,
+ UDate* transition, UErrorCode* status)
+{
+ if (U_FAILURE(*status)) {
+ return FALSE;
+ }
+ UDate base = ((Calendar*)cal)->getTime(*status);
+ const TimeZone& tz = ((Calendar*)cal)->getTimeZone();
+ const BasicTimeZone * btz = dynamic_cast<const BasicTimeZone *>(&tz);
+ if (btz != NULL && U_SUCCESS(*status)) {
+ TimeZoneTransition tzt;
+ UBool inclusive = (type == UCAL_TZ_TRANSITION_NEXT_INCLUSIVE || type == UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE);
+ UBool result = (type == UCAL_TZ_TRANSITION_NEXT || type == UCAL_TZ_TRANSITION_NEXT_INCLUSIVE)?
+ btz->getNextTransition(base, inclusive, tzt):
+ btz->getPreviousTransition(base, inclusive, tzt);
+ if (result) {
+ *transition = tzt.getTime();
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
#endif /* #if !UCONFIG_NO_FORMATTING */