* added possibility to pass in the timezone when formatting the time

* added TODOs about the need to get rid of some of the date/time-formatting
  shortcut methods

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38146 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-08-16 15:03:54 +00:00
parent 3f2a18bd30
commit f23b9d8a72
2 changed files with 18 additions and 2 deletions
+7 -1
View File
@@ -13,6 +13,7 @@
class BCatalog;
class BString;
class BTimeZone;
class BLocale {
@@ -46,6 +47,8 @@ public:
// Date
// TODO: drop some of these once BDateFormat
// has been implemented!
status_t FormatDate(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatDate(BString* string, time_t time,
@@ -63,10 +66,13 @@ public:
// Time
// TODO: drop some of these once BTimeFormat
// has been implemented!
status_t FormatTime(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatTime(BString* string, time_t time,
bool longFormat);
bool longFormat,
const BTimeZone* timeZone = NULL);
status_t FormatTime(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);
+11 -1
View File
@@ -9,6 +9,7 @@
#include <Catalog.h>
#include <Locale.h>
#include <LocaleRoster.h>
#include <TimeZone.h>
#include <unicode/datefmt.h>
#include <unicode/dcfmtsym.h>
@@ -393,7 +394,8 @@ BLocale::FormatTime(char* string, size_t maxSize, time_t time, bool longFormat)
status_t
BLocale::FormatTime(BString* string, time_t time, bool longFormat)
BLocale::FormatTime(BString* string, time_t time, bool longFormat,
const BTimeZone* timeZone)
{
string->Truncate(0);
@@ -402,6 +404,14 @@ BLocale::FormatTime(BString* string, time_t time, bool longFormat)
if (timeFormatter.Get() == NULL)
return B_NO_MEMORY;
if (timeZone != NULL) {
ObjectDeleter<TimeZone> icuTimeZone
= TimeZone::createTimeZone(timeZone->Code().String());
if (icuTimeZone.Get() == NULL)
return B_NO_MEMORY;
timeFormatter->setTimeZone(*icuTimeZone.Get());
}
UnicodeString ICUString;
ICUString = timeFormatter->format((UDate)time * 1000, ICUString);