xref: /haiku/docs/user/locale/DateFormat.dox (revision 4a31c3262018a36b9c920caca1be0034d6836923)
1*4a31c326SJohn Scipione/*
2*4a31c326SJohn Scipione * Copyright 2011-2014 Haiku, Inc. All rights reserved.
3*4a31c326SJohn Scipione * Distributed under the terms of the MIT License.
4*4a31c326SJohn Scipione *
5*4a31c326SJohn Scipione * Authors:
6*4a31c326SJohn Scipione *		Adrien Destugues, pulkomandy@pulkomandy.ath.cx
7*4a31c326SJohn Scipione *		John Scipione, jscipione@gmail.com
8*4a31c326SJohn Scipione *
9*4a31c326SJohn Scipione * Corresponds to:
10*4a31c326SJohn Scipione *		headers/os/locale/DateFormat.h	hrev48439
11*4a31c326SJohn Scipione *		src/kits/locale/DateFormat.cpp	hrev48439
12*4a31c326SJohn Scipione */
13*4a31c326SJohn Scipione
14*4a31c326SJohn Scipione
15*4a31c326SJohn Scipione/*!
16*4a31c326SJohn Scipione	\file DateFormat.h
17*4a31c326SJohn Scipione	\ingroup locale
18*4a31c326SJohn Scipione	\ingroup libbe
19*4a31c326SJohn Scipione	\brief Contains BDateFormat class, a date formatter.
20*4a31c326SJohn Scipione*/
21*4a31c326SJohn Scipione
22*4a31c326SJohn Scipione
23*4a31c326SJohn Scipione/*!
24*4a31c326SJohn Scipione	\class BDateFormat
25*4a31c326SJohn Scipione	\ingroup locale
26*4a31c326SJohn Scipione	\ingroup libbe
27*4a31c326SJohn Scipione	\brief Formatter for dates.
28*4a31c326SJohn Scipione
29*4a31c326SJohn Scipione	\since Haiku R1
30*4a31c326SJohn Scipione*/
31*4a31c326SJohn Scipione
32*4a31c326SJohn Scipione
33*4a31c326SJohn Scipione/*!
34*4a31c326SJohn Scipione	\fn BDateFormat::BDateFormat(const BLocale* locale)
35*4a31c326SJohn Scipione	\brief Locale constructor.
36*4a31c326SJohn Scipione
37*4a31c326SJohn Scipione	\param locale The locale to use, can be \c NULL for the default locale.
38*4a31c326SJohn Scipione*/
39*4a31c326SJohn Scipione
40*4a31c326SJohn Scipione
41*4a31c326SJohn Scipione/*!
42*4a31c326SJohn Scipione	\fn BDateFormat::BDateFormat(const BLanguage& language,
43*4a31c326SJohn Scipione		const BFormattingConventions& format);
44*4a31c326SJohn Scipione	\brief Language and formatting convention constructor.
45*4a31c326SJohn Scipione
46*4a31c326SJohn Scipione	\param language The \a language to use.
47*4a31c326SJohn Scipione	\param format The formatting convention to use.
48*4a31c326SJohn Scipione*/
49*4a31c326SJohn Scipione
50*4a31c326SJohn Scipione
51*4a31c326SJohn Scipione/*!
52*4a31c326SJohn Scipione	\fn BDateFormat::BDateFormat(const BDateFormat& other)
53*4a31c326SJohn Scipione	\brief Copy Constructor.
54*4a31c326SJohn Scipione
55*4a31c326SJohn Scipione	\param other The BDateFormat object to copy from.
56*4a31c326SJohn Scipione
57*4a31c326SJohn Scipione	\since Haiku R1
58*4a31c326SJohn Scipione*/
59*4a31c326SJohn Scipione
60*4a31c326SJohn Scipione
61*4a31c326SJohn Scipione/*!
62*4a31c326SJohn Scipione	\fn BDateFormat::~BDateFormat()
63*4a31c326SJohn Scipione	\brief Destructor.
64*4a31c326SJohn Scipione
65*4a31c326SJohn Scipione	\since Haiku R1
66*4a31c326SJohn Scipione*/
67*4a31c326SJohn Scipione
68*4a31c326SJohn Scipione
69*4a31c326SJohn Scipione/*!
70*4a31c326SJohn Scipione	\fn ssize_t BDateFormat::Format(char* string, const size_t maxSize,
71*4a31c326SJohn Scipione		const time_t time, const BDateFormatStyle style) const
72*4a31c326SJohn Scipione	\brief Fills in \a string with a formatted date up to \a maxSize bytes for
73*4a31c326SJohn Scipione	       the given \a time and \a style for the locale.
74*4a31c326SJohn Scipione
75*4a31c326SJohn Scipione	\param string The string buffer to fill with the formatted date.
76*4a31c326SJohn Scipione	\param maxSize The size of the buffer.
77*4a31c326SJohn Scipione	\param time The time (in seconds since epoch) to format
78*4a31c326SJohn Scipione	\param style Specify the long format (with day name, full
79*4a31c326SJohn Scipione	       month name) or the short format, 08/12/2010 or similar.
80*4a31c326SJohn Scipione
81*4a31c326SJohn Scipione	\returns The number of bytes written during the date formatting.
82*4a31c326SJohn Scipione	\retval B_ERROR Unable to lock the BLocale.
83*4a31c326SJohn Scipione	\retval B_NO_MEMORY Ran out of memory while creating the DateFormat object.
84*4a31c326SJohn Scipione	\retval B_BAD_VALUE CheckedArrayByteSink overflowed.
85*4a31c326SJohn Scipione
86*4a31c326SJohn Scipione	\since Haiku R1
87*4a31c326SJohn Scipione*/
88*4a31c326SJohn Scipione
89*4a31c326SJohn Scipione
90*4a31c326SJohn Scipione/*!
91*4a31c326SJohn Scipione	\fn status_t BDateFormat::Format(BString& string, const time_t time,
92*4a31c326SJohn Scipione		const BDateFormatStyle style, const BTimeZone* timeZone) const
93*4a31c326SJohn Scipione	\brief Fills in \a string with a formatted date for the given
94*4a31c326SJohn Scipione	       \a time, \a style, and \a timeZone for the locale.
95*4a31c326SJohn Scipione
96*4a31c326SJohn Scipione	\param string The string buffer to fill with the formatted date.
97*4a31c326SJohn Scipione	\param time The time (in seconds since epoch) to format
98*4a31c326SJohn Scipione	\param style Specify the long format (with day name, full
99*4a31c326SJohn Scipione		month name) or the short format, 08/12/2010 or similar.
100*4a31c326SJohn Scipione	\param timeZone The time zone.
101*4a31c326SJohn Scipione
102*4a31c326SJohn Scipione	\returns A status code.
103*4a31c326SJohn Scipione	\retval B_OK Everything went fine.
104*4a31c326SJohn Scipione	\retval B_ERROR Unable to lock the BLocale.
105*4a31c326SJohn Scipione	\retval B_NO_MEMORY Ran out of memory while creating the DateFormat object.
106*4a31c326SJohn Scipione
107*4a31c326SJohn Scipione	\since Haiku R1
108*4a31c326SJohn Scipione*/
109*4a31c326SJohn Scipione
110*4a31c326SJohn Scipione
111*4a31c326SJohn Scipione/*!
112*4a31c326SJohn Scipione	\fn status_t BDateFormat::Format(BString& string,
113*4a31c326SJohn Scipione		int*& fieldPositions, int& fieldCount, const time_t time,
114*4a31c326SJohn Scipione		const BDateFormatStyle style) const
115*4a31c326SJohn Scipione	\brief Fills in \a string with a formatted date for the given
116*4a31c326SJohn Scipione	       \a time and \a style for the locale.
117*4a31c326SJohn Scipione
118*4a31c326SJohn Scipione	\param string The string buffer to fill with the formatted date.
119*4a31c326SJohn Scipione	\param fieldPositions An array of date field positions to use.
120*4a31c326SJohn Scipione	\param fieldCount The number of \a fields in \a fieldPositions.
121*4a31c326SJohn Scipione	\param time The time (in seconds since epoch) to format
122*4a31c326SJohn Scipione	\param style Specify the long format (with day name, full
123*4a31c326SJohn Scipione		month name) or the short format, 08/12/2010 or similar.
124*4a31c326SJohn Scipione
125*4a31c326SJohn Scipione	\returns A status code.
126*4a31c326SJohn Scipione	\retval B_OK Everything went fine.
127*4a31c326SJohn Scipione	\retval B_ERROR Unable to lock the BLocale.
128*4a31c326SJohn Scipione	\retval B_NO_MEMORY Ran out of memory while creating the DateFormat object.
129*4a31c326SJohn Scipione	\retval B_BAD_VALUE An error occurred while performing the date formatting.
130*4a31c326SJohn Scipione
131*4a31c326SJohn Scipione	\since Haiku R1
132*4a31c326SJohn Scipione*/
133*4a31c326SJohn Scipione
134*4a31c326SJohn Scipione
135*4a31c326SJohn Scipione/*!
136*4a31c326SJohn Scipione	\fn status_t BDateFormat::GetFields(BDateElement*& fields, int& fieldCount,
137*4a31c326SJohn Scipione		BDateFormatStyle style) const
138*4a31c326SJohn Scipione	\brief Get the type of each field in the date format of the locale.
139*4a31c326SJohn Scipione
140*4a31c326SJohn Scipione	This method is most often used in combination with FormatDate().
141*4a31c326SJohn Scipione	FormatDate() gives you the offset of each field in a formatted string,
142*4a31c326SJohn Scipione	and GetDateFields() gives you the type of the field at a given offset.
143*4a31c326SJohn Scipione	With these informations, you can handle the formatted date string as
144*4a31c326SJohn Scipione	a list of fields that you can split and alter at will.
145*4a31c326SJohn Scipione
146*4a31c326SJohn Scipione	\param fields Pointer to the fields object.
147*4a31c326SJohn Scipione	\param fieldCount The number of fields.
148*4a31c326SJohn Scipione	\param style Specify the long format (with day name, full
149*4a31c326SJohn Scipione	       month name) or the short format, 08/12/2010 or similar.
150*4a31c326SJohn Scipione
151*4a31c326SJohn Scipione	\returns A status code.
152*4a31c326SJohn Scipione	\retval B_OK Everything went fine.
153*4a31c326SJohn Scipione	\retval B_ERROR Unable to lock the BLocale.
154*4a31c326SJohn Scipione	\retval B_NO_MEMORY Ran out of memory while creating the DateFormat object.
155*4a31c326SJohn Scipione	\retval B_BAD_VALUE An error occurred while getting the date fields.
156*4a31c326SJohn Scipione
157*4a31c326SJohn Scipione	\sa BDateFormat::GetTimeFields(BDateElement*& fields, int& fieldCount,
158*4a31c326SJohn Scipione		BTimeFormatStyle style) const
159*4a31c326SJohn Scipione
160*4a31c326SJohn Scipione	\since Haiku R1
161*4a31c326SJohn Scipione*/
162*4a31c326SJohn Scipione
163*4a31c326SJohn Scipione
164*4a31c326SJohn Scipione/*!
165*4a31c326SJohn Scipione	\fn status_t BDateFormat::GetStartOfWeek(BWeekday* startOfWeek) const
166*4a31c326SJohn Scipione	\brief Returns the day used as the start of week in this locale.
167*4a31c326SJohn Scipione
168*4a31c326SJohn Scipione	Possible values for \a startOfWeek include:
169*4a31c326SJohn Scipione		- \c B_WEEKDAY_SUNDAY
170*4a31c326SJohn Scipione		- \c B_WEEKDAY_MONDAY
171*4a31c326SJohn Scipione		- \c B_WEEKDAY_TUESDAY
172*4a31c326SJohn Scipione		- \c B_WEEKDAY_WEDNESDAY
173*4a31c326SJohn Scipione		- \c B_WEEKDAY_THURSDAY
174*4a31c326SJohn Scipione		- \c B_WEEKDAY_FRIDAY
175*4a31c326SJohn Scipione		- \c B_WEEKDAY_SATURDAY
176*4a31c326SJohn Scipione
177*4a31c326SJohn Scipione	\returns A status code.
178*4a31c326SJohn Scipione	\retval B_OK Everything went fine.
179*4a31c326SJohn Scipione	\retval B_BAD_VALUE \a startOfWeek is \c NULL.
180*4a31c326SJohn Scipione	\retval B_ERROR Unable to lock the BLocale or another error occurred.
181*4a31c326SJohn Scipione
182*4a31c326SJohn Scipione	\since Haiku R1
183*4a31c326SJohn Scipione*/
184