From 635df643527f1c43faacdec5bfec86b12768e68a Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 7 Apr 2012 20:44:39 +0200 Subject: [PATCH] Add BLocaleRoster::GetAvailableTimeZonesWithRegionInfo() * allow locale kit clients to get all timezones with their corresponding country/region ID piecemeal --- headers/os/locale/LocaleRoster.h | 2 ++ src/kits/locale/LocaleRoster.cpp | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index 0bff1b1b0d..8e77e597e8 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -45,6 +45,8 @@ public: BMessage* timeZones) const; status_t GetAvailableTimeZones( BMessage* timeZones) const; + status_t GetAvailableTimeZonesWithRegionInfo( + BMessage* timeZonesWithRegonInfo) const; status_t GetAvailableTimeZonesForCountry( BMessage* message, const char* countryCode) const; diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 8f3f0b194b..3874e6b543 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -279,6 +279,47 @@ BLocaleRoster::GetAvailableTimeZones(BMessage* timeZones) const } +status_t +BLocaleRoster::GetAvailableTimeZonesWithRegionInfo(BMessage* timeZones) const +{ + if (!timeZones) + return B_BAD_VALUE; + + status_t status = B_OK; + + UErrorCode icuStatus = U_ZERO_ERROR; + + StringEnumeration* zoneList = TimeZone::createTimeZoneIDEnumeration( + UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, icuStatus); + + int32 count = zoneList->count(icuStatus); + if (U_SUCCESS(icuStatus)) { + for (int i = 0; i < count; ++i) { + const char* zoneID = zoneList->next(NULL, icuStatus); + if (zoneID == NULL || !U_SUCCESS(icuStatus)) { + status = B_ERROR; + break; + } + timeZones->AddString("timeZone", zoneID); + + char region[5]; + icuStatus = U_ZERO_ERROR; + TimeZone::getRegion(zoneID, region, 5, icuStatus); + if (!U_SUCCESS(icuStatus)) { + status = B_ERROR; + break; + } + timeZones->AddString("region", region); + } + } else + status = B_ERROR; + + delete zoneList; + + return status; +} + + status_t BLocaleRoster::GetAvailableTimeZonesForCountry(BMessage* timeZones, const char* countryCode) const