xref: /haiku/headers/os/locale/DateFormat.h (revision 0e7fcd84af6c2bae5d5a741f3eb8f59813e0a6e0)
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 namespace icu {
18 	class DateFormat;
19 }
20 
21 
22 class BString;
23 class BTimeZone;
24 
25 
26 enum BWeekday {
27 	B_WEEKDAY_MONDAY = 1,
28 	B_WEEKDAY_TUESDAY,
29 	B_WEEKDAY_WEDNESDAY,
30 	B_WEEKDAY_THURSDAY,
31 	B_WEEKDAY_FRIDAY,
32 	B_WEEKDAY_SATURDAY,
33 	B_WEEKDAY_SUNDAY,
34 };
35 
36 
37 class BDateFormat: public BFormat {
38 public:
39 								BDateFormat(
40 									const BLanguage* const language = NULL,
41 									const BFormattingConventions* const
42 										format = NULL);
43 								BDateFormat(const BDateFormat &other);
44 	virtual						~BDateFormat();
45 
46 			status_t			GetDateFormat(BDateFormatStyle style,
47 									BString& outFormat) const;
48 			void				SetDateFormat(BDateFormatStyle style,
49 									const BString& format);
50 
51 								// formatting
52 
53 			ssize_t				Format(char* string, const size_t maxSize,
54 									const time_t time,
55 									const BDateFormatStyle style) const;
56 			status_t			Format(BString& string, const time_t time,
57 									const BDateFormatStyle style,
58 									const BTimeZone* timeZone = NULL) const;
59 			status_t			Format(BString& string, const BDate& time,
60 									const BDateFormatStyle style,
61 									const BTimeZone* timeZone = NULL) const;
62 			status_t			Format(BString& string,
63 									int*& fieldPositions, int& fieldCount,
64 									const time_t time,
65 									const BDateFormatStyle style) const;
66 
67 			status_t			GetFields(BDateElement*& fields,
68 									int& fieldCount, BDateFormatStyle style
69 									) const;
70 
71 			status_t			GetStartOfWeek(BWeekday* weekday) const;
72 			status_t			GetMonthName(int month, BString& outName);
73 
74 								// parsing
75 
76 			status_t			Parse(BString source, BDateFormatStyle style,
77 									BDate& output);
78 
79 private:
80 			icu::DateFormat*	_CreateDateFormatter(
81 									const BDateFormatStyle style) const;
82 
83 };
84 
85 
86 #endif	// _B_DATE_FORMAT_H_
87