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