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(const BLocale* locale = NULL); 40 BDateFormat(const BLanguage& language, 41 const BFormattingConventions& format); 42 BDateFormat(const BDateFormat &other); 43 virtual ~BDateFormat(); 44 45 status_t GetDateFormat(BDateFormatStyle style, 46 BString& outFormat) const; 47 void SetDateFormat(BDateFormatStyle style, 48 const BString& format); 49 50 // formatting 51 52 ssize_t Format(char* string, const size_t maxSize, 53 const time_t time, 54 const BDateFormatStyle style) const; 55 status_t Format(BString& string, const time_t time, 56 const BDateFormatStyle style, 57 const BTimeZone* timeZone = NULL) const; 58 status_t Format(BString& string, const BDate& time, 59 const BDateFormatStyle style, 60 const BTimeZone* timeZone = NULL) const; 61 status_t Format(BString& string, 62 int*& fieldPositions, int& fieldCount, 63 const time_t time, 64 const BDateFormatStyle style) const; 65 66 status_t GetFields(BDateElement*& fields, 67 int& fieldCount, BDateFormatStyle style 68 ) const; 69 70 status_t GetStartOfWeek(BWeekday* weekday) const; 71 status_t GetMonthName(int month, BString& outName); 72 73 // parsing 74 75 status_t Parse(BString source, BDateFormatStyle style, 76 BDate& output); 77 78 private: 79 icu::DateFormat* _CreateDateFormatter( 80 const BDateFormatStyle style) const; 81 82 }; 83 84 85 #endif // _B_DATE_FORMAT_H_ 86