14a31c326SJohn Scipione/* 24a31c326SJohn Scipione * Copyright 2011-2014 Haiku, Inc. All rights reserved. 34a31c326SJohn Scipione * Distributed under the terms of the MIT License. 44a31c326SJohn Scipione * 54a31c326SJohn Scipione * Authors: 64a31c326SJohn Scipione * Adrien Destugues, pulkomandy@pulkomandy.ath.cx 74a31c326SJohn Scipione * John Scipione, jscipione@gmail.com 84a31c326SJohn Scipione * 94a31c326SJohn Scipione * Corresponds to: 104a31c326SJohn Scipione * headers/os/locale/DateFormat.h hrev48439 114a31c326SJohn Scipione * src/kits/locale/DateFormat.cpp hrev48439 124a31c326SJohn Scipione */ 134a31c326SJohn Scipione 144a31c326SJohn Scipione 154a31c326SJohn Scipione/*! 164a31c326SJohn Scipione \file DateFormat.h 174a31c326SJohn Scipione \ingroup locale 184a31c326SJohn Scipione \ingroup libbe 19*71f6259aSJohn Scipione \brief Contains BDateFormat class, a date formatter and parser. 204a31c326SJohn Scipione*/ 214a31c326SJohn Scipione 224a31c326SJohn Scipione 234a31c326SJohn Scipione/*! 244a31c326SJohn Scipione \class BDateFormat 254a31c326SJohn Scipione \ingroup locale 264a31c326SJohn Scipione \ingroup libbe 274a31c326SJohn Scipione \brief Formatter for dates. 284a31c326SJohn Scipione 294a31c326SJohn Scipione \since Haiku R1 304a31c326SJohn Scipione*/ 314a31c326SJohn Scipione 324a31c326SJohn Scipione 334a31c326SJohn Scipione/*! 344a31c326SJohn Scipione \fn BDateFormat::BDateFormat(const BLocale* locale) 354a31c326SJohn Scipione \brief Locale constructor. 364a31c326SJohn Scipione 374a31c326SJohn Scipione \param locale The locale to use, can be \c NULL for the default locale. 38*71f6259aSJohn Scipione 39*71f6259aSJohn Scipione \since Haiku R1 404a31c326SJohn Scipione*/ 414a31c326SJohn Scipione 424a31c326SJohn Scipione 434a31c326SJohn Scipione/*! 444a31c326SJohn Scipione \fn BDateFormat::BDateFormat(const BLanguage& language, 454a31c326SJohn Scipione const BFormattingConventions& format); 464a31c326SJohn Scipione \brief Language and formatting convention constructor. 474a31c326SJohn Scipione 484a31c326SJohn Scipione \param language The \a language to use. 494a31c326SJohn Scipione \param format The formatting convention to use. 50*71f6259aSJohn Scipione 51*71f6259aSJohn Scipione \since Haiku R1 524a31c326SJohn Scipione*/ 534a31c326SJohn Scipione 544a31c326SJohn Scipione 554a31c326SJohn Scipione/*! 564a31c326SJohn Scipione \fn BDateFormat::BDateFormat(const BDateFormat& other) 574a31c326SJohn Scipione \brief Copy Constructor. 584a31c326SJohn Scipione 594a31c326SJohn Scipione \param other The BDateFormat object to copy from. 604a31c326SJohn Scipione 614a31c326SJohn Scipione \since Haiku R1 624a31c326SJohn Scipione*/ 634a31c326SJohn Scipione 644a31c326SJohn Scipione 654a31c326SJohn Scipione/*! 664a31c326SJohn Scipione \fn BDateFormat::~BDateFormat() 674a31c326SJohn Scipione \brief Destructor. 684a31c326SJohn Scipione 694a31c326SJohn Scipione \since Haiku R1 704a31c326SJohn Scipione*/ 714a31c326SJohn Scipione 724a31c326SJohn Scipione 734a31c326SJohn Scipione/*! 744a31c326SJohn Scipione \fn ssize_t BDateFormat::Format(char* string, const size_t maxSize, 754a31c326SJohn Scipione const time_t time, const BDateFormatStyle style) const 764a31c326SJohn Scipione \brief Fills in \a string with a formatted date up to \a maxSize bytes for 774a31c326SJohn Scipione the given \a time and \a style for the locale. 784a31c326SJohn Scipione 794a31c326SJohn Scipione \param string The string buffer to fill with the formatted date. 804a31c326SJohn Scipione \param maxSize The size of the buffer. 814a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 824a31c326SJohn Scipione \param style Specify the long format (with day name, full 834a31c326SJohn Scipione month name) or the short format, 08/12/2010 or similar. 844a31c326SJohn Scipione 854a31c326SJohn Scipione \returns The number of bytes written during the date formatting. 864a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 877ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 88*71f6259aSJohn Scipione \retval B_BAD_VALUE There was not enough space to store the result. 894a31c326SJohn Scipione 904a31c326SJohn Scipione \since Haiku R1 914a31c326SJohn Scipione*/ 924a31c326SJohn Scipione 934a31c326SJohn Scipione 944a31c326SJohn Scipione/*! 954a31c326SJohn Scipione \fn status_t BDateFormat::Format(BString& string, const time_t time, 964a31c326SJohn Scipione const BDateFormatStyle style, const BTimeZone* timeZone) const 974a31c326SJohn Scipione \brief Fills in \a string with a formatted date for the given 984a31c326SJohn Scipione \a time, \a style, and \a timeZone for the locale. 994a31c326SJohn Scipione 1004a31c326SJohn Scipione \param string The string buffer to fill with the formatted date. 1014a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 1024a31c326SJohn Scipione \param style Specify the long format (with day name, full 1034a31c326SJohn Scipione month name) or the short format, 08/12/2010 or similar. 104*71f6259aSJohn Scipione \param timeZone Specifies the time zone to use, if \c NULL, use the 105*71f6259aSJohn Scipione system default time zone (usually UTC). 1064a31c326SJohn Scipione 1074a31c326SJohn Scipione \returns A status code. 1084a31c326SJohn Scipione \retval B_OK Everything went fine. 1094a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 1107ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 1114a31c326SJohn Scipione 1124a31c326SJohn Scipione \since Haiku R1 1134a31c326SJohn Scipione*/ 1144a31c326SJohn Scipione 1154a31c326SJohn Scipione 1164a31c326SJohn Scipione/*! 1174a31c326SJohn Scipione \fn status_t BDateFormat::Format(BString& string, 1184a31c326SJohn Scipione int*& fieldPositions, int& fieldCount, const time_t time, 1194a31c326SJohn Scipione const BDateFormatStyle style) const 1209bd3dedfSJohn Scipione \brief Fills in \a string with a custom formatted date according to the 121*71f6259aSJohn Scipione given parameters for the locale and fills out an array of 122*71f6259aSJohn Scipione \a fieldPositions which must be freed by the caller and a 123*71f6259aSJohn Scipione \a fieldCount which contains the number of positions. 124*71f6259aSJohn Scipione 125*71f6259aSJohn Scipione The positions are offsets in the string at which each element of the date 126*71f6259aSJohn Scipione (day, month, year, etc) and the separator starting positions. These 127*71f6259aSJohn Scipione can be used, for example, to split the string into parts to use in a 128*71f6259aSJohn Scipione locale-aware set of BMenuFields to edit the date in the local format. 1294a31c326SJohn Scipione 1304a31c326SJohn Scipione \param string The string buffer to fill with the formatted date. 131*71f6259aSJohn Scipione \param fieldPositions An array of date field positions to be filled out. 132*71f6259aSJohn Scipione \param fieldCount The number of \a fields in \a fieldPositions to be 133*71f6259aSJohn Scipione filled out. 1344a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 1354a31c326SJohn Scipione \param style Specify the long format (with day name, full 1364a31c326SJohn Scipione month name) or the short format, 08/12/2010 or similar. 1374a31c326SJohn Scipione 1384a31c326SJohn Scipione \returns A status code. 1394a31c326SJohn Scipione \retval B_OK Everything went fine. 1404a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 141*71f6259aSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the \a string buffer 142*71f6259aSJohn Scipione or \a fieldPositions array. 143*71f6259aSJohn Scipione \retval B_BAD_VALUE There was not enough space to store the result. 1444a31c326SJohn Scipione 1454a31c326SJohn Scipione \since Haiku R1 1464a31c326SJohn Scipione*/ 1474a31c326SJohn Scipione 1484a31c326SJohn Scipione 1494a31c326SJohn Scipione/*! 1504a31c326SJohn Scipione \fn status_t BDateFormat::GetFields(BDateElement*& fields, int& fieldCount, 1514a31c326SJohn Scipione BDateFormatStyle style) const 1524a31c326SJohn Scipione \brief Get the type of each field in the date format of the locale. 1534a31c326SJohn Scipione 154*71f6259aSJohn Scipione This method is most often used in combination with the version of Format() 155*71f6259aSJohn Scipione that takes a fieldPositions parameter. Format() gives you the offset of 156*71f6259aSJohn Scipione each field in a formatted string, and GetFields() gives you the type of 157*71f6259aSJohn Scipione the field at a given offset. With these informations, you can handle the 158*71f6259aSJohn Scipione formatted date string as a list of fields that you can split and alter at 159*71f6259aSJohn Scipione will. 1604a31c326SJohn Scipione 161*71f6259aSJohn Scipione \param fields Pointer to the array of BDateElement objects. 162*71f6259aSJohn Scipione \param fieldCount The number of fields in \a fields. 163*71f6259aSJohn Scipione \param style Specify the long format (with day name, full month name) 164*71f6259aSJohn Scipione or the short format, "08/12/2010" or similar. 1654a31c326SJohn Scipione 1664a31c326SJohn Scipione \returns A status code. 1674a31c326SJohn Scipione \retval B_OK Everything went fine. 1684a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 1697ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 170*71f6259aSJohn Scipione \retval B_BAD_VALUE Bad or invalid \a fields data. 1714a31c326SJohn Scipione 172*71f6259aSJohn Scipione \sa BDateFormat::GetFields(BDateElement*&, int&, BTimeFormatStyle) const 173*71f6259aSJohn Scipione \sa BDateFormat::Format(BString&, int*&, int&, const time_t, 174*71f6259aSJohn Scipione const BDateFormatStyle) const 1754a31c326SJohn Scipione 1764a31c326SJohn Scipione \since Haiku R1 1774a31c326SJohn Scipione*/ 1784a31c326SJohn Scipione 1794a31c326SJohn Scipione 1804a31c326SJohn Scipione/*! 1814a31c326SJohn Scipione \fn status_t BDateFormat::GetStartOfWeek(BWeekday* startOfWeek) const 1824a31c326SJohn Scipione \brief Returns the day used as the start of week in this locale. 1834a31c326SJohn Scipione 1844a31c326SJohn Scipione Possible values for \a startOfWeek include: 1854a31c326SJohn Scipione - \c B_WEEKDAY_SUNDAY 1864a31c326SJohn Scipione - \c B_WEEKDAY_MONDAY 1874a31c326SJohn Scipione - \c B_WEEKDAY_TUESDAY 1884a31c326SJohn Scipione - \c B_WEEKDAY_WEDNESDAY 1894a31c326SJohn Scipione - \c B_WEEKDAY_THURSDAY 1904a31c326SJohn Scipione - \c B_WEEKDAY_FRIDAY 1914a31c326SJohn Scipione - \c B_WEEKDAY_SATURDAY 1924a31c326SJohn Scipione 1934a31c326SJohn Scipione \returns A status code. 1944a31c326SJohn Scipione \retval B_OK Everything went fine. 1954a31c326SJohn Scipione \retval B_BAD_VALUE \a startOfWeek is \c NULL. 1964a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale or another error occurred. 1974a31c326SJohn Scipione 1984a31c326SJohn Scipione \since Haiku R1 1994a31c326SJohn Scipione*/ 200