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: 10*7ec9bf2fSJohn Scipione * headers/os/locale/TimeFormat.h hrev48439 11*7ec9bf2fSJohn Scipione * src/kits/locale/TimeFormat.cpp hrev48439 124a31c326SJohn Scipione */ 134a31c326SJohn Scipione 144a31c326SJohn Scipione 154a31c326SJohn Scipione/*! 169bd3dedfSJohn Scipione \file TimeFormat.h 174a31c326SJohn Scipione \ingroup locale 184a31c326SJohn Scipione \ingroup libbe 199bd3dedfSJohn Scipione \brief Contains BTimeFormat class, a time formatter. 204a31c326SJohn Scipione*/ 214a31c326SJohn Scipione 224a31c326SJohn Scipione 234a31c326SJohn Scipione/*! 244a31c326SJohn Scipione \class BTimeFormat 254a31c326SJohn Scipione \ingroup locale 264a31c326SJohn Scipione \ingroup libbe 279bd3dedfSJohn Scipione \brief Formatter for times. 284a31c326SJohn Scipione 294a31c326SJohn Scipione \since Haiku R1 304a31c326SJohn Scipione*/ 314a31c326SJohn Scipione 324a31c326SJohn Scipione 334a31c326SJohn Scipione/*! 344a31c326SJohn Scipione \fn BTimeFormat::BTimeFormat() 354a31c326SJohn Scipione \brief Constructor. 364a31c326SJohn Scipione*/ 374a31c326SJohn Scipione 384a31c326SJohn Scipione 394a31c326SJohn Scipione/*! 404a31c326SJohn Scipione \fn BTimeFormat::BTimeFormat(const BLanguage& language, 414a31c326SJohn Scipione const BFormattingConventions& format); 424a31c326SJohn Scipione \brief Language and formatting convention constructor. 434a31c326SJohn Scipione 444a31c326SJohn Scipione \param language The \a language to use. 454a31c326SJohn Scipione \param format The formatting convention to use. 464a31c326SJohn Scipione*/ 474a31c326SJohn Scipione 484a31c326SJohn Scipione 494a31c326SJohn Scipione/*! 504a31c326SJohn Scipione \fn BTimeFormat::BTimeFormat(const BTimeFormat& other) 514a31c326SJohn Scipione \brief Copy Constructor. 524a31c326SJohn Scipione 534a31c326SJohn Scipione \param other The BTimeFormat object to copy from. 544a31c326SJohn Scipione 554a31c326SJohn Scipione \since Haiku R1 564a31c326SJohn Scipione*/ 574a31c326SJohn Scipione 584a31c326SJohn Scipione 594a31c326SJohn Scipione/*! 604a31c326SJohn Scipione \fn BTimeFormat::~BTimeFormat() 614a31c326SJohn Scipione \brief Destructor. 624a31c326SJohn Scipione 634a31c326SJohn Scipione \since Haiku R1 644a31c326SJohn Scipione*/ 654a31c326SJohn Scipione 664a31c326SJohn Scipione 674a31c326SJohn Scipione/*! 684a31c326SJohn Scipione \fn ssize_t BTimeFormat::Format(char* string, size_t maxSize, time_t time, 694a31c326SJohn Scipione BTimeFormatStyle style) const 709bd3dedfSJohn Scipione \brief Fills in \a string with a formatted time up to \a maxSize bytes for 714a31c326SJohn Scipione the given \a time and \a style for the locale. 724a31c326SJohn Scipione 734a31c326SJohn Scipione \param string The string buffer to fill with the formatted time. 744a31c326SJohn Scipione \param maxSize The size of the buffer. 754a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 764a31c326SJohn Scipione \param style Specify the long format or the short format. 774a31c326SJohn Scipione 784a31c326SJohn Scipione \returns The number of bytes written during the time formatting. 794a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 80*7ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 814a31c326SJohn Scipione \retval B_BAD_VALUE CheckedArrayByteSink overflowed. 824a31c326SJohn Scipione 834a31c326SJohn Scipione \since Haiku R1 844a31c326SJohn Scipione*/ 854a31c326SJohn Scipione 864a31c326SJohn Scipione 874a31c326SJohn Scipione/*! 884a31c326SJohn Scipione \fn status_t BTimeFormat::Format(char* string, size_t maxSize, 894a31c326SJohn Scipione time_t time, BTimeFormatStyle style) const 904a31c326SJohn Scipione \brief Fills in \a string with a formatted time for the given 914a31c326SJohn Scipione \a time, \a style, and \a timeZone for the locale. 924a31c326SJohn Scipione 93*7ec9bf2fSJohn Scipione \param string The string buffer to fill with the formatted time. 944a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 954a31c326SJohn Scipione \param style Specify the long format or the short format. 964a31c326SJohn Scipione 974a31c326SJohn Scipione \returns A status code. 984a31c326SJohn Scipione \retval B_OK Everything went fine. 994a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 100*7ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 1014a31c326SJohn Scipione 1024a31c326SJohn Scipione \sa BLocale::FormatDate(BString *string, time_t time, 1034a31c326SJohn Scipione BTimeFormatStyle style, const BTimeZone* timeZone) const 1044a31c326SJohn Scipione \sa BLocale::FormatDateTime(BString* target, time_t time, 1054a31c326SJohn Scipione BTimeFormatStyle dateStyle, BTimeFormatStyle timeStyle, 1064a31c326SJohn Scipione const BTimeZone* timeZone) const 1074a31c326SJohn Scipione 1084a31c326SJohn Scipione \since Haiku R1 1094a31c326SJohn Scipione*/ 1104a31c326SJohn Scipione 1114a31c326SJohn Scipione 1124a31c326SJohn Scipione/*! 1134a31c326SJohn Scipione \fn status_t BTimeFormat::Format(BString& string, const time_t time, 1144a31c326SJohn Scipione const BTimeFormatStyle style, const BTimeZone* timeZone) const 1154a31c326SJohn Scipione \brief Fills in \a string with a formatted time for the given 1164a31c326SJohn Scipione \a time and \a style for the locale. 1174a31c326SJohn Scipione 1184a31c326SJohn Scipione \param string The string buffer to fill with the formatted time. 1194a31c326SJohn Scipione \param time The time (in seconds since epoch) to format. 1204a31c326SJohn Scipione \param style Specify the long format or the short format. 1214a31c326SJohn Scipione \param timeZone The time zone to use, if \c NULL, uses the one set by the 1224a31c326SJohn Scipione locale. 1234a31c326SJohn Scipione 1244a31c326SJohn Scipione \returns A status code. 1254a31c326SJohn Scipione \retval B_OK Everything went fine. 1264a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 127*7ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 1284a31c326SJohn Scipione \retval B_BAD_VALUE An error occurred during time formatting. 1294a31c326SJohn Scipione 1304a31c326SJohn Scipione \since Haiku R1 1314a31c326SJohn Scipione*/ 1324a31c326SJohn Scipione 1334a31c326SJohn Scipione 1344a31c326SJohn Scipione/*! 1354a31c326SJohn Scipione \fn status_t BTimeFormat::Format(BString& string, 1364a31c326SJohn Scipione int*& fieldPositions, int& fieldCount, 1374a31c326SJohn Scipione time_t time, BTimeFormatStyle style) const 1389bd3dedfSJohn Scipione \brief Fills in \a string with a custom formatted time according to the 1399bd3dedfSJohn Scipione given parameters for the locale. 1404a31c326SJohn Scipione 141*7ec9bf2fSJohn Scipione \param string The string buffer to fill with the formatted time. 142*7ec9bf2fSJohn Scipione \param fieldPositions An array of time field positions to use. 1434a31c326SJohn Scipione \param fieldCount The number of \a fields in \a fieldPositions. 1444a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 1454a31c326SJohn Scipione \param style Specify the long format (with day name, full 1464a31c326SJohn Scipione month name) or the short format, 08/12/2010 or similar. 1474a31c326SJohn Scipione 1484a31c326SJohn Scipione \returns A status code. 1494a31c326SJohn Scipione \retval B_OK Everything went fine. 1504a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 151*7ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 152*7ec9bf2fSJohn Scipione \retval B_BAD_VALUE An error occurred while performing the time formatting. 1534a31c326SJohn Scipione 1544a31c326SJohn Scipione \since Haiku R1 1554a31c326SJohn Scipione*/ 1564a31c326SJohn Scipione 1574a31c326SJohn Scipione 1584a31c326SJohn Scipione/*! 1594a31c326SJohn Scipione \fn status_t BTimeFormat::GetTimeFields(BDateElement*& fields, int& fieldCount, 1604a31c326SJohn Scipione BTimeFormatStyle style) const 1614a31c326SJohn Scipione \brief Get the type of each field in the time format of the locale. 1624a31c326SJohn Scipione 1634a31c326SJohn Scipione This method is used most often in combination with FormatTime(). 1644a31c326SJohn Scipione FormatTime() gives you the offset of each field in a formatted string, 1654a31c326SJohn Scipione and GetTimeFields() gives you the type of the field at a given offset. 166*7ec9bf2fSJohn Scipione With this information you can handle the formatted time string as 1674a31c326SJohn Scipione a list of fields that you can split and alter at will. 1684a31c326SJohn Scipione 1694a31c326SJohn Scipione \param fields Pointer to the fields object. 1704a31c326SJohn Scipione \param fieldCount The number of fields. 1714a31c326SJohn Scipione \param style Specify the long format or the short format. 1724a31c326SJohn Scipione 1734a31c326SJohn Scipione \returns A status code. 1744a31c326SJohn Scipione \retval B_OK Everything went fine. 1754a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 176*7ec9bf2fSJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the object. 1774a31c326SJohn Scipione \retval B_BAD_VALUE An error occurred while getting the time fields. 1784a31c326SJohn Scipione 1794a31c326SJohn Scipione \since Haiku R1 1804a31c326SJohn Scipione*/ 181