diff --git a/headers/os/locale/TimeZone.h b/headers/os/locale/TimeZone.h index 4b1cf124b0..e2f1194d25 100644 --- a/headers/os/locale/TimeZone.h +++ b/headers/os/locale/TimeZone.h @@ -10,13 +10,16 @@ namespace icu_44 { + class Locale; class TimeZone; } +class BLocale; class BTimeZone { public: - BTimeZone(const char* zoneID = NULL); + BTimeZone(const char* zoneID = NULL, + const BLocale* locale = NULL); BTimeZone(const BTimeZone& other); ~BTimeZone(); @@ -32,12 +35,16 @@ public: status_t InitCheck() const; - status_t SetTo(const char* zoneID); + status_t SetTo(const char* zoneID, + const BLocale* locale = NULL); + + status_t SetLocale(const BLocale* locale); static const char* kNameOfGmtZone; private: icu_44::TimeZone* fIcuTimeZone; + icu_44::Locale* fIcuLocale; status_t fInitStatus; mutable uint32 fInitializedFields; diff --git a/src/kits/locale/TimeZone.cpp b/src/kits/locale/TimeZone.cpp index 16a9227e43..890c78a02e 100644 --- a/src/kits/locale/TimeZone.cpp +++ b/src/kits/locale/TimeZone.cpp @@ -12,9 +12,12 @@ #include +#include #include #include +#include + const char* BTimeZone::kNameOfGmtZone = "GMT"; @@ -33,13 +36,14 @@ static const uint32 skSupportsDaylightSavingField = 1U << 7; static const uint32 skOffsetFromGMTField = 1U << 8; -BTimeZone::BTimeZone(const char* zoneID) +BTimeZone::BTimeZone(const char* zoneID, const BLocale* locale) : fIcuTimeZone(NULL), + fIcuLocale(NULL), fInitStatus(B_NO_INIT), fInitializedFields(0) { - SetTo(zoneID); + SetTo(zoneID, locale); } @@ -48,6 +52,9 @@ BTimeZone::BTimeZone(const BTimeZone& other) fIcuTimeZone(other.fIcuTimeZone == NULL ? NULL : other.fIcuTimeZone->clone()), + fIcuLocale(other.fIcuLocale == NULL + ? NULL + : other.fIcuLocale->clone()), fInitStatus(other.fInitStatus), fInitializedFields(other.fInitializedFields), fZoneID(other.fZoneID), @@ -63,6 +70,7 @@ BTimeZone::BTimeZone(const BTimeZone& other) BTimeZone::~BTimeZone() { + delete fIcuLocale; delete fIcuTimeZone; } @@ -73,6 +81,9 @@ BTimeZone& BTimeZone::operator=(const BTimeZone& source) fIcuTimeZone = source.fIcuTimeZone == NULL ? NULL : source.fIcuTimeZone->clone(); + fIcuLocale = source.fIcuLocale == NULL + ? NULL + : source.fIcuLocale->clone(); fInitStatus = source.fInitStatus; fInitializedFields = source.fInitializedFields; fZoneID = source.fZoneID; @@ -99,8 +110,13 @@ BTimeZone::Name() const { if ((fInitializedFields & skNameField) == 0) { UnicodeString unicodeString; - fIcuTimeZone->getDisplayName(false, TimeZone::GENERIC_LOCATION, - unicodeString); + if (fIcuLocale != NULL) { + fIcuTimeZone->getDisplayName(false, TimeZone::GENERIC_LOCATION, + *fIcuLocale, unicodeString); + } else { + fIcuTimeZone->getDisplayName(false, TimeZone::GENERIC_LOCATION, + unicodeString); + } BStringByteSink sink(&fName); unicodeString.toUTF8(sink); fInitializedFields |= skNameField; @@ -115,8 +131,13 @@ BTimeZone::DaylightSavingName() const { if ((fInitializedFields & skDaylightSavingNameField) == 0) { UnicodeString unicodeString; - fIcuTimeZone->getDisplayName(true, TimeZone::GENERIC_LOCATION, - unicodeString); + if (fIcuLocale != NULL) { + fIcuTimeZone->getDisplayName(true, TimeZone::GENERIC_LOCATION, + *fIcuLocale, unicodeString); + } else { + fIcuTimeZone->getDisplayName(true, TimeZone::GENERIC_LOCATION, + unicodeString); + } BStringByteSink sink(&fDaylightSavingName); unicodeString.toUTF8(sink); fInitializedFields |= skDaylightSavingNameField; @@ -131,8 +152,13 @@ BTimeZone::ShortName() const { if ((fInitializedFields & skShortNameField) == 0) { UnicodeString unicodeString; - fIcuTimeZone->getDisplayName(false, TimeZone::SHORT_COMMONLY_USED, - unicodeString); + if (fIcuLocale != NULL) { + fIcuTimeZone->getDisplayName(false, TimeZone::SHORT_COMMONLY_USED, + *fIcuLocale, unicodeString); + } else { + fIcuTimeZone->getDisplayName(false, TimeZone::SHORT_COMMONLY_USED, + unicodeString); + } BStringByteSink sink(&fShortName); unicodeString.toUTF8(sink); fInitializedFields |= skShortNameField; @@ -147,8 +173,13 @@ BTimeZone::ShortDaylightSavingName() const { if ((fInitializedFields & skShortDaylightSavingNameField) == 0) { UnicodeString unicodeString; - fIcuTimeZone->getDisplayName(true, TimeZone::SHORT_COMMONLY_USED, - unicodeString); + if (fIcuLocale != NULL) { + fIcuTimeZone->getDisplayName(true, TimeZone::SHORT_COMMONLY_USED, + *fIcuLocale, unicodeString); + } else { + fIcuTimeZone->getDisplayName(true, TimeZone::SHORT_COMMONLY_USED, + unicodeString); + } BStringByteSink sink(&fShortDaylightSavingName); unicodeString.toUTF8(sink); fInitializedFields |= skShortDaylightSavingNameField; @@ -201,8 +232,17 @@ BTimeZone::InitCheck() const status_t -BTimeZone::SetTo(const char* zoneID) +BTimeZone::SetLocale(const BLocale* locale) { + return SetTo(fZoneID, locale); +} + + +status_t +BTimeZone::SetTo(const char* zoneID, const BLocale* locale) +{ + delete fIcuLocale; + fIcuLocale = NULL; delete fIcuTimeZone; fInitializedFields = 0; @@ -216,6 +256,14 @@ BTimeZone::SetTo(const char* zoneID) return fInitStatus; } + if (locale != NULL) { + fIcuLocale = new Locale(locale->Code()); + if (fIcuLocale == NULL) { + fInitStatus = B_NO_MEMORY; + return fInitStatus; + } + } + UnicodeString unicodeString; fIcuTimeZone->getID(unicodeString); BStringByteSink sink(&fZoneID);