526d483999
* Add setters for the language and formatting conventions * Add shortcut getter and setter for the date format * Use those in the locale roster to make the BDateFormat actually use the system preferred language and format. * Applications can also use this to extract specific information from the system format (eg. set date format to "LLLL" to extract month names), or define specific formats more easily (eg. for parsing and generating e-mail headers or HTTP cookies).
83 lines
2.0 KiB
C++
83 lines
2.0 KiB
C++
/*
|
|
* Copyright 2010-2014, Haiku, Inc.
|
|
* Distributed under the terms of the MIT Licence.
|
|
*/
|
|
#ifndef _B_DATE_FORMAT_H_
|
|
#define _B_DATE_FORMAT_H_
|
|
|
|
|
|
#include <DateTime.h>
|
|
#include <DateTimeFormat.h>
|
|
#include <FormattingConventions.h>
|
|
#include <Language.h>
|
|
#include <Locker.h>
|
|
|
|
|
|
class BString;
|
|
class BTimeZone;
|
|
|
|
|
|
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(const BLanguage* const,
|
|
const BFormattingConventions* const);
|
|
BDateFormat(const BDateFormat &other);
|
|
virtual ~BDateFormat();
|
|
|
|
static const BDateFormat* Default();
|
|
|
|
void SetLanguage(const BLanguage& newLanguage);
|
|
void SetFormattingConventions(
|
|
const BFormattingConventions& conventions);
|
|
status_t GetDateFormat(BDateFormatStyle style,
|
|
BString& outFormat) const;
|
|
void SetDateFormat(BDateFormatStyle style,
|
|
const BString& format);
|
|
|
|
// formatting
|
|
|
|
ssize_t Format(char* string, const size_t maxSize,
|
|
const time_t time,
|
|
const BDateFormatStyle style) const;
|
|
status_t Format(BString& string, const time_t time,
|
|
const BDateFormatStyle style,
|
|
const BTimeZone* timeZone = NULL) const;
|
|
status_t Format(BString& string, const BDate& time,
|
|
const BDateFormatStyle style,
|
|
const BTimeZone* timeZone = NULL) const;
|
|
status_t Format(BString& string,
|
|
int*& fieldPositions, int& fieldCount,
|
|
const time_t time,
|
|
const BDateFormatStyle style) const;
|
|
|
|
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;
|
|
};
|
|
|
|
|
|
#endif // _B_DATE_FORMAT_H_
|