U_CAPI int32_t U_EXPORT2 ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) { int32_t result = 0; TimeZone* zone = _createTimeZone(zoneID, -1, ec); if (U_SUCCESS(*ec)) { SimpleTimeZone* stz = dynamic_cast<SimpleTimeZone*>(zone); if (stz != NULL) { result = stz->getDSTSavings(); } else { // Since there is no getDSTSavings on TimeZone, we use a // heuristic: Starting with the current time, march // forwards for one year, looking for DST savings. // Stepping by weeks is sufficient. UDate d = Calendar::getNow(); for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) { int32_t raw, dst; zone->getOffset(d, FALSE, raw, dst, *ec); if (U_FAILURE(*ec)) { break; } else if (dst != 0) { result = dst; break; } } } } delete zone; return result; }
U_CAPI void U_EXPORT2 ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec) { TimeZone* zone = _createTimeZone(zoneID, -1, ec); if (zone != NULL) { TimeZone::adoptDefault(zone); } }
U_CAPI UCalendar* U_EXPORT2 ucal_open( const UChar* zoneID, int32_t len, const char* locale, UCalendarType caltype, UErrorCode* status) { if(U_FAILURE(*status)) return 0; TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault() : _createTimeZone(zoneID, len, status); if (U_FAILURE(*status)) { return NULL; } if ( caltype == UCAL_GREGORIAN ) { char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY]; if ( locale == NULL ) { locale = uloc_getDefault(); } uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY); uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status); if (U_FAILURE(*status)) { return NULL; } return (UCalendar*)Calendar::createInstance(zone, Locale(localeBuf), *status); } return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status); }
U_CAPI void U_EXPORT2 ucal_setTimeZone( UCalendar* cal, const UChar* zoneID, int32_t len, UErrorCode *status) { if(U_FAILURE(*status)) return; TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault() : _createTimeZone(zoneID, len, status); if (zone != NULL) { ((Calendar*)cal)->adoptTimeZone(zone); } }
// ignore type until we add more subclasses U_CAPI UCalendar* U_EXPORT2 ucal_open( const UChar* zoneID, int32_t len, const char* locale, UCalendarType /*type*/, UErrorCode* status) { if(U_FAILURE(*status)) return 0; TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault() : _createTimeZone(zoneID, len, status); if (U_FAILURE(*status)) { return NULL; } return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status); }