Formatter for dates.
More...
Inherits BFormat.
|
| 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.
|
|
Formatter for dates.
- Since
- Haiku R1
◆ BDateFormat() [1/3]
BDateFormat::BDateFormat |
( |
const BLocale * |
locale = NULL | ) |
|
Locale constructor.
- Parameters
-
locale | The 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
-
language | The language to use. |
format | The formatting convention to use. |
- Since
- Haiku R1
◆ BDateFormat() [3/3]
Copy Constructor.
- Parameters
-
- Since
- Haiku R1
◆ ~BDateFormat()
BDateFormat::~BDateFormat |
( |
| ) |
|
|
virtual |
Destructor.
- Since
- Haiku R1
◆ Format() [1/3]
Fills in string with a formatted date for the given time, style, and timeZone for the locale.
- Parameters
-
string | The string buffer to fill with the formatted date. |
time | The time (in seconds since epoch) to format |
style | Specify the long format (with day name, full month name) or the short format, 08/12/2010 or similar. |
timeZone | Specifies the time zone to use, if NULL , use the system default time zone (usually UTC). |
- Returns
- A status code.
- Return values
-
B_OK | Everything went fine. |
B_ERROR | Unable to lock the BLocale. |
B_NO_MEMORY | Ran 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
-
string | The string buffer to fill with the formatted date. |
fieldPositions | An array of date field positions to be filled out. |
fieldCount | The number of fields in fieldPositions to be filled out. |
time | The time (in seconds since epoch) to format |
style | Specify 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_OK | Everything went fine. |
B_ERROR | Unable to lock the BLocale. |
B_NO_MEMORY | Ran out of memory while creating the string buffer or fieldPositions array. |
B_BAD_VALUE | There 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
-
string | The string buffer to fill with the formatted date. |
maxSize | The size of the buffer. |
time | The time (in seconds since epoch) to format |
style | Specify 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_ERROR | Unable to lock the BLocale. |
B_NO_MEMORY | Ran out of memory while creating the object. |
B_BAD_VALUE | There 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
-
fields | Pointer to the array of BDateElement objects. |
fieldCount | The number of fields in fields. |
style | Specify 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_OK | Everything went fine. |
B_ERROR | Unable to lock the BLocale. |
B_NO_MEMORY | Ran out of memory while creating the object. |
B_BAD_VALUE | Bad 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_OK | Everything went fine. |
B_BAD_VALUE | startOfWeek is NULL . |
B_ERROR | Unable to lock the BLocale or another error occurred. |
- Since
- Haiku R1