Move time formatting to BTimeformat.

* Harmonize API for all B*Format to take an output BString by reference
as the first parameter,
* Move the FormatTime methods from BLocale to BTimeFormat
* Adjust all callers for BTimeFormat, BTimeUnitFormat and
BDurationFormat.
This commit is contained in:
Adrien Destugues
2014-10-01 18:13:35 +02:00
parent 0a925409bc
commit 03b2550ef1
22 changed files with 364 additions and 317 deletions
+3 -2
View File
@@ -35,8 +35,9 @@ public:
virtual status_t SetLanguage(const BLanguage& language);
status_t SetTimeZone(const BTimeZone* timeZone);
status_t Format(bigtime_t startValue,
bigtime_t stopValue, BString* buffer,
status_t Format(BString& buffer,
const bigtime_t startValue,
const bigtime_t stopValue,
time_unit_style style = B_TIME_UNIT_FULL
) const;
-21
View File
@@ -69,27 +69,6 @@ public:
BTimeFormatStyle timeStyle,
const BTimeZone* timeZone = NULL) const;
// Time
// TODO: drop some of these once BTimeFormat
// has been implemented!
ssize_t FormatTime(char* string, size_t maxSize,
time_t time, BTimeFormatStyle style) const;
ssize_t FormatTime(char* string, size_t maxSize,
time_t time, BString format) const;
status_t FormatTime(BString* string, time_t time,
BTimeFormatStyle style,
const BTimeZone* timeZone = NULL) const;
status_t FormatTime(BString* string, time_t time,
BString format,
const BTimeZone* timeZone) const;
status_t FormatTime(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, BTimeFormatStyle style) const;
status_t GetTimeFields(BDateElement*& fields,
int& fieldCount, BTimeFormatStyle style
) const;
// numbers
ssize_t FormatNumber(char* string, size_t maxSize,
+28 -7
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010, Haiku, Inc.
* Copyright 2010-2014, Haiku, Inc.
* Distributed under the terms of the MIT Licence.
*/
#ifndef _B_TIME_FORMAT_H_
@@ -9,20 +9,41 @@
class BString;
class BTimeZone;
class BTimeFormat : public BDateTimeFormat {
class BTimeFormat : public BFormat {
public:
BTimeFormat(
const BLanguage* const language = NULL,
const BFormattingConventions* const
format = NULL);
BTimeFormat(const BTimeFormat &other);
virtual ~BTimeFormat();
// formatting
// no-frills version: Simply appends the
// formatted date to the string buffer.
// Can fail only with B_NO_MEMORY or B_BAD_VALUE.
virtual status_t Format(bigtime_t value, BString* buffer) const;
ssize_t Format(char* string, size_t maxSize,
time_t time, BTimeFormatStyle style) const;
ssize_t Format(char* string, size_t maxSize,
time_t time, BString format) const;
status_t Format(BString& string, const time_t time,
const BTimeFormatStyle style,
const BTimeZone* timeZone = NULL) const;
status_t Format(BString& string, const time_t time,
const BString format,
const BTimeZone* timeZone) const;
status_t Format(BString& string,
int*& fieldPositions, int& fieldCount,
time_t time, BTimeFormatStyle style) const;
// TODO: ... basically, all of it!
status_t GetTimeFields(BDateElement*& fields,
int& fieldCount, BTimeFormatStyle style
) const;
// TODO parsing
private:
icu::DateFormat* _CreateTimeFormatter(
const BString& format) const;
};
+3 -2
View File
@@ -47,8 +47,9 @@ public:
BTimeUnitFormat& operator=(const BTimeUnitFormat& other);
virtual status_t SetLanguage(const BLanguage& locale);
status_t Format(int32 value, time_unit_element unit,
BString* buffer,
status_t Format(BString& buffer,
const int32 value,
const time_unit_element unit,
time_unit_style style = B_TIME_UNIT_FULL
) const;