Public Member Functions | List of all members
BTimeFormat Class Reference

Formatter for times. More...

Inherits BFormat.

Public Member Functions

 BTimeFormat ()
 Default Constructor. The current system locale is used. More...
 
 BTimeFormat (const BLanguage &language, const BFormattingConventions &conventions)
 Language and formatting convention constructor. More...
 
 BTimeFormat (const BTimeFormat &other)
 Copy Constructor. More...
 
virtual ~BTimeFormat ()
 Destructor. More...
 
ssize_t Format (char *string, size_t maxSize, time_t time, BTimeFormatStyle style) const
 Fills in string with a formatted time up to maxSize bytes for the given time and style for the locale. More...
 
status_t Format (BString &string, const time_t time, const BTimeFormatStyle style, const BTimeZone *timeZone=NULL) const
 Fills in string with a formatted time for the given time, style, and timeZone for the locale. More...
 
status_t Format (BString &string, int *&fieldPositions, int &fieldCount, time_t time, BTimeFormatStyle 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. More...
 
status_t GetTimeFields (BDateElement *&fields, int &fieldCount, BTimeFormatStyle style) const
 Get the type of each field in the time format of the locale. More...
 

Detailed Description

Formatter for times.

Since
Haiku R1

Constructor & Destructor Documentation

◆ BTimeFormat() [1/3]

BTimeFormat::BTimeFormat ( )

Default Constructor. The current system locale is used.

Since
Haiku R1

◆ BTimeFormat() [2/3]

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

Language and formatting convention constructor.

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

◆ BTimeFormat() [3/3]

BTimeFormat::BTimeFormat ( const BTimeFormat other)

Copy Constructor.

Parameters
otherThe BTimeFormat object to copy from.
Since
Haiku R1

◆ ~BTimeFormat()

BTimeFormat::~BTimeFormat ( )
virtual

Destructor.

Since
Haiku R1

Member Function Documentation

◆ Format() [1/3]

status_t BTimeFormat::Format ( char *  string,
size_t  maxSize,
time_t  time,
BTimeFormatStyle  style 
) const

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

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

Parameters
stringThe string buffer to fill with the formatted time.
maxSizeThe size of the buffer.
timeThe time (in seconds since midnight) to format.
styleSpecify the long format or the short format.
Returns
The number of bytes written during the time 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
Parameters
stringThe string buffer to fill with the formatted time.
timeThe time (in seconds since midnight) to format.
styleSpecify the long format or the short format.
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.
See also
BLocale::FormatDate(BString*, time_t, BTimeFormatStyle, const BTimeZone*) const
BLocale::FormatDateTime(BString*, time_t, BTimeFormatStyle, BTimeFormatStyle, const BTimeZone*) const
Since
Haiku R1

◆ Format() [2/3]

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

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

Parameters
stringThe string buffer to fill with the formatted time.
timeThe time (in seconds since epoch) to format.
styleSpecifies whether to use the long format or short format.
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.
B_BAD_VALUEThere was not enough space to store the result.
Since
Haiku R1

◆ Format() [3/3]

status_t BTimeFormat::Format ( BString string,
int *&  fieldPositions,
int &  fieldCount,
time_t  time,
BTimeFormatStyle  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 time (hour, minute, second, etc) and the separator starting positions. These can be used, for example, to split the string in parts to use in a locale-aware set of BMenuFields to edit the time in the local format.

Parameters
stringThe string buffer to fill with the formatted time.
fieldPositionsAn array of time 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 object.
B_BAD_VALUEThere was not enough space to store the result.
Since
Haiku R1

◆ GetTimeFields()

status_t BTimeFormat::GetTimeFields ( BDateElement *&  fields,
int &  fieldCount,
BTimeFormatStyle  style 
) const

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

This method is used most often in combination with FormatTime(). FormatTime() gives you the offset of each field in a formatted string, and GetTimeFields() gives you the type of the field at a given offset. With this information you can handle the formatted time string as a list of fields that you can split and alter at will.

Parameters
fieldsPointer to the fields object.
fieldCountThe number of fields.
styleSpecify the long format or the short format.
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.
Since
Haiku R1