Reimplement BDateTimeFormat using ICU support
* Avoid hardcoding the format to "date, time" * Allows using DateTimePatternGenerator to create custom formats from a set of fields.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <DateTime.h>
|
||||
#include <DateTimeFormat.h>
|
||||
#include <Format.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
@@ -22,17 +23,6 @@ class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
enum BDateElement {
|
||||
B_DATE_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_DATE_ELEMENT_YEAR = 0,
|
||||
B_DATE_ELEMENT_MONTH,
|
||||
B_DATE_ELEMENT_DAY,
|
||||
B_DATE_ELEMENT_AM_PM,
|
||||
B_DATE_ELEMENT_HOUR,
|
||||
B_DATE_ELEMENT_MINUTE,
|
||||
B_DATE_ELEMENT_SECOND
|
||||
};
|
||||
|
||||
enum BWeekday {
|
||||
B_WEEKDAY_MONDAY = 1,
|
||||
B_WEEKDAY_TUESDAY,
|
||||
|
||||
@@ -6,21 +6,42 @@
|
||||
#define _B_DATE_TIME_FORMAT_H_
|
||||
|
||||
|
||||
#include <DateFormat.h>
|
||||
#include <Format.h>
|
||||
#include <FormatParameters.h>
|
||||
#include <TimeFormat.h>
|
||||
|
||||
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
enum BDateElement {
|
||||
B_DATE_ELEMENT_INVALID = 0,
|
||||
B_DATE_ELEMENT_YEAR = 1 << 0,
|
||||
B_DATE_ELEMENT_MONTH = 1 << 1,
|
||||
B_DATE_ELEMENT_WEEKDAY = 1 << 2,
|
||||
B_DATE_ELEMENT_DAY = 1 << 3,
|
||||
B_DATE_ELEMENT_AM_PM = 1 << 4,
|
||||
B_DATE_ELEMENT_HOUR = 1 << 5,
|
||||
B_DATE_ELEMENT_MINUTE = 1 << 6,
|
||||
B_DATE_ELEMENT_SECOND = 1 << 7,
|
||||
B_DATE_ELEMENT_TIMEZONE = 1 << 8
|
||||
};
|
||||
|
||||
|
||||
|
||||
class BDateTimeFormat : public BFormat {
|
||||
public:
|
||||
BDateTimeFormat();
|
||||
BDateTimeFormat(
|
||||
const BLanguage* const language = NULL,
|
||||
const BFormattingConventions* const format
|
||||
= NULL);
|
||||
BDateTimeFormat(const BDateTimeFormat &other);
|
||||
virtual ~BDateTimeFormat();
|
||||
|
||||
void SetDateTimeFormat(BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
int32 elements);
|
||||
|
||||
// formatting
|
||||
|
||||
ssize_t Format(char* target, const size_t maxSize,
|
||||
@@ -33,9 +54,7 @@ public:
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
|
||||
private:
|
||||
icu::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
icu::DateFormat* _CreateTimeFormatter(
|
||||
icu::DateFormat* _CreateDateTimeFormatter(
|
||||
const BString& format) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,6 +83,9 @@ public:
|
||||
BString& outFormat) const;
|
||||
status_t GetTimeFormat(BTimeFormatStyle style,
|
||||
BString& outFormat) const;
|
||||
status_t GetDateTimeFormat(BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
BString& outFormat) const;
|
||||
status_t GetNumericFormat(BString& outFormat) const;
|
||||
status_t GetMonetaryFormat(BString& outFormat) const;
|
||||
|
||||
@@ -90,6 +93,10 @@ public:
|
||||
const BString& format);
|
||||
void SetExplicitTimeFormat(BTimeFormatStyle style,
|
||||
const BString& format);
|
||||
void SetExplicitDateTimeFormat(
|
||||
BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
const BString& format);
|
||||
void SetExplicitNumericFormat(const BString& format);
|
||||
void SetExplicitMonetaryFormat(
|
||||
const BString& format);
|
||||
@@ -112,12 +119,18 @@ private:
|
||||
|
||||
mutable BString fCachedDateFormats[B_DATE_FORMAT_STYLE_COUNT];
|
||||
mutable BString fCachedTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
|
||||
mutable BString fCachedDateTimeFormats
|
||||
[B_DATE_FORMAT_STYLE_COUNT]
|
||||
[B_TIME_FORMAT_STYLE_COUNT];
|
||||
mutable BString fCachedNumericFormat;
|
||||
mutable BString fCachedMonetaryFormat;
|
||||
mutable int8 fCachedUse24HourClock;
|
||||
|
||||
BString fExplicitDateFormats[B_DATE_FORMAT_STYLE_COUNT];
|
||||
BString fExplicitTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
|
||||
BString fExplicitDateTimeFormats
|
||||
[B_DATE_FORMAT_STYLE_COUNT]
|
||||
[B_TIME_FORMAT_STYLE_COUNT];
|
||||
BString fExplicitNumericFormat;
|
||||
BString fExplicitMonetaryFormat;
|
||||
int8 fExplicitUse24HourClock;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
|
||||
|
||||
class BTimeFormat : public BFormat {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user