* Add an API to get a formatted time along with delimiters for the differrent fields, for further parsing/formatting
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37514 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -37,13 +37,14 @@ class BCountry {
|
|||||||
|
|
||||||
virtual void FormatDate(char* string, size_t maxSize, time_t time,
|
virtual void FormatDate(char* string, size_t maxSize, time_t time,
|
||||||
bool longFormat);
|
bool longFormat);
|
||||||
virtual void FormatDate(BString* string, time_t time, bool longFormat);
|
virtual void FormatDate(BString* string, time_t time,
|
||||||
|
bool longFormat);
|
||||||
virtual void FormatTime(char* string, size_t maxSize, time_t time,
|
virtual void FormatTime(char* string, size_t maxSize, time_t time,
|
||||||
bool longFormat);
|
bool longFormat);
|
||||||
virtual void FormatTime(BString* string, time_t time,
|
virtual void FormatTime(BString* string, time_t time,
|
||||||
bool longFormat);
|
bool longFormat);
|
||||||
virtual void FormatTime(BString* string, int*& fieldPositions,
|
status_t FormatTime(BString* string, int*& fieldPositions,
|
||||||
int& fieldCount, time_t time);
|
int& fieldCount, time_t time, bool LongFormat);
|
||||||
|
|
||||||
bool DateFormat(BString&, bool longFormat) const;
|
bool DateFormat(BString&, bool longFormat) const;
|
||||||
void SetDateFormat(const char* formatString,
|
void SetDateFormat(const char* formatString,
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <Country.h>
|
#include <Country.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <CalendarView.h>
|
#include <CalendarView.h>
|
||||||
#include <IconUtils.h>
|
#include <IconUtils.h>
|
||||||
@@ -198,12 +200,42 @@ BCountry::FormatTime(BString* string, time_t time, bool longFormat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
status_t
|
||||||
BCountry::FormatTime(BString* string, int*& fieldPositions, int& fieldCount,
|
BCountry::FormatTime(BString* string, int*& fieldPositions, int& fieldCount,
|
||||||
time_t time)
|
time_t time, bool longFormat)
|
||||||
{
|
{
|
||||||
// TODO : this needs ICU 4.4 functions
|
fieldPositions = NULL;
|
||||||
FormatTime(string, time, false);
|
UErrorCode error = U_ZERO_ERROR;
|
||||||
|
ICU_VERSION::DateFormat* timeFormatter;
|
||||||
|
ICU_VERSION::FieldPositionIterator positionIterator;
|
||||||
|
timeFormatter = longFormat ? fICULongTimeFormatter : fICUShortTimeFormatter;
|
||||||
|
UnicodeString ICUString;
|
||||||
|
ICUString = timeFormatter->format((UDate)time * 1000, ICUString,
|
||||||
|
&positionIterator, error);
|
||||||
|
|
||||||
|
if (error != U_ZERO_ERROR)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
ICU_VERSION::FieldPosition field;
|
||||||
|
std::vector<int> fieldPosStorage;
|
||||||
|
fieldCount = 0;
|
||||||
|
while (positionIterator.next(field)) {
|
||||||
|
fieldPosStorage.push_back(field.getBeginIndex());
|
||||||
|
fieldPosStorage.push_back(field.getEndIndex());
|
||||||
|
fieldCount += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldPositions = (int*) malloc(fieldCount * sizeof(int));
|
||||||
|
|
||||||
|
for (int i = 0 ; i < fieldCount ; i++ )
|
||||||
|
fieldPositions[i] = fieldPosStorage[i];
|
||||||
|
|
||||||
|
string->Truncate(0);
|
||||||
|
BStringByteSink stringConverter(string);
|
||||||
|
|
||||||
|
ICUString.toUTF8(stringConverter);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user