2010-08-02 00:28:19 +04:00
|
|
|
/*
|
2014-09-26 20:24:07 +04:00
|
|
|
* Copyright 2010-2014, Haiku, Inc.
|
2010-08-02 00:28:19 +04:00
|
|
|
* Distributed under the terms of the MIT Licence.
|
|
|
|
*/
|
|
|
|
#ifndef _B_DATE_FORMAT_H_
|
|
|
|
#define _B_DATE_FORMAT_H_
|
|
|
|
|
2014-09-26 20:24:07 +04:00
|
|
|
|
2014-09-30 11:39:18 +04:00
|
|
|
#include <DateTime.h>
|
2014-10-07 14:46:51 +04:00
|
|
|
#include <DateTimeFormat.h>
|
2014-10-02 11:19:54 +04:00
|
|
|
#include <Format.h>
|
2014-09-26 20:24:07 +04:00
|
|
|
#include <FormattingConventions.h>
|
|
|
|
#include <Language.h>
|
|
|
|
#include <Locker.h>
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
|
2015-05-10 22:13:59 +03:00
|
|
|
#ifndef U_ICU_NAMESPACE
|
|
|
|
#define U_ICU_NAMESPACE icu
|
|
|
|
#endif
|
|
|
|
namespace U_ICU_NAMESPACE {
|
2014-10-02 11:19:54 +04:00
|
|
|
class DateFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
class BString;
|
2014-09-26 20:24:07 +04:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
|
2014-10-01 16:24:15 +04:00
|
|
|
class BDateFormat: public BFormat {
|
2010-08-02 00:28:19 +04:00
|
|
|
public:
|
2014-10-27 11:05:48 +03:00
|
|
|
BDateFormat(const BLocale* locale = NULL);
|
|
|
|
BDateFormat(const BLanguage& language,
|
|
|
|
const BFormattingConventions& format);
|
2010-08-02 00:28:19 +04:00
|
|
|
BDateFormat(const BDateFormat &other);
|
|
|
|
virtual ~BDateFormat();
|
|
|
|
|
2014-09-30 13:49:47 +04:00
|
|
|
status_t GetDateFormat(BDateFormatStyle style,
|
|
|
|
BString& outFormat) const;
|
|
|
|
void SetDateFormat(BDateFormatStyle style,
|
|
|
|
const BString& format);
|
2014-09-26 20:24:07 +04:00
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
// formatting
|
|
|
|
|
2014-09-30 11:39:18 +04:00
|
|
|
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,
|
2014-09-26 20:24:07 +04:00
|
|
|
const BTimeZone* timeZone = NULL) const;
|
2014-09-30 11:39:18 +04:00
|
|
|
status_t Format(BString& string, const BDate& time,
|
|
|
|
const BDateFormatStyle style,
|
|
|
|
const BTimeZone* timeZone = NULL) const;
|
|
|
|
status_t Format(BString& string,
|
2014-09-26 20:24:07 +04:00
|
|
|
int*& fieldPositions, int& fieldCount,
|
2014-09-30 11:39:18 +04:00
|
|
|
const time_t time,
|
|
|
|
const BDateFormatStyle style) const;
|
2014-09-26 20:24:07 +04:00
|
|
|
|
|
|
|
status_t GetFields(BDateElement*& fields,
|
|
|
|
int& fieldCount, BDateFormatStyle style
|
|
|
|
) const;
|
|
|
|
|
|
|
|
status_t GetStartOfWeek(BWeekday* weekday) const;
|
2017-08-30 13:59:49 +03:00
|
|
|
status_t GetMonthName(int month, BString& outName,
|
2017-08-30 22:29:30 +03:00
|
|
|
const BDateFormatStyle style
|
|
|
|
= B_FULL_DATE_FORMAT) const;
|
2017-08-30 13:59:49 +03:00
|
|
|
status_t GetDayName(int day, BString& outName,
|
2017-08-30 22:29:30 +03:00
|
|
|
const BDateFormatStyle style
|
|
|
|
= B_FULL_DATE_FORMAT) const;
|
2014-09-26 20:24:07 +04:00
|
|
|
|
2014-10-07 19:40:18 +04:00
|
|
|
// parsing
|
|
|
|
|
|
|
|
status_t Parse(BString source, BDateFormatStyle style,
|
|
|
|
BDate& output);
|
2014-09-26 20:24:07 +04:00
|
|
|
|
|
|
|
private:
|
2017-09-04 10:24:28 +03:00
|
|
|
int _ConvertDayNumberToICU(int day) const;
|
|
|
|
|
2015-05-10 22:13:59 +03:00
|
|
|
U_ICU_NAMESPACE::DateFormat* _CreateDateFormatter(
|
2014-10-07 19:40:18 +04:00
|
|
|
const BDateFormatStyle style) const;
|
2010-08-02 00:28:19 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-04 10:24:28 +03:00
|
|
|
inline int
|
|
|
|
BDateFormat::_ConvertDayNumberToICU(int day) const
|
|
|
|
{
|
|
|
|
return day == 7 ? 1 : day + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-02 00:28:19 +04:00
|
|
|
#endif // _B_DATE_FORMAT_H_
|