* added timezone-support to some more date/time-formatting methods in BLocale

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38381 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2010-08-26 22:17:40 +00:00
parent c91aa9f4e6
commit 9ef134d918
2 changed files with 50 additions and 4 deletions

View File

@ -62,7 +62,8 @@ public:
status_t FormatDateTime(char* target, size_t maxSize,
time_t time, bool longFormat);
status_t FormatDateTime(BString* buffer, time_t time,
bool longFormat);
bool longFormat,
const BTimeZone* timeZone = NULL);
// Date
@ -71,7 +72,8 @@ public:
status_t FormatDate(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatDate(BString* string, time_t time,
bool longFormat);
bool longFormat,
const BTimeZone* timeZone = NULL);
status_t FormatDate(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);

View File

@ -164,7 +164,8 @@ BLocale::FormatDate(char* string, size_t maxSize, time_t time, bool longFormat)
status_t
BLocale::FormatDate(BString *string, time_t time, bool longFormat)
BLocale::FormatDate(BString *string, time_t time, bool longFormat,
const BTimeZone* timeZone)
{
string->Truncate(0);
// We make the string empty, this way even in cases where ICU fail we at
@ -174,11 +175,18 @@ BLocale::FormatDate(BString *string, time_t time, bool longFormat)
if (dateFormatter.Get() == NULL)
return B_NO_MEMORY;
if (timeZone != NULL) {
ObjectDeleter<TimeZone> icuTimeZone
= TimeZone::createTimeZone(timeZone->ID().String());
if (icuTimeZone.Get() == NULL)
return B_NO_MEMORY;
dateFormatter->setTimeZone(*icuTimeZone.Get());
}
UnicodeString ICUString;
ICUString = dateFormatter->format((UDate)time * 1000, ICUString);
BStringByteSink stringConverter(string);
ICUString.toUTF8(stringConverter);
return B_OK;
@ -369,6 +377,42 @@ BLocale::FormatDateTime(char* target, size_t maxSize, time_t time,
}
status_t
BLocale::FormatDateTime(BString* target, time_t time, bool longFormat,
const BTimeZone* timeZone)
{
ObjectDeleter<DateFormat> dateFormatter = CreateDateFormat(longFormat,
*fICULocale, longFormat ? fLongDateFormat : fShortDateFormat);
if (dateFormatter.Get() == NULL)
return B_NO_MEMORY;
ObjectDeleter<DateFormat> timeFormatter = CreateTimeFormat(longFormat,
*fICULocale, longFormat ? fLongTimeFormat : fShortTimeFormat);
if (timeFormatter.Get() == NULL)
return B_NO_MEMORY;
if (timeZone != NULL) {
ObjectDeleter<TimeZone> icuTimeZone
= TimeZone::createTimeZone(timeZone->ID().String());
if (icuTimeZone.Get() == NULL)
return B_NO_MEMORY;
timeFormatter->setTimeZone(*icuTimeZone.Get());
}
UnicodeString ICUString;
ICUString = dateFormatter->format((UDate)time * 1000, ICUString);
ICUString.append(UnicodeString::fromUTF8(", "));
ICUString = timeFormatter->format((UDate)time * 1000, ICUString);
BStringByteSink stringConverter(target);
ICUString.toUTF8(stringConverter);
return B_OK;
}
// #pragma mark - Time