2 * Copyright 2011-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Adrien Destugues, pulkomandy@pulkomandy.ath.cx
7 * John Scipione, jscipione@gmail.com
10 * headers/os/locale/DateFormat.h hrev48439
11 * src/kits/locale/DateFormat.cpp hrev48439
19 \brief Contains BDateFormat class, a date formatter and parser.
27 \brief Formatter for dates.
34 \fn BDateFormat::BDateFormat(const BLocale* locale)
35 \brief Locale constructor.
37 \param locale The locale to use, can be \c NULL for the default locale.
44 \fn BDateFormat::BDateFormat(const BLanguage& language,
45 const BFormattingConventions& format);
46 \brief Language and formatting convention constructor.
48 \param language The \a language to use.
49 \param format The formatting convention to use.
56 \fn BDateFormat::BDateFormat(const BDateFormat& other)
57 \brief Copy Constructor.
59 \param other The BDateFormat object to copy from.
66 \fn BDateFormat::~BDateFormat()
74 \fn ssize_t BDateFormat::Format(char* string, const size_t maxSize,
75 const time_t time, const BDateFormatStyle style) const
76 \brief Fills in \a string with a formatted date up to \a maxSize bytes for
77 the given \a time and \a style for the locale.
79 \param string The string buffer to fill with the formatted date.
80 \param maxSize The size of the buffer.
81 \param time The time (in seconds since epoch) to format
82 \param style Specify the long format (with day name, full
83 month name) or the short format, 08/12/2010 or similar.
85 \returns The number of bytes written during the date formatting.
86 \retval B_ERROR Unable to lock the BLocale.
87 \retval B_NO_MEMORY Ran out of memory while creating the object.
88 \retval B_BAD_VALUE There was not enough space to store the result.
95 \fn status_t BDateFormat::Format(BString& string, const time_t time,
96 const BDateFormatStyle style, const BTimeZone* timeZone) const
97 \brief Fills in \a string with a formatted date for the given
98 \a time, \a style, and \a timeZone for the locale.
100 \param string The string buffer to fill with the formatted date.
101 \param time The time (in seconds since epoch) to format
102 \param style Specify the long format (with day name, full
103 month name) or the short format, 08/12/2010 or similar.
104 \param timeZone Specifies the time zone to use, if \c NULL, use the
105 system default time zone (usually UTC).
107 \returns A status code.
108 \retval B_OK Everything went fine.
109 \retval B_ERROR Unable to lock the BLocale.
110 \retval B_NO_MEMORY Ran out of memory while creating the object.
117 \fn status_t BDateFormat::Format(BString& string,
118 int*& fieldPositions, int& fieldCount, const time_t time,
119 const BDateFormatStyle style) const
120 \brief Fills in \a string with a custom formatted date according to the
121 given parameters for the locale and fills out an array of
122 \a fieldPositions which must be freed by the caller and a
123 \a fieldCount which contains the number of positions.
125 The positions are offsets in the string at which each element of the date
126 (day, month, year, etc) and the separator starting positions. These
127 can be used, for example, to split the string into parts to use in a
128 locale-aware set of BMenuFields to edit the date in the local format.
130 \param string The string buffer to fill with the formatted date.
131 \param fieldPositions An array of date field positions to be filled out.
132 \param fieldCount The number of \a fields in \a fieldPositions to be
134 \param time The time (in seconds since epoch) to format
135 \param style Specify the long format (with day name, full
136 month name) or the short format, 08/12/2010 or similar.
138 \returns A status code.
139 \retval B_OK Everything went fine.
140 \retval B_ERROR Unable to lock the BLocale.
141 \retval B_NO_MEMORY Ran out of memory while creating the \a string buffer
142 or \a fieldPositions array.
143 \retval B_BAD_VALUE There was not enough space to store the result.
150 \fn status_t BDateFormat::GetFields(BDateElement*& fields, int& fieldCount,
151 BDateFormatStyle style) const
152 \brief Get the type of each field in the date format of the locale.
154 This method is most often used in combination with the version of Format()
155 that takes a fieldPositions parameter. Format() gives you the offset of
156 each field in a formatted string, and GetFields() gives you the type of
157 the field at a given offset. With these informations, you can handle the
158 formatted date string as a list of fields that you can split and alter at
161 \param fields Pointer to the array of BDateElement objects.
162 \param fieldCount The number of fields in \a fields.
163 \param style Specify the long format (with day name, full month name)
164 or the short format, "08/12/2010" or similar.
166 \returns A status code.
167 \retval B_OK Everything went fine.
168 \retval B_ERROR Unable to lock the BLocale.
169 \retval B_NO_MEMORY Ran out of memory while creating the object.
170 \retval B_BAD_VALUE Bad or invalid \a fields data.
172 \sa BDateFormat::GetFields(BDateElement*&, int&, BTimeFormatStyle) const
173 \sa BDateFormat::Format(BString&, int*&, int&, const time_t,
174 const BDateFormatStyle) const
181 \fn status_t BDateFormat::GetStartOfWeek(BWeekday* startOfWeek) const
182 \brief Returns the day used as the start of week in this locale.
184 Possible values for \a startOfWeek include:
185 - \c B_WEEKDAY_SUNDAY
186 - \c B_WEEKDAY_MONDAY
187 - \c B_WEEKDAY_TUESDAY
188 - \c B_WEEKDAY_WEDNESDAY
189 - \c B_WEEKDAY_THURSDAY
190 - \c B_WEEKDAY_FRIDAY
191 - \c B_WEEKDAY_SATURDAY
193 \returns A status code.
194 \retval B_OK Everything went fine.
195 \retval B_BAD_VALUE \a startOfWeek is \c NULL.
196 \retval B_ERROR Unable to lock the BLocale or another error occurred.