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 20 namespace U_ICU_NAMESPACE { 21 class DateFormat; 22 } 23 24 25 class BString; 26 class BTimeZone; 27 28 29 enum 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 40 class BDateFormat: public BFormat { 41 public: 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 const BDateFormatStyle style 76 = B_FULL_DATE_FORMAT) const; 77 status_t GetDayName(int day, BString& outName, 78 const BDateFormatStyle style 79 = B_FULL_DATE_FORMAT) const; 80 81 // parsing 82 83 status_t Parse(BString source, BDateFormatStyle style, 84 BDate& output); 85 86 private: 87 int _ConvertDayNumberToICU(int day) const; 88 89 U_ICU_NAMESPACE::DateFormat* _CreateDateFormatter( 90 const BDateFormatStyle style) const; 91 92 }; 93 94 95 inline int 96 BDateFormat::_ConvertDayNumberToICU(int day) const 97 { 98 return day == 7 ? 1 : day + 1; 99 } 100 101 102 #endif // _B_DATE_FORMAT_H_ 103