From f23b9d8a7261881cfa9c4f721de5483c9ce96049 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 16 Aug 2010 15:03:54 +0000 Subject: [PATCH] * 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 --- headers/os/locale/Locale.h | 8 +++++++- src/kits/locale/Locale.cpp | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/headers/os/locale/Locale.h b/headers/os/locale/Locale.h index 915565e12d..a4cbdce90c 100644 --- a/headers/os/locale/Locale.h +++ b/headers/os/locale/Locale.h @@ -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); diff --git a/src/kits/locale/Locale.cpp b/src/kits/locale/Locale.cpp index 07e7a19dd1..2cccd6c7bb 100644 --- a/src/kits/locale/Locale.cpp +++ b/src/kits/locale/Locale.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -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 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);