DateFormat.h revision 73de5837
1/*
2 * Copyright 2010-2014, Haiku, Inc.
3 * Distributed under the terms of the MIT Licence.
4 */
5#ifndef _B_DATE_FORMAT_H_
6#define _B_DATE_FORMAT_H_
7
8
9#include <DateTime.h>
10#include <DateTimeFormat.h>
11#include <Format.h>
12#include <FormattingConventions.h>
13#include <Language.h>
14#include <Locker.h>
15
16
17#ifndef U_ICU_NAMESPACE
18  #define U_ICU_NAMESPACE icu
19#endif
20namespace U_ICU_NAMESPACE {
21	class DateFormat;
22}
23
24
25class BString;
26class BTimeZone;
27
28
29enum BWeekday {
30	B_WEEKDAY_MONDAY = 1,
31	B_WEEKDAY_TUESDAY,
32	B_WEEKDAY_WEDNESDAY,
33	B_WEEKDAY_THURSDAY,
34	B_WEEKDAY_FRIDAY,
35	B_WEEKDAY_SATURDAY,
36	B_WEEKDAY_SUNDAY,
37};
38
39
40class BDateFormat: public BFormat {
41public:
42								BDateFormat(const BLocale* locale = NULL);
43								BDateFormat(const BLanguage& language,
44									const BFormattingConventions& format);
45								BDateFormat(const BDateFormat &other);
46	virtual						~BDateFormat();
47
48			status_t			GetDateFormat(BDateFormatStyle style,
49									BString& outFormat) const;
50			void				SetDateFormat(BDateFormatStyle style,
51									const BString& format);
52
53								// formatting
54
55			ssize_t				Format(char* string, const size_t maxSize,
56									const time_t time,
57									const BDateFormatStyle style) const;
58			status_t			Format(BString& string, const time_t time,
59									const BDateFormatStyle style,
60									const BTimeZone* timeZone = NULL) const;
61			status_t			Format(BString& string, const BDate& time,
62									const BDateFormatStyle style,
63									const BTimeZone* timeZone = NULL) const;
64			status_t			Format(BString& string,
65									int*& fieldPositions, int& fieldCount,
66									const time_t time,
67									const BDateFormatStyle style) const;
68
69			status_t			GetFields(BDateElement*& fields,
70									int& fieldCount, BDateFormatStyle style
71									) const;
72
73			status_t			GetStartOfWeek(BWeekday* weekday) const;
74			status_t			GetMonthName(int month, BString& outName);
75
76								// parsing
77
78			status_t			Parse(BString source, BDateFormatStyle style,
79									BDate& output);
80
81private:
82			U_ICU_NAMESPACE::DateFormat*	_CreateDateFormatter(
83									const BDateFormatStyle style) const;
84
85};
86
87
88#endif	// _B_DATE_FORMAT_H_
89