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 BTimeFormat class, a date formatter. 20*4a31c326SJohn Scipione*/ 21*4a31c326SJohn Scipione 22*4a31c326SJohn Scipione 23*4a31c326SJohn Scipione/*! 24*4a31c326SJohn Scipione \class BTimeFormat 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 BTimeFormat::BTimeFormat() 35*4a31c326SJohn Scipione \brief Constructor. 36*4a31c326SJohn Scipione*/ 37*4a31c326SJohn Scipione 38*4a31c326SJohn Scipione 39*4a31c326SJohn Scipione/*! 40*4a31c326SJohn Scipione \fn BTimeFormat::BTimeFormat(const BLanguage& language, 41*4a31c326SJohn Scipione const BFormattingConventions& format); 42*4a31c326SJohn Scipione \brief Language and formatting convention constructor. 43*4a31c326SJohn Scipione 44*4a31c326SJohn Scipione \param language The \a language to use. 45*4a31c326SJohn Scipione \param format The formatting convention to use. 46*4a31c326SJohn Scipione*/ 47*4a31c326SJohn Scipione 48*4a31c326SJohn Scipione 49*4a31c326SJohn Scipione/*! 50*4a31c326SJohn Scipione \fn BTimeFormat::BTimeFormat(const BTimeFormat& other) 51*4a31c326SJohn Scipione \brief Copy Constructor. 52*4a31c326SJohn Scipione 53*4a31c326SJohn Scipione \param other The BTimeFormat object to copy from. 54*4a31c326SJohn Scipione 55*4a31c326SJohn Scipione \since Haiku R1 56*4a31c326SJohn Scipione*/ 57*4a31c326SJohn Scipione 58*4a31c326SJohn Scipione 59*4a31c326SJohn Scipione/*! 60*4a31c326SJohn Scipione \fn BTimeFormat::~BTimeFormat() 61*4a31c326SJohn Scipione \brief Destructor. 62*4a31c326SJohn Scipione 63*4a31c326SJohn Scipione \since Haiku R1 64*4a31c326SJohn Scipione*/ 65*4a31c326SJohn Scipione 66*4a31c326SJohn Scipione 67*4a31c326SJohn Scipione/*! 68*4a31c326SJohn Scipione \fn ssize_t BTimeFormat::Format(char* string, size_t maxSize, time_t time, 69*4a31c326SJohn Scipione BTimeFormatStyle style) const 70*4a31c326SJohn Scipione \brief Fills in \a string with a formatted date up to \a maxSize bytes for 71*4a31c326SJohn Scipione the given \a time and \a style for the locale. 72*4a31c326SJohn Scipione 73*4a31c326SJohn Scipione \param string The string buffer to fill with the formatted time. 74*4a31c326SJohn Scipione \param maxSize The size of the buffer. 75*4a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 76*4a31c326SJohn Scipione \param style Specify the long format or the short format. 77*4a31c326SJohn Scipione 78*4a31c326SJohn Scipione \returns The number of bytes written during the time formatting. 79*4a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 80*4a31c326SJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the DateFormat object. 81*4a31c326SJohn Scipione \retval B_BAD_VALUE CheckedArrayByteSink overflowed. 82*4a31c326SJohn Scipione 83*4a31c326SJohn Scipione \since Haiku R1 84*4a31c326SJohn Scipione*/ 85*4a31c326SJohn Scipione 86*4a31c326SJohn Scipione 87*4a31c326SJohn Scipione/*! 88*4a31c326SJohn Scipione \fn status_t BTimeFormat::Format(char* string, size_t maxSize, 89*4a31c326SJohn Scipione time_t time, BTimeFormatStyle style) const 90*4a31c326SJohn Scipione \brief Fills in \a string with a formatted time for the given 91*4a31c326SJohn Scipione \a time, \a style, and \a timeZone for the locale. 92*4a31c326SJohn Scipione 93*4a31c326SJohn Scipione \param string The string buffer to fill with the formatted date. 94*4a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 95*4a31c326SJohn Scipione \param style Specify the long format or the short format. 96*4a31c326SJohn Scipione 97*4a31c326SJohn Scipione \returns A status code. 98*4a31c326SJohn Scipione \retval B_OK Everything went fine. 99*4a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 100*4a31c326SJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the DateFormat object. 101*4a31c326SJohn Scipione 102*4a31c326SJohn Scipione \sa BLocale::FormatDate(BString *string, time_t time, 103*4a31c326SJohn Scipione BTimeFormatStyle style, const BTimeZone* timeZone) const 104*4a31c326SJohn Scipione \sa BLocale::FormatDateTime(BString* target, time_t time, 105*4a31c326SJohn Scipione BTimeFormatStyle dateStyle, BTimeFormatStyle timeStyle, 106*4a31c326SJohn Scipione const BTimeZone* timeZone) const 107*4a31c326SJohn Scipione 108*4a31c326SJohn Scipione \since Haiku R1 109*4a31c326SJohn Scipione*/ 110*4a31c326SJohn Scipione 111*4a31c326SJohn Scipione 112*4a31c326SJohn Scipione/*! 113*4a31c326SJohn Scipione \fn status_t BTimeFormat::Format(BString& string, const time_t time, 114*4a31c326SJohn Scipione const BTimeFormatStyle style, const BTimeZone* timeZone) const 115*4a31c326SJohn Scipione \brief Fills in \a string with a formatted time 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 time. 119*4a31c326SJohn Scipione \param time The time (in seconds since epoch) to format. 120*4a31c326SJohn Scipione \param style Specify the long format or the short format. 121*4a31c326SJohn Scipione \param timeZone The time zone to use, if \c NULL, uses the one set by the 122*4a31c326SJohn Scipione locale. 123*4a31c326SJohn Scipione 124*4a31c326SJohn Scipione \returns A status code. 125*4a31c326SJohn Scipione \retval B_OK Everything went fine. 126*4a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 127*4a31c326SJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the DateFormat object. 128*4a31c326SJohn Scipione \retval B_BAD_VALUE An error occurred during time formatting. 129*4a31c326SJohn Scipione 130*4a31c326SJohn Scipione \since Haiku R1 131*4a31c326SJohn Scipione*/ 132*4a31c326SJohn Scipione 133*4a31c326SJohn Scipione 134*4a31c326SJohn Scipione/*! 135*4a31c326SJohn Scipione \fn status_t BTimeFormat::Format(BString& string, 136*4a31c326SJohn Scipione int*& fieldPositions, int& fieldCount, 137*4a31c326SJohn Scipione time_t time, BTimeFormatStyle style) const 138*4a31c326SJohn Scipione \brief Fills in \a string with a formatted time for the given parameters. 139*4a31c326SJohn Scipione 140*4a31c326SJohn Scipione \param string The string buffer to fill with the formatted date. 141*4a31c326SJohn Scipione \param fieldPositions An array of date field positions to use. 142*4a31c326SJohn Scipione \param fieldCount The number of \a fields in \a fieldPositions. 143*4a31c326SJohn Scipione \param time The time (in seconds since epoch) to format 144*4a31c326SJohn Scipione \param style Specify the long format (with day name, full 145*4a31c326SJohn Scipione month name) or the short format, 08/12/2010 or similar. 146*4a31c326SJohn Scipione 147*4a31c326SJohn Scipione \returns A status code. 148*4a31c326SJohn Scipione \retval B_OK Everything went fine. 149*4a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 150*4a31c326SJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the DateFormat object. 151*4a31c326SJohn Scipione \retval B_BAD_VALUE An error occurred while performing the date formatting. 152*4a31c326SJohn Scipione 153*4a31c326SJohn Scipione \since Haiku R1 154*4a31c326SJohn Scipione*/ 155*4a31c326SJohn Scipione 156*4a31c326SJohn Scipione 157*4a31c326SJohn Scipione/*! 158*4a31c326SJohn Scipione \fn status_t BTimeFormat::GetTimeFields(BDateElement*& fields, int& fieldCount, 159*4a31c326SJohn Scipione BTimeFormatStyle style) const 160*4a31c326SJohn Scipione \brief Get the type of each field in the time format of the locale. 161*4a31c326SJohn Scipione 162*4a31c326SJohn Scipione This method is used most often in combination with FormatTime(). 163*4a31c326SJohn Scipione FormatTime() gives you the offset of each field in a formatted string, 164*4a31c326SJohn Scipione and GetTimeFields() gives you the type of the field at a given offset. 165*4a31c326SJohn Scipione With this information you can handle the formatted date string as 166*4a31c326SJohn Scipione a list of fields that you can split and alter at will. 167*4a31c326SJohn Scipione 168*4a31c326SJohn Scipione \param fields Pointer to the fields object. 169*4a31c326SJohn Scipione \param fieldCount The number of fields. 170*4a31c326SJohn Scipione \param style Specify the long format or the short format. 171*4a31c326SJohn Scipione 172*4a31c326SJohn Scipione \returns A status code. 173*4a31c326SJohn Scipione \retval B_OK Everything went fine. 174*4a31c326SJohn Scipione \retval B_ERROR Unable to lock the BLocale. 175*4a31c326SJohn Scipione \retval B_NO_MEMORY Ran out of memory while creating the DateFormat object. 176*4a31c326SJohn Scipione \retval B_BAD_VALUE An error occurred while getting the time fields. 177*4a31c326SJohn Scipione 178*4a31c326SJohn Scipione \since Haiku R1 179*4a31c326SJohn Scipione*/ 180