| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************* | 2 ******************************************************************************* |
| 3 * Copyright (C) 1996-2010, International Business Machines | 3 * Copyright (C) 1996-2010, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
| 5 ******************************************************************************* | 5 ******************************************************************************* |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <typeinfo> // for 'typeid' to work | |
| 9 | 8 |
| 10 #include "unicode/utypes.h" | 9 #include "unicode/utypes.h" |
| 11 | 10 |
| 12 #if !UCONFIG_NO_FORMATTING | 11 #if !UCONFIG_NO_FORMATTING |
| 13 | 12 |
| 14 #include "unicode/ucal.h" | 13 #include "unicode/ucal.h" |
| 15 #include "unicode/uloc.h" | 14 #include "unicode/uloc.h" |
| 16 #include "unicode/calendar.h" | 15 #include "unicode/calendar.h" |
| 17 #include "unicode/timezone.h" | 16 #include "unicode/timezone.h" |
| 18 #include "unicode/gregocal.h" | 17 #include "unicode/gregocal.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (zone != NULL) { | 77 if (zone != NULL) { |
| 79 TimeZone::adoptDefault(zone); | 78 TimeZone::adoptDefault(zone); |
| 80 } | 79 } |
| 81 } | 80 } |
| 82 | 81 |
| 83 U_CAPI int32_t U_EXPORT2 | 82 U_CAPI int32_t U_EXPORT2 |
| 84 ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) { | 83 ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) { |
| 85 int32_t result = 0; | 84 int32_t result = 0; |
| 86 TimeZone* zone = _createTimeZone(zoneID, -1, ec); | 85 TimeZone* zone = _createTimeZone(zoneID, -1, ec); |
| 87 if (U_SUCCESS(*ec)) { | 86 if (U_SUCCESS(*ec)) { |
| 88 SimpleTimeZone* stz = dynamic_cast<SimpleTimeZone*>(zone); | 87 SimpleTimeZone* stz = CR_DYNAMIC_CAST<SimpleTimeZone*>(zone); |
| 89 if (stz != NULL) { | 88 if (stz != NULL) { |
| 90 result = stz->getDSTSavings(); | 89 result = stz->getDSTSavings(); |
| 91 } else { | 90 } else { |
| 92 // Since there is no getDSTSavings on TimeZone, we use a | 91 // Since there is no getDSTSavings on TimeZone, we use a |
| 93 // heuristic: Starting with the current time, march | 92 // heuristic: Starting with the current time, march |
| 94 // forwards for one year, looking for DST savings. | 93 // forwards for one year, looking for DST savings. |
| 95 // Stepping by weeks is sufficient. | 94 // Stepping by weeks is sufficient. |
| 96 UDate d = Calendar::getNow(); | 95 UDate d = Calendar::getNow(); |
| 97 for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) { | 96 for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) { |
| 98 int32_t raw, dst; | 97 int32_t raw, dst; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if(U_FAILURE(*status)) return (UBool) -1; | 239 if(U_FAILURE(*status)) return (UBool) -1; |
| 241 return ((Calendar*)cal)->inDaylightTime(*status); | 240 return ((Calendar*)cal)->inDaylightTime(*status); |
| 242 } | 241 } |
| 243 | 242 |
| 244 U_CAPI void U_EXPORT2 | 243 U_CAPI void U_EXPORT2 |
| 245 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) { | 244 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode) { |
| 246 if(U_FAILURE(*pErrorCode)) { | 245 if(U_FAILURE(*pErrorCode)) { |
| 247 return; | 246 return; |
| 248 } | 247 } |
| 249 Calendar *cpp_cal = (Calendar *)cal; | 248 Calendar *cpp_cal = (Calendar *)cal; |
| 250 GregorianCalendar *gregocal = dynamic_cast<GregorianCalendar *>(cpp_cal); | 249 GregorianCalendar *gregocal = CR_DYNAMIC_CAST<GregorianCalendar *>(cpp_cal); |
| 251 // Not if(gregocal == NULL) { | 250 // Not if(gregocal == NULL) { |
| 252 // because we really want to work only with a GregorianCalendar, not with | 251 // because we really want to work only with a GregorianCalendar, not with |
| 253 // its subclasses like BuddhistCalendar. | 252 // its subclasses like BuddhistCalendar. |
| 254 if(typeid(*cpp_cal) != typeid(GregorianCalendar)) { | 253 // Blindly replacing typeid with CR_TYPEID does not work here. |
| 254 if(CR_TYPEID(*cpp_cal) != GregorianCalendar::getStaticClassID()) { |
| 255 *pErrorCode = U_UNSUPPORTED_ERROR; | 255 *pErrorCode = U_UNSUPPORTED_ERROR; |
| 256 return; | 256 return; |
| 257 } | 257 } |
| 258 gregocal->setGregorianChange(date, *pErrorCode); | 258 gregocal->setGregorianChange(date, *pErrorCode); |
| 259 } | 259 } |
| 260 | 260 |
| 261 U_CAPI UDate U_EXPORT2 | 261 U_CAPI UDate U_EXPORT2 |
| 262 ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode) { | 262 ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode) { |
| 263 if(U_FAILURE(*pErrorCode)) { | 263 if(U_FAILURE(*pErrorCode)) { |
| 264 return (UDate)0; | 264 return (UDate)0; |
| 265 } | 265 } |
| 266 const Calendar *cpp_cal = (const Calendar *)cal; | 266 const Calendar *cpp_cal = (const Calendar *)cal; |
| 267 const GregorianCalendar *gregocal = dynamic_cast<const GregorianCalendar *>(
cpp_cal); | 267 const GregorianCalendar *gregocal = CR_DYNAMIC_CAST<const GregorianCalendar
*>(cpp_cal); |
| 268 // Not if(gregocal == NULL) { | 268 // Not if(gregocal == NULL) { |
| 269 // see comments in ucal_setGregorianChange(). | 269 // see comments in ucal_setGregorianChange(). |
| 270 if(typeid(*cpp_cal) != typeid(GregorianCalendar)) { | 270 // Blindly replacing typeid with CR_TYPEID does not work here. |
| 271 if(CR_TYPEID(*cpp_cal) != GregorianCalendar::getStaticClassID()) { |
| 271 *pErrorCode = U_UNSUPPORTED_ERROR; | 272 *pErrorCode = U_UNSUPPORTED_ERROR; |
| 272 return (UDate)0; | 273 return (UDate)0; |
| 273 } | 274 } |
| 274 return gregocal->getGregorianChange(); | 275 return gregocal->getGregorianChange(); |
| 275 } | 276 } |
| 276 | 277 |
| 277 U_CAPI int32_t U_EXPORT2 | 278 U_CAPI int32_t U_EXPORT2 |
| 278 ucal_getAttribute( const UCalendar* cal, | 279 ucal_getAttribute( const UCalendar* cal, |
| 279 UCalendarAttribute attr) | 280 UCalendarAttribute attr) |
| 280 { | 281 { |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 ulist_deleteList(values); | 679 ulist_deleteList(values); |
| 679 return NULL; | 680 return NULL; |
| 680 } | 681 } |
| 681 ulist_resetList(values); | 682 ulist_resetList(values); |
| 682 memcpy(en, &defaultKeywordValues, sizeof(UEnumeration)); | 683 memcpy(en, &defaultKeywordValues, sizeof(UEnumeration)); |
| 683 en->context = values; | 684 en->context = values; |
| 684 return en; | 685 return en; |
| 685 } | 686 } |
| 686 | 687 |
| 687 #endif /* #if !UCONFIG_NO_FORMATTING */ | 688 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| OLD | NEW |