HaikuDepot: do not use ICU directly.

Change-Id: I0097fe51cc9b41509e5ba0d2452c5f28eac0538a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2724
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Adrien Destugues
2020-05-17 16:00:53 +00:00
committed by waddlesplash
parent 79ca65ac9d
commit 05d6891800
+6 -27
View File
@@ -5,13 +5,10 @@
#include "LocaleUtils.h"
#include <stdlib.h>
#include <unicode/datefmt.h>
#include <unicode/dtptngen.h>
#include <unicode/smpdtfmt.h>
#include <Catalog.h>
#include <Collator.h>
#include <ICUWrapper.h>
#include <DateTimeFormat.h>
#include <Locale.h>
#include <LocaleRoster.h>
#include <StringFormat.h>
@@ -48,37 +45,19 @@ LocaleUtils::GetCollator(BCollator* collator)
}
/*! There was some difficulty in getting BDateTime and friends to
work for the purposes of this application. Data comes in as millis since
the epoc relative to GMT0. These need to be displayed in the local time
zone, but the timezone aspect never seems to be quite right with BDateTime!
For now, to avoid this work over-spilling into a debug of the date-time
classes in Haiku, I am adding this method that uses ICU directly in order
to get something basic working for now. Later this should be migrated to
use the BDateTime etc... classes from Haiku once these problems have been
ironed out.
*/
/*static*/ BString
LocaleUtils::TimestampToDateTimeString(uint64 millis)
{
if (millis == 0)
return "?";
UnicodeString pattern("yyyy-MM-dd HH:mm:ss");
// later use variants of DateFormat::createInstance()
UErrorCode success = U_ZERO_ERROR;
SimpleDateFormat sdf(pattern, success);
if (U_FAILURE(success))
BDateTimeFormat format;
BString buffer;
if (format.Format(buffer, millis / 1000, B_SHORT_DATE_FORMAT,
B_SHORT_TIME_FORMAT) != B_OK)
return "!";
UnicodeString icuResult;
sdf.format((UDate) millis, icuResult);
BString result;
BStringByteSink converter(&result);
icuResult.toUTF8(converter);
return result;
return buffer;
}