Move date formatting from BLocale to BDateFormat
* There is a little code duplication. This will be moved to BFormat once the time and datetime formatting is also moved out of BLocale * The way to create a BDateFormat from a BLocale is still open for discussion. I'm undecided between making BDateFormat a member of BLocale, or adding a BDateFormat(const BLocale&) constructor. * Adjust all users of the API.
This commit is contained in:
@@ -1,29 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Copyright 2010-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_DATE_FORMAT_H_
|
||||
#define _B_DATE_FORMAT_H_
|
||||
|
||||
|
||||
#include <DateTimeFormat.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
|
||||
class BDateFormat : public BDateTimeFormat {
|
||||
|
||||
enum BWeekday {
|
||||
B_WEEKDAY_MONDAY = 1,
|
||||
B_WEEKDAY_TUESDAY,
|
||||
B_WEEKDAY_WEDNESDAY,
|
||||
B_WEEKDAY_THURSDAY,
|
||||
B_WEEKDAY_FRIDAY,
|
||||
B_WEEKDAY_SATURDAY,
|
||||
B_WEEKDAY_SUNDAY,
|
||||
};
|
||||
|
||||
|
||||
class BDateFormat {
|
||||
public:
|
||||
BDateFormat();
|
||||
BDateFormat(const BLanguage* const,
|
||||
const BFormattingConventions* const);
|
||||
BDateFormat(const BDateFormat &other);
|
||||
virtual ~BDateFormat();
|
||||
|
||||
static const BDateFormat* Default();
|
||||
|
||||
// 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, BDateFormatStyle style) const;
|
||||
status_t Format(BString* string, time_t time,
|
||||
BDateFormatStyle style,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
status_t Format(BString* string,
|
||||
int*& fieldPositions, int& fieldCount,
|
||||
time_t time, BDateFormatStyle style) const;
|
||||
|
||||
// TODO: ... all, basically!
|
||||
status_t GetFields(BDateElement*& fields,
|
||||
int& fieldCount, BDateFormatStyle style
|
||||
) const;
|
||||
|
||||
status_t GetStartOfWeek(BWeekday* weekday) const;
|
||||
|
||||
// TODO parsing
|
||||
|
||||
private:
|
||||
icu::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
|
||||
mutable BLocker fLock;
|
||||
BFormattingConventions fConventions;
|
||||
BLanguage fLanguage;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Copyright 2010-2014, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_DATE_TIME_FORMAT_H_
|
||||
#define _B_DATE_TIME_FORMAT_H_
|
||||
|
||||
|
||||
#include <Format.h>
|
||||
#include <FormatParameters.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
class BDateTimeFormat : public BFormat {
|
||||
public:
|
||||
BDateTimeFormat();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <DateTimeFormat.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
#include <Locker.h>
|
||||
@@ -18,21 +19,11 @@ namespace icu {
|
||||
|
||||
|
||||
class BCatalog;
|
||||
class BDateFormat;
|
||||
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 BNumberElement {
|
||||
B_NUMBER_ELEMENT_INVALID = B_BAD_DATA,
|
||||
B_NUMBER_ELEMENT_INTEGER = 0,
|
||||
@@ -41,18 +32,6 @@ enum BNumberElement {
|
||||
};
|
||||
|
||||
|
||||
// TODO: move this to BCalendar (should we ever have that) or BDate
|
||||
enum BWeekday {
|
||||
B_WEEKDAY_MONDAY = 1,
|
||||
B_WEEKDAY_TUESDAY,
|
||||
B_WEEKDAY_WEDNESDAY,
|
||||
B_WEEKDAY_THURSDAY,
|
||||
B_WEEKDAY_FRIDAY,
|
||||
B_WEEKDAY_SATURDAY,
|
||||
B_WEEKDAY_SUNDAY,
|
||||
};
|
||||
|
||||
|
||||
class BLocale {
|
||||
public:
|
||||
BLocale(const BLanguage* language = NULL,
|
||||
@@ -78,11 +57,6 @@ public:
|
||||
// see definitions in LocaleStrings.h
|
||||
const char* GetString(uint32 id) const;
|
||||
|
||||
void FormatString(char* target, size_t maxSize,
|
||||
char* fmt, ...) const;
|
||||
void FormatString(BString* buffer, char* fmt,
|
||||
...) const;
|
||||
|
||||
// DateTime
|
||||
|
||||
// TODO: drop some of these once BDateTimeFormat
|
||||
@@ -95,24 +69,6 @@ public:
|
||||
BTimeFormatStyle timeStyle,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
|
||||
// Date
|
||||
|
||||
// TODO: drop some of these once BDateFormat
|
||||
// has been implemented!
|
||||
ssize_t FormatDate(char* string, size_t maxSize,
|
||||
time_t time, BDateFormatStyle style) const;
|
||||
status_t FormatDate(BString* string, time_t time,
|
||||
BDateFormatStyle style,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
status_t FormatDate(BString* string,
|
||||
int*& fieldPositions, int& fieldCount,
|
||||
time_t time, BDateFormatStyle style) const;
|
||||
status_t GetDateFields(BDateElement*& fields,
|
||||
int& fieldCount, BDateFormatStyle style
|
||||
) const;
|
||||
|
||||
status_t GetStartOfWeek(BWeekday* weekday) const;
|
||||
|
||||
// Time
|
||||
|
||||
// TODO: drop some of these once BTimeFormat
|
||||
|
||||
@@ -16,6 +16,7 @@ class BBitmap;
|
||||
class BCatalog;
|
||||
class BCollator;
|
||||
class BCountry;
|
||||
class BDateFormat;
|
||||
class BFormattingConventions;
|
||||
class BLanguage;
|
||||
class BLocale;
|
||||
@@ -78,6 +79,7 @@ public:
|
||||
// (that needs to link with liblocalestub.a)
|
||||
|
||||
const BLocale* GetDefaultLocale() const;
|
||||
const BDateFormat* GetDefaultDateFormat() const;
|
||||
|
||||
bool IsFilesystemTranslationPreferred() const;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <DateFormat.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <image.h>
|
||||
#include <Language.h>
|
||||
@@ -37,6 +38,7 @@ struct LocaleRosterData {
|
||||
|
||||
BLocale fDefaultLocale;
|
||||
BTimeZone fDefaultTimeZone;
|
||||
BDateFormat fDefaultDateFormat;
|
||||
|
||||
bool fIsFilesystemTranslationPreferred;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "DateTime.h"
|
||||
|
||||
|
||||
#include <DateFormat.h>
|
||||
#include <Invoker.h>
|
||||
#include <List.h>
|
||||
#include <Locale.h>
|
||||
|
||||
Reference in New Issue
Block a user