* Add a BTimeZone class for handling time zones.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37718 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2010, Haiku, Inc.
|
||||||
|
Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __TIMEZONE_H__
|
||||||
|
#define __TIMEZONE_H__
|
||||||
|
|
||||||
|
|
||||||
|
class BString;
|
||||||
|
namespace icu_44 {
|
||||||
|
class TimeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class BTimeZone {
|
||||||
|
public:
|
||||||
|
BTimeZone(const char* zoneCode);
|
||||||
|
~BTimeZone();
|
||||||
|
|
||||||
|
void Name(BString& name);
|
||||||
|
void Code(BString& code);
|
||||||
|
int OffsetFromGMT();
|
||||||
|
|
||||||
|
private:
|
||||||
|
icu_44::TimeZone* fICUTimeZone;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -11,8 +11,16 @@ local sources =
|
|||||||
Catalog.cpp
|
Catalog.cpp
|
||||||
Collator.cpp
|
Collator.cpp
|
||||||
Country.cpp
|
Country.cpp
|
||||||
Currency.cpp
|
|
||||||
DefaultCatalog.cpp
|
DefaultCatalog.cpp
|
||||||
|
HashMapCatalog.cpp
|
||||||
|
Language.cpp
|
||||||
|
LibbeLocaleBackend.cpp
|
||||||
|
LibraryInit.cpp
|
||||||
|
Locale.cpp
|
||||||
|
LocaleRoster.cpp
|
||||||
|
TimeZone.cpp
|
||||||
|
|
||||||
|
Currency.cpp
|
||||||
FloatFormat.cpp
|
FloatFormat.cpp
|
||||||
FloatFormatImpl.cpp
|
FloatFormatImpl.cpp
|
||||||
FloatFormatParameters.cpp
|
FloatFormatParameters.cpp
|
||||||
@@ -20,16 +28,10 @@ local sources =
|
|||||||
FormatImpl.cpp
|
FormatImpl.cpp
|
||||||
FormatParameters.cpp
|
FormatParameters.cpp
|
||||||
GenericNumberFormat.cpp
|
GenericNumberFormat.cpp
|
||||||
HashMapCatalog.cpp
|
|
||||||
IntegerFormat.cpp
|
IntegerFormat.cpp
|
||||||
IntegerFormatImpl.cpp
|
IntegerFormatImpl.cpp
|
||||||
IntegerFormatParameters.cpp
|
IntegerFormatParameters.cpp
|
||||||
langinfo.cpp
|
langinfo.cpp
|
||||||
Language.cpp
|
|
||||||
LibbeLocaleBackend.cpp
|
|
||||||
LibraryInit.cpp
|
|
||||||
Locale.cpp
|
|
||||||
LocaleRoster.cpp
|
|
||||||
NumberFormat.cpp
|
NumberFormat.cpp
|
||||||
NumberFormatImpl.cpp
|
NumberFormatImpl.cpp
|
||||||
NumberFormatParameters.cpp
|
NumberFormatParameters.cpp
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2010, Adrien Destugues <[email protected]>
|
||||||
|
Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <TimeZone.h>
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <unicode/timezone.h>
|
||||||
|
#include <ICUWrapper.h>
|
||||||
|
|
||||||
|
|
||||||
|
BTimeZone::BTimeZone(const char* zoneCode)
|
||||||
|
{
|
||||||
|
fICUTimeZone = TimeZone::createTimeZone(zoneCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BTimeZone::~BTimeZone()
|
||||||
|
{
|
||||||
|
delete fICUTimeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BTimeZone::Name(BString& name)
|
||||||
|
{
|
||||||
|
UnicodeString unicodeName;
|
||||||
|
fICUTimeZone->getDisplayName(unicodeName);
|
||||||
|
|
||||||
|
BStringByteSink converter(&name);
|
||||||
|
unicodeName.toUTF8(converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BTimeZone::Code(BString& code)
|
||||||
|
{
|
||||||
|
UnicodeString unicodeName;
|
||||||
|
fICUTimeZone->getID(unicodeName);
|
||||||
|
|
||||||
|
BStringByteSink converter(&code);
|
||||||
|
unicodeName.toUTF8(converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
BTimeZone::OffsetFromGMT()
|
||||||
|
{
|
||||||
|
int32_t rawOffset;
|
||||||
|
int32_t dstOffset;
|
||||||
|
time_t now;
|
||||||
|
UErrorCode error = U_ZERO_ERROR;
|
||||||
|
fICUTimeZone->getOffset(time(&now) * 1000, FALSE, rawOffset, dstOffset
|
||||||
|
, error);
|
||||||
|
if (error != U_ZERO_ERROR)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return rawOffset + dstOffset;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user