1/*
2 * Copyright 2011-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Adrien Destugues, pulkomandy@pulkomandy.ath.cx
7 *		John Scipione, jscipione@gmail.com
8 *
9 * Corresponds to:
10 *		headers/os/locale/TimeFormat.h	hrev48439
11 *		src/kits/locale/TimeFormat.cpp	hrev48439
12 */
13
14
15/*!
16	\file TimeFormat.h
17	\ingroup locale
18	\ingroup libbe
19	\brief Contains BTimeFormat class, a time formatter and parser.
20*/
21
22
23/*!
24	\class BTimeFormat
25	\ingroup locale
26	\ingroup libbe
27	\brief Formatter for times.
28
29	\since Haiku R1
30*/
31
32
33/*!
34	\fn BTimeFormat::BTimeFormat()
35	\brief Default Constructor. The current system locale is used.
36
37	\since Haiku R1
38*/
39
40
41/*!
42	\fn BTimeFormat::BTimeFormat(const BLanguage& language,
43		const BFormattingConventions& format);
44	\brief Language and formatting convention constructor.
45
46	\param language The \a language to use.
47	\param format The formatting convention to use.
48
49	\since Haiku R1
50*/
51
52
53/*!
54	\fn BTimeFormat::BTimeFormat(const BTimeFormat& other)
55	\brief Copy Constructor.
56
57	\param other The BTimeFormat object to copy from.
58
59	\since Haiku R1
60*/
61
62
63/*!
64	\fn BTimeFormat::~BTimeFormat()
65	\brief Destructor.
66
67	\since Haiku R1
68*/
69
70
71/*!
72	\fn ssize_t BTimeFormat::Format(char* string, size_t maxSize, time_t time,
73		BTimeFormatStyle style) const
74	\brief Fills in \a string with a formatted time up to \a maxSize bytes for
75	       the given \a time and \a style for the locale.
76
77	\param string The string buffer to fill with the formatted time.
78	\param maxSize The size of the buffer.
79	\param time The time (in seconds since midnight) to format.
80	\param style Specify the long format or the short format.
81
82	\returns The number of bytes written during the time formatting.
83	\retval B_ERROR Unable to lock the BLocale.
84	\retval B_NO_MEMORY Ran out of memory while creating the object.
85	\retval B_BAD_VALUE There was not enough space to store the result.
86
87	\since Haiku R1
88*/
89
90
91/*!
92	\fn status_t BTimeFormat::Format(BString& string, const time_t time,
93		const BTimeFormatStyle style, const BTimeZone* timeZone) const
94	\brief Fills in \a string with a formatted time for the given
95	       \a time, \a style, and \a timeZone for the locale.
96
97	\param string The string buffer to fill with the formatted time.
98	\param time The time (in seconds since epoch) to format.
99	\param style Specifies whether to use the long format or short format.
100	\param timeZone Specifies the time zone to use, if \c NULL, use the
101	       system default time zone (usually UTC).
102
103	\returns A status code.
104	\retval B_OK Everything went fine.
105	\retval B_ERROR Unable to lock the BLocale.
106	\retval B_NO_MEMORY Ran out of memory while creating the object.
107	\retval B_BAD_VALUE There was not enough space to store the result.
108
109	\since Haiku R1
110*/
111
112
113/*!
114	\fn status_t BTimeFormat::Format(BString& string, int*& fieldPositions,
115		int& fieldCount, time_t time, BTimeFormatStyle style) const
116	\brief Fills in \a string with a custom formatted date according to the
117	       given parameters for the locale and fills out an array of
118	       \a fieldPositions which must be freed by the caller and a
119	       \a fieldCount which contains the number of positions.
120
121	The positions are offsets in the string at which each element of the time
122	(hour, minute, second, etc) and the separator starting positions. These
123	can be used, for example, to split the string in parts to use in a
124	locale-aware set of BMenuFields to edit the time in the local format.
125
126	\param string The string buffer to fill with the formatted time.
127	\param fieldPositions An array of time field positions to be filled out.
128	\param fieldCount The number of \a fields in \a fieldPositions to be
129	       filled out.
130	\param time The time (in seconds since epoch) to format.
131	\param style Specify the long format (with day name, full
132		month name) or the short format, 08/12/2010 or similar.
133
134	\returns A status code.
135	\retval B_OK Everything went fine.
136	\retval B_ERROR Unable to lock the BLocale.
137	\retval B_NO_MEMORY Ran out of memory while creating the object.
138	\retval B_BAD_VALUE There was not enough space to store the result.
139
140	\since Haiku R1
141*/
142
143
144/*!
145	\fn status_t BTimeFormat::GetTimeFields(BDateElement*& fields, int& fieldCount,
146		BTimeFormatStyle style) const
147	\brief Get the type of each field in the time format of the locale.
148
149	This method is used most often in combination with FormatTime().
150	FormatTime() gives you the offset of each field in a formatted string,
151	and GetTimeFields() gives you the type of the field at a given offset.
152	With this information you can handle the formatted time string as
153	a list of fields that you can split and alter at will.
154
155	\param fields Pointer to the fields object.
156	\param fieldCount The number of fields.
157	\param style Specify the long format or the short format.
158
159	\returns A status code.
160	\retval B_OK Everything went fine.
161	\retval B_ERROR Unable to lock the BLocale.
162	\retval B_NO_MEMORY Ran out of memory while creating the object.
163	\retval B_BAD_VALUE Bad or invalid \a fields data.
164
165	\since Haiku R1
166*/
167