2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FLclDateTimeFormatter.h
19 * @brief This is the header file for the %DateTimeFormatter class.
21 * This header file contains the declarations of the %DateTimeFormatter class.
24 #ifndef _FLCL_DATE_TIME_FORMATTER_H_
25 #define _FLCL_DATE_TIME_FORMATTER_H_
28 #include <FBaseString.h>
29 #include <FLclCalendar.h>
30 #include <FLclDateTimeSymbols.h>
33 namespace Tizen { namespace Locales
36 // forward declaration
37 class NumberFormatter;
39 class _DateTimeFormatterImpl;
45 * Defines the style for date and time.
51 DATE_TIME_STYLE_NONE = -1, /**< The date time style: None */
52 DATE_TIME_STYLE_FULL = 0, /**< The date time style: FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42PM PST */
53 DATE_TIME_STYLE_LONG = 1, /**< The date time style: LONG is longer, such as July 18, 2012 or 3:30:32PM */
54 DATE_TIME_STYLE_MEDIUM = 2, /**< The date time style: MEDIUM is a little longer, such as Jan 12, 1952 */
55 DATE_TIME_STYLE_SHORT = 3, /**< The date time style: SHORT is completely numeric, such as 12/13/52 or 3:30PM */
56 DATE_TIME_STYLE_DEFAULT = DATE_TIME_STYLE_MEDIUM /**< The default date time style: Medium */
60 * @class DateTimeFormatter
61 * @brief This class provides methods for formatting the date and time formats.
65 * The %DateTimeFormatter class is used to format the date and time formats in a language-independent manner.
66 * The date and time are represented as a Tizen::Base::DateTime instance.
68 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/locales/datetime_formatter.htm">Date and Time Formatter</a>.
70 * @see Tizen::Base::DateTime
71 * @see DateTimeSymbols
73 * The following example demonstrates how to use the %DateTimeFormatter class.
80 using namespace Tizen::Base;
81 using namespace Tizen::Locales;
82 using namespace Tizen::System;
85 LocaleApp::DateTimeFormatterExample(void)
88 Locale locale(LANGUAGE_ENG, COUNTRY_US);
92 SystemTime::GetCurrentTime(TIME_MODE_UTC, today);
95 DateTimeFormatter* pDateFormatter = DateTimeFormatter::CreateDateFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
97 String formattedString;
99 // Format today with date formatter
100 pDateFormatter->Format(today, formattedString);
102 // Get time formatter
103 DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
105 // Format today with time formatter
106 pTimeFormatter->Format(today, formattedString);
108 // Customized pattern
109 String cutomizedPattern = L"EEE d MMM yy";
110 pDateFormatter->ApplyPattern(cutomizedPattern);
112 // Format today with date formatter
113 pDateFormatter->Format(today, formattedString);
115 delete pDateFormatter;
116 delete pTimeFormatter;
121 class _OSP_EXPORT_ DateTimeFormatter
122 : public Tizen::Base::Object
126 * This is the destructor for this class. @n
127 * This destructor overrides Tizen::Base::Object::~Object().
131 virtual ~DateTimeFormatter(void);
134 * Creates the date formatter with the specified formatting style for the system locale.
138 * @return A pointer to the system locale date formatter, @n
139 * else @c null if an error occurs
140 * @param[in] style The formatting style @n
141 * For example, "M/d/yy" is the short form for displaying only date in the US locale.
142 * @exception E_SUCCESS The method is successful.
143 * @exception E_OUT_OF_MEMORY The memory is insufficient.
144 * @exception E_UNSUPPORTED_OPERATION The current locale is not supported.
145 * @exception E_INVALID_ARG The specified @c style is an invalid value.
146 * @remarks The specific error code can be accessed using the GetLastResult() method.
148 static DateTimeFormatter* CreateDateFormatterN(DateTimeStyle style = DATE_TIME_STYLE_DEFAULT);
152 * Creates the date formatter with the specified formatting style for the specified locale.
155 * @brief <i> [Compatibility] </i>
159 * @compatibility This method has compatibility issues with OSP compatible applications. @n
160 * For more information, see @ref CompDateTimeFormatterCreateDateFormatterNPage "here".
163 * @return A pointer to the specified locale date formatter, @n
164 * else @c null if an error occurs
165 * @param[in] locale The locale
166 * @param[in] style The formatting style @n
167 * For example, "M/d/yy" is the short form for displaying only date in the US locale.
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_OUT_OF_MEMORY The memory is insufficient.
170 * @exception E_INVALID_ARG The specified @c locale or @c style is invalid.
171 * @remarks The specific error code can be accessed using the GetLastResult() method.
173 static DateTimeFormatter* CreateDateFormatterN(const Locale& locale, DateTimeStyle style = DATE_TIME_STYLE_DEFAULT);
177 * @page CompDateTimeFormatterCreateDateFormatterNPage Compatibility for CreateDateFormatterN()
178 * @section CompDateTimeFormatterCreateDateFormatterNIssueSection Issues
179 * Implementation of this method in OSP compatible applications has the following issue: @n
180 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
182 * @section CompDateTimeFormatterCreateDateFormatterNtSolutionSection Resolutions
183 * This issue has been resolved in Tizen.
184 * @par When working in Tizen:
185 * -# The method returns E_INVALID_ARG if the @c locale or @c style is invalid.
191 * Creates the time formatter with the specified formatting style for the system locale.
195 * @return A pointer to the system locale time formatter, @n
196 * else @c null if an error occurs
197 * @param[in] style The formatting style @n
198 * For example, "h:mm a" is the short form for displaying the 12-hour time format in the US locale.
199 * @exception E_SUCCESS The method is successful.
200 * @exception E_OUT_OF_MEMORY The memory is insufficient.
201 * @exception E_UNSUPPORTED_OPERATION The current locale is not supported.
202 * @exception E_INVALID_ARG The specified @c style is invalid.
203 * @remarks The specific error code can be accessed using the GetLastResult() method.
205 static DateTimeFormatter* CreateTimeFormatterN(DateTimeStyle style = DATE_TIME_STYLE_DEFAULT);
209 * Creates the time formatter with the specified formatting style for the specified @c locale.
212 * @brief <i> [Compatibility] </i>
216 * @compatibility This method has compatibility issues with OSP compatible applications. @n
217 * For more information, see @ref CompDateTimeFormatterCreateTimeFormatterNPage "here".
220 * @return A pointer to the specified locale time formatter, @n
221 * else @c null if an error occurs
222 * @param[in] locale The locale
223 * @param[in] style The formatting style @n
224 * For example, "h:mm a" is the short form for displaying the 12-hour time format in the US locale.
225 * @exception E_SUCCESS The method is successful.
226 * @exception E_OUT_OF_MEMORY The memory is insufficient.
227 * @exception E_INVALID_ARG The specified @c locale or @c style is invalid.
228 * @remarks The specific error code can be accessed using the GetLastResult() method.
230 static DateTimeFormatter* CreateTimeFormatterN(const Locale& locale, DateTimeStyle style = DATE_TIME_STYLE_DEFAULT);
234 * @page CompDateTimeFormatterCreateTimeFormatterNPage Compatibility for CreateTimeFormatterN()
235 * @section CompDateTimeFormatterCreateTimeFormatterNIssueSection Issues
236 * Implementation of this method in OSP compatible applications has the following issue: @n
237 * -# The method returns E_UNSUPPORTED_OPERATION if the @c locale is invalid.
239 * @section CompGrDateTimeFormatterCreateTimeFormatterNSolutionSection Resolutions
240 * This issue has been resolved in Tizen.
241 * @par When working in Tizen:
242 * -# The method returns E_INVALID_ARG if the @c locale or @c style is invalid.
247 * Creates the date/time formatter with the specified formatting style for the system locale.
251 * @return A pointer to the system locale date/time formatter, @n
252 * else @c null if an error occurs
253 * @param[in] dateStyle The date formatting style @n
254 * For example, "M/d/yy" is the short form for displaying only date in the US locale.
255 * @param[in] timeStyle The time formatting style @n
256 * For example, "h:mm a" is the short form for displaying the 12-hour time format in the US locale.
257 * @exception E_SUCCESS The method is successful.
258 * @exception E_OUT_OF_MEMORY The memory is insufficient.
259 * @exception E_UNSUPPORTED_OPERATION The current locale is not supported.
260 * @exception E_INVALID_ARG The specified @c dateStyle or @c timeStyle is invalid.
261 * @remarks The specific error code can be accessed using the GetLastResult() method.
263 static DateTimeFormatter* CreateDateTimeFormatterN(DateTimeStyle dateStyle = DATE_TIME_STYLE_DEFAULT, DateTimeStyle timeStyle = DATE_TIME_STYLE_DEFAULT);
267 * Creates the date/time formatter with the specified formatting style for the specified @c locale.
271 * @return A pointer to the specified locale date/time formatter, @n
272 * else @c null if an error occurs
273 * @param[in] locale The locale
274 * @param[in] dateStyle The date formatting style @n
275 * For example, "M/d/yy" is the short form for displaying only date in the US locale.
276 * @param[in] timeStyle The time formatting style @n
277 * For example, "h:mm a" is the short form for displaying the 12-hour time format in the US locale.
278 * @exception E_SUCCESS The method is successful.
279 * @exception E_OUT_OF_MEMORY The memory is insufficient.
280 * @exception E_INVALID_ARG The specified @c locale is not supported, or the @c dateStyle or the @c timeStyle is invalid.
281 * @remarks The specific error code can be accessed using the GetLastResult() method.
283 static DateTimeFormatter* CreateDateTimeFormatterN(const Locale& locale, DateTimeStyle dateStyle = DATE_TIME_STYLE_DEFAULT, DateTimeStyle timeStyle = DATE_TIME_STYLE_DEFAULT);
286 * Formats a Tizen::Base::DateTime object into a date/time string and appends the resulting string to the specified string buffer.
290 * @return An error code
291 * @param[in] date The Tizen::Base::DateTime object to format
292 * @param[out] str The string to append to the resultant string
293 * @exception E_SUCCESS The method is successful.
294 * @remarks This method does not handle the time zone information, so "z" pattern always returns "GMT+00:00".
295 * @see Tizen::Base::DateTime
297 virtual result Format(const Tizen::Base::DateTime& date, Tizen::Base::String& str) const;
301 * Formats a Calendar object into a date/time string and appends the resulting string to the specified string buffer.
305 * @return An error code
306 * @param[in] calendar The Calendar object to format
307 * @param[out] str The string to append to the resultant string
308 * @exception E_SUCCESS The method is successful.
309 * @see Tizen::Base::DateTime
311 virtual result Format(const Calendar& calendar, Tizen::Base::String& str) const;
315 * Applies the specified pattern string to the date format.
319 * @param[in] pattern The new date and time pattern for the date format
320 * @exception E_SUCCESS The method is successful.
321 * @exception E_INVALID_ARG The length of the specified @c pattern is @c 0.
323 result ApplyPattern(const Tizen::Base::String& pattern);
327 * Gets a pattern string describing the date format.
331 * @return A string describing the date format
333 Tizen::Base::String GetPattern(void) const;
337 * Gets the date and time format symbols of the formatter.
341 * @return A pointer to DateTimeSymbols for the formatter instance
342 * @see SetDateTimeSymbols()
344 const DateTimeSymbols* GetDateTimeSymbols(void) const;
348 * Sets the date and time format symbols of the date format.
352 * @param[in] newSymbols The new date and time format symbols
353 * @see GetDateTimeSymbols()
355 void SetDateTimeSymbols(const DateTimeSymbols& newSymbols);
358 NumberFormatter* __pNumberFormat;
359 Calendar* __pCalendar;
362 * This default constructor is intentionally declared as private so that only the platform can create an instance.
364 DateTimeFormatter(void);
367 * The implementation of this copy constructor is intentionally blank and declared as private to
368 * prohibit copying of objects.
370 DateTimeFormatter(const DateTimeFormatter& dateTimeFormatter);
373 * The implementation of this copy assignment operator is intentionally blank and declared as private
374 * to prohibit copying of objects.
376 DateTimeFormatter& operator =(const DateTimeFormatter& dateTimeFormatter);
378 friend class _DateTimeFormatterImpl;
379 class _DateTimeFormatterImpl* __pDateTimeFormatterImpl;
380 }; // DateTimeFormatter
384 #endif //_FLCL_DATE_TIME_FORMATTER_H_