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:
committed by
waddlesplash
parent
79ca65ac9d
commit
05d6891800
@@ -5,13 +5,10 @@
|
|||||||
#include "LocaleUtils.h"
|
#include "LocaleUtils.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unicode/datefmt.h>
|
|
||||||
#include <unicode/dtptngen.h>
|
|
||||||
#include <unicode/smpdtfmt.h>
|
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Collator.h>
|
#include <Collator.h>
|
||||||
#include <ICUWrapper.h>
|
#include <DateTimeFormat.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <LocaleRoster.h>
|
#include <LocaleRoster.h>
|
||||||
#include <StringFormat.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
|
/*static*/ BString
|
||||||
LocaleUtils::TimestampToDateTimeString(uint64 millis)
|
LocaleUtils::TimestampToDateTimeString(uint64 millis)
|
||||||
{
|
{
|
||||||
if (millis == 0)
|
if (millis == 0)
|
||||||
return "?";
|
return "?";
|
||||||
|
|
||||||
UnicodeString pattern("yyyy-MM-dd HH:mm:ss");
|
BDateTimeFormat format;
|
||||||
// later use variants of DateFormat::createInstance()
|
BString buffer;
|
||||||
UErrorCode success = U_ZERO_ERROR;
|
if (format.Format(buffer, millis / 1000, B_SHORT_DATE_FORMAT,
|
||||||
SimpleDateFormat sdf(pattern, success);
|
B_SHORT_TIME_FORMAT) != B_OK)
|
||||||
|
|
||||||
if (U_FAILURE(success))
|
|
||||||
return "!";
|
return "!";
|
||||||
|
|
||||||
UnicodeString icuResult;
|
return buffer;
|
||||||
sdf.format((UDate) millis, icuResult);
|
|
||||||
BString result;
|
|
||||||
BStringByteSink converter(&result);
|
|
||||||
icuResult.toUTF8(converter);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user