Loading...
Searching...
No Matches
Public Member Functions | List of all members
BDateFormat Class Reference

Formatter for dates. More...

Inherits BFormat.

Public Member Functions

 BDateFormat (const BDateFormat &other)
 Copy Constructor.
 
 BDateFormat (const BLanguage &language, const BFormattingConventions &format)
 Language and formatting convention constructor.
 
 BDateFormat (const BLocale *locale=NULL)
 Locale constructor.
 
virtual ~BDateFormat ()
 Destructor.
 
status_t Format (BString &string, const time_t time, const BDateFormatStyle style, const BTimeZone *timeZone=NULL) const
 Fills in string with a formatted date for the given time, style, and timeZone for the locale.
 
status_t Format (BString &string, int *&fieldPositions, int &fieldCount, const time_t time, const BDateFormatStyle style) const
 Fills in string with a custom formatted date according to the given parameters for the locale and fills out an array of fieldPositions which must be freed by the caller and a fieldCount which contains the number of positions.
 
ssize_t Format (char *string, const size_t maxSize, const time_t time, const BDateFormatStyle style) const
 Fills in string with a formatted date up to maxSize bytes for the given time and style for the locale.
 
status_t GetFields (BDateElement *&fields, int &fieldCount, BDateFormatStyle style) const
 Get the type of each field in the date format of the locale.
 
status_t GetStartOfWeek (BWeekday *weekday) const
 Returns the day used as the start of week in this locale.
 

Detailed Description

Formatter for dates.

Since
Haiku R1

Constructor & Destructor Documentation

◆ BDateFormat() [1/3]

BDateFormat::BDateFormat ( const BLocale locale = NULL)

Locale constructor.

Parameters
localeThe locale to use, can be NULL for the default locale.
Since
Haiku R1

◆ BDateFormat() [2/3]

BDateFormat::BDateFormat ( const BLanguage &  language,
const BFormattingConventions &  format 
)

Language and formatting convention constructor.

Parameters
languageThe language to use.
formatThe formatting convention to use.
Since
Haiku R1

◆ BDateFormat() [3/3]

BDateFormat::BDateFormat ( const BDateFormat other)

Copy Constructor.

Parameters
otherThe BDateFormat object to copy from.
Since
Haiku R1

◆ ~BDateFormat()

BDateFormat::~BDateFormat ( )
virtual

Destructor.

Since
Haiku R1

Member Function Documentation

◆ Format() [1/3]

status_t BDateFormat::Format ( BString string,
const time_t  time,
const BDateFormatStyle  style,
const BTimeZone timeZone = NULL 
) const

Fills in string with a formatted date for the given time, style, and timeZone for the locale.

Parameters
stringThe string buffer to fill with the formatted date.
timeThe time (in seconds since epoch) to format
styleSpecify the long format (with day name, full month name) or the short format, 08/12/2010 or similar.
timeZoneSpecifies the time zone to use, if NULL, use the system default time zone (usually UTC).
Returns
A status code.
Return values
B_OKEverything went fine.
B_ERRORUnable to lock the BLocale.
B_NO_MEMORYRan out of memory while creating the object.
Since
Haiku R1

◆ Format() [2/3]

status_t BDateFormat::Format ( BString string,
int *&  fieldPositions,
int &  fieldCount,
const time_t  time,
const BDateFormatStyle  style 
) const

Fills in string with a custom formatted date according to the given parameters for the locale and fills out an array of fieldPositions which must be freed by the caller and a fieldCount which contains the number of positions.

The positions are offsets in the string at which each element of the date (day, month, year, etc) and the separator starting positions. These can be used, for example, to split the string into parts to use in a locale-aware set of BMenuFields to edit the date in the local format.

Parameters
stringThe string buffer to fill with the formatted date.
fieldPositionsAn array of date field positions to be filled out.
fieldCountThe number of fields in fieldPositions to be filled out.
timeThe time (in seconds since epoch) to format
styleSpecify the long format (with day name, full month name) or the short format, 08/12/2010 or similar.
Returns
A status code.
Return values
B_OKEverything went fine.
B_ERRORUnable to lock the BLocale.
B_NO_MEMORYRan out of memory while creating the string buffer or fieldPositions array.
B_BAD_VALUEThere was not enough space to store the result.
Since
Haiku R1

◆ Format() [3/3]

ssize_t BDateFormat::Format ( char *  string,
const size_t  maxSize,
const time_t  time,
const BDateFormatStyle  style 
) const

Fills in string with a formatted date up to maxSize bytes for the given time and style for the locale.

Parameters
stringThe string buffer to fill with the formatted date.
maxSizeThe size of the buffer.
timeThe time (in seconds since epoch) to format
styleSpecify the long format (with day name, full month name) or the short format, 08/12/2010 or similar.
Returns
The number of bytes written during the date formatting.
Return values
B_ERRORUnable to lock the BLocale.
B_NO_MEMORYRan out of memory while creating the object.
B_BAD_VALUEThere was not enough space to store the result.
Since
Haiku R1

◆ GetFields()

status_t BDateFormat::GetFields ( BDateElement *&  fields,
int &  fieldCount,
BDateFormatStyle  style 
) const

Get the type of each field in the date format of the locale.

This method is most often used in combination with the version of Format() that takes a fieldPositions parameter. Format() gives you the offset of each field in a formatted string, and GetFields() gives you the type of the field at a given offset. With these informations, you can handle the formatted date string as a list of fields that you can split and alter at will.

Parameters
fieldsPointer to the array of BDateElement objects.
fieldCountThe number of fields in fields.
styleSpecify the long format (with day name, full month name) or the short format, "08/12/2010" or similar.
Returns
A status code.
Return values
B_OKEverything went fine.
B_ERRORUnable to lock the BLocale.
B_NO_MEMORYRan out of memory while creating the object.
B_BAD_VALUEBad or invalid fields data.
See also
BDateFormat::GetFields(BDateElement*&, int&, BTimeFormatStyle) const
BDateFormat::Format(BString&, int*&, int&, const time_t, const BDateFormatStyle) const
Since
Haiku R1

◆ GetStartOfWeek()

status_t BDateFormat::GetStartOfWeek ( BWeekday *  startOfWeek) const

Returns the day used as the start of week in this locale.

Possible values for startOfWeek include:

  • B_WEEKDAY_SUNDAY
  • B_WEEKDAY_MONDAY
  • B_WEEKDAY_TUESDAY
  • B_WEEKDAY_WEDNESDAY
  • B_WEEKDAY_THURSDAY
  • B_WEEKDAY_FRIDAY
  • B_WEEKDAY_SATURDAY
Returns
A status code.
Return values
B_OKEverything went fine.
B_BAD_VALUEstartOfWeek is NULL.
B_ERRORUnable to lock the BLocale or another error occurred.
Since
Haiku R1