mirror of
https://review.haiku-os.org/haiku
synced 2025-02-09 15:18:56 +01:00
* Move relevant parts up into BFormat so other format classes can use those * Adjust BDurationFormat and BTimeUnitFormat for the changes * Remove the "default" date format, it is better to keep only a default locale and let applications create B*Formats from it as needed. * Creating a B*Format without arguments to the constructor now configures it for the default locale, which allows for easy use in standard cases (formatting something with the current language and format) * Creating a B*Format is potentially an expansive operation, it is advised to keep the instance around and reuse it whenever possible. However it must be "refreshed" when the locale changes, for apps which supports that, since it keeps a copy of the language and formatting convention, rather than a pointer to the locale as it did before.
61 lines
1.1 KiB
C++
61 lines
1.1 KiB
C++
/*
|
|
* Copyright 2010-2011, Haiku, Inc.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _B_TIME_UNIT_FORMAT_H_
|
|
#define _B_TIME_UNIT_FORMAT_H_
|
|
|
|
|
|
#include <Format.h>
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
class BString;
|
|
|
|
namespace icu {
|
|
class TimeUnitFormat;
|
|
}
|
|
|
|
|
|
enum time_unit_style {
|
|
B_TIME_UNIT_ABBREVIATED, // e.g. '5 hrs.'
|
|
B_TIME_UNIT_FULL, // e.g. '5 hours'
|
|
};
|
|
|
|
|
|
enum time_unit_element {
|
|
B_TIME_UNIT_YEAR,
|
|
B_TIME_UNIT_MONTH,
|
|
B_TIME_UNIT_WEEK,
|
|
B_TIME_UNIT_DAY,
|
|
B_TIME_UNIT_HOUR,
|
|
B_TIME_UNIT_MINUTE,
|
|
B_TIME_UNIT_SECOND,
|
|
|
|
B_TIME_UNIT_LAST = B_TIME_UNIT_SECOND
|
|
};
|
|
|
|
|
|
class BTimeUnitFormat : public BFormat {
|
|
typedef BFormat Inherited;
|
|
|
|
public:
|
|
BTimeUnitFormat();
|
|
BTimeUnitFormat(const BTimeUnitFormat& other);
|
|
virtual ~BTimeUnitFormat();
|
|
|
|
BTimeUnitFormat& operator=(const BTimeUnitFormat& other);
|
|
|
|
virtual status_t SetLanguage(const BLanguage& locale);
|
|
status_t Format(int32 value, time_unit_element unit,
|
|
BString* buffer,
|
|
time_unit_style style = B_TIME_UNIT_FULL
|
|
) const;
|
|
|
|
private:
|
|
icu::TimeUnitFormat* fFormatter;
|
|
};
|
|
|
|
|
|
#endif
|