* 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:
parent
c91aa9f4e6
commit
9ef134d918
@ -62,7 +62,8 @@ public:
|
|||||||
status_t FormatDateTime(char* target, size_t maxSize,
|
status_t FormatDateTime(char* target, size_t maxSize,
|
||||||
time_t time, bool longFormat);
|
time_t time, bool longFormat);
|
||||||
status_t FormatDateTime(BString* buffer, time_t time,
|
status_t FormatDateTime(BString* buffer, time_t time,
|
||||||
bool longFormat);
|
bool longFormat,
|
||||||
|
const BTimeZone* timeZone = NULL);
|
||||||
|
|
||||||
// Date
|
// Date
|
||||||
|
|
||||||
@ -71,7 +72,8 @@ public:
|
|||||||
status_t FormatDate(char* string, size_t maxSize,
|
status_t FormatDate(char* string, size_t maxSize,
|
||||||
time_t time, bool longFormat);
|
time_t time, bool longFormat);
|
||||||
status_t FormatDate(BString* string, time_t time,
|
status_t FormatDate(BString* string, time_t time,
|
||||||
bool longFormat);
|
bool longFormat,
|
||||||
|
const BTimeZone* timeZone = NULL);
|
||||||
status_t FormatDate(BString* string,
|
status_t FormatDate(BString* string,
|
||||||
int*& fieldPositions, int& fieldCount,
|
int*& fieldPositions, int& fieldCount,
|
||||||
time_t time, bool longFormat);
|
time_t time, bool longFormat);
|
||||||
|
@ -164,7 +164,8 @@ BLocale::FormatDate(char* string, size_t maxSize, time_t time, bool longFormat)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
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);
|
string->Truncate(0);
|
||||||
// We make the string empty, this way even in cases where ICU fail we at
|
// 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)
|
if (dateFormatter.Get() == NULL)
|
||||||
return B_NO_MEMORY;
|
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;
|
UnicodeString ICUString;
|
||||||
ICUString = dateFormatter->format((UDate)time * 1000, ICUString);
|
ICUString = dateFormatter->format((UDate)time * 1000, ICUString);
|
||||||
|
|
||||||
BStringByteSink stringConverter(string);
|
BStringByteSink stringConverter(string);
|
||||||
|
|
||||||
ICUString.toUTF8(stringConverter);
|
ICUString.toUTF8(stringConverter);
|
||||||
|
|
||||||
return B_OK;
|
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
|
// #pragma mark - Time
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user