* added support for getting the names of a timezone for a specific locale

(not currently used anywhere, but should be part of the BTimeZone interface)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38333 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2010-08-24 15:03:54 +00:00
parent 303ecf89ec
commit 3bdedcf3f1
2 changed files with 68 additions and 13 deletions

View File

@ -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;

View File

@ -12,9 +12,12 @@
#include <new>
#include <unicode/locid.h>
#include <unicode/timezone.h>
#include <ICUWrapper.h>
#include <Locale.h>
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);