ICU 76.1: icu::TimeUnitFormat Class Reference

ICU 76.1 76.1

Public Member Functions | Static Public Member Functions | Friends
icu::TimeUnitFormat Class Reference

Format or parse a TimeUnitAmount, using plural rules for the units where available. More...

`#include <tmutfmt.h>`

Inheritance diagram for icu::TimeUnitFormat:

## Public Member Functions
| TimeUnitFormat (UErrorCode &status)
| Create TimeUnitFormat with default locale, and full name style.
| TimeUnitFormat (const Locale &locale, UErrorCode &status)
| Create TimeUnitFormat given locale, and full name style.
| TimeUnitFormat (const Locale &locale, UTimeUnitFormatStyle style, UErrorCode &status)
| Create TimeUnitFormat given locale and style.
| TimeUnitFormat (const TimeUnitFormat &)
| Copy constructor.
virtual | ~TimeUnitFormat ()
| deconstructor
virtual TimeUnitFormat * | clone () const override
| Clone this Format object polymorphically.
TimeUnitFormat & | operator= (const TimeUnitFormat &other)
| Assignment operator.
void | setLocale (const Locale &locale, UErrorCode &status)
| Set the locale used for formatting or parsing.
void | setNumberFormat (const NumberFormat &format, UErrorCode &status)
| Set the number format used for formatting or parsing.
virtual void | parseObject (const UnicodeString &source, Formattable &result, ParsePosition &pos) const override
| Parse a TimeUnitAmount.
virtual UClassID | getDynamicClassID () const override
| Returns a unique class ID POLYMORPHICALLY.
Public Member Functions inherited from icu::MeasureFormat
| MeasureFormat (const Locale &locale, UMeasureFormatWidth width, UErrorCode &status)
| Constructor.
| MeasureFormat (const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
| Constructor.
| MeasureFormat (const MeasureFormat &other)
| Copy constructor.
MeasureFormat & | operator= (const MeasureFormat &rhs)
| Assignment operator.
virtual | ~MeasureFormat ()
| Destructor.
virtual bool | operator== (const Format &other) const override
| Return true if given Format objects are semantically equal.
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const override
| Formats object to produce a string.
UnicodeString & | formatMeasures (const Measure *measures, int32_t measureCount, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
| Formats measure objects to produce a string.
UnicodeString & | formatMeasurePerUnit (const Measure &measure, const MeasureUnit &perUnit, UnicodeString &appendTo, FieldPosition &pos, UErrorCode &status) const
| Formats a single measure per unit.
UnicodeString | getUnitDisplayName (const MeasureUnit &unit, UErrorCode &status) const
| Gets the display name of the specified `MeasureUnit` corresponding to the current locale and format width.
void | parseObject (const UnicodeString &source, Formattable &result, UErrorCode &status) const
| Parses a string to produce an object.
UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
| Formats an object to produce a string.
virtual UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, FieldPositionIterator *posIter, UErrorCode &status) const
| Format an object to produce a string.
Public Member Functions inherited from icu::Format
virtual | ~Format ()
| Destructor.
bool | operator!= (const Format &other) const
| Return true if the given Format objects are not semantically equal.
UnicodeString & | format (const Formattable &obj, UnicodeString &appendTo, UErrorCode &status) const
| Formats an object to produce a string.
void | parseObject (const UnicodeString &source, Formattable &result, UErrorCode &status) const
| Parses a string to produce an object.
Locale | getLocale (ULocDataLocaleType type, UErrorCode &status) const
| Get the locale for this format object.
const char * | getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
| Get the locale for this format object.
Public Member Functions inherited from icu::UObject
virtual | ~UObject ()
| Destructor.

## Static Public Member Functions
static UClassID | getStaticClassID ()
| Return the class ID for this class.
Static Public Member Functions inherited from icu::MeasureFormat
static MeasureFormat * | createCurrencyFormat (const Locale &locale, UErrorCode &ec)
| Return a formatter for CurrencyAmount objects in the given locale.
static MeasureFormat * | createCurrencyFormat (UErrorCode &ec)
| Return a formatter for CurrencyAmount objects in the default locale.
static UClassID | getStaticClassID ()
| Return the class ID for this class.

## Friends
struct | TimeUnitFormatReadSink

## Additional Inherited Members
Protected Member Functions inherited from icu::MeasureFormat
| MeasureFormat ()
| Default constructor.
void | initMeasureFormat (const Locale &locale, UMeasureFormatWidth width, NumberFormat *nfToAdopt, UErrorCode &status)
| ICU use only.
UBool | setMeasureFormatLocale (const Locale &locale, UErrorCode &status)
| ICU use only.
void | adoptNumberFormat (NumberFormat *nfToAdopt, UErrorCode &status)
| ICU use only.
const NumberFormat & | getNumberFormatInternal () const
| ICU use only.
const NumberFormat & | getCurrencyFormatInternal () const
| ICU use only.
const PluralRules & | getPluralRules () const
| ICU use only.
Locale | getLocale (UErrorCode &status) const
| ICU use only.
const char * | getLocaleID (UErrorCode &status) const
| ICU use only.
Protected Member Functions inherited from icu::Format
void | setLocaleIDs (const char *valid, const char *actual)
| Format ()
| Default constructor for subclass use only.
| Format (const Format &)
Format & | operator= (const Format &)
Static Protected Member Functions inherited from icu::Format
static void | syntaxError (const UnicodeString &pattern, int32_t pos, UParseError &parseError)
| Simple function for initializing a UParseError from a UnicodeString.

## Detailed Description

Format or parse a TimeUnitAmount, using plural rules for the units where available.

Code Sample:

      // create time unit amount instance - a combination of Number and time unit
      UErrorCode status = U_ZERO_ERROR;
      TimeUnitAmount* source = new TimeUnitAmount(2, TimeUnit::UTIMEUNIT_YEAR, status);
      // create time unit format instance
      TimeUnitFormat* format = new TimeUnitFormat(Locale("en"), status);
      // format a time unit amount
      UnicodeString formatted;
      Formattable formattable;
      if (U_SUCCESS(status)) {
          formattable.adoptObject(source);
          formatted = ((Format*)format)->format(formattable, formatted, status);
          Formattable result;
          ((Format*)format)->parseObject(formatted, result, status);
          if (U_SUCCESS(status)) {
              assert (result == formattable);
          }
      }

See also
  TimeUnitAmount
  TimeUnitFormat

Deprecated
  ICU 53 Use the MeasureFormat class instead.

Definition at line 89 of file tmutfmt.h.

## Constructor & Destructor Documentation

## ◆ TimeUnitFormat() [1/4]

icu::TimeUnitFormat::TimeUnitFormat | ( | UErrorCode & | status | ) |

Create TimeUnitFormat with default locale, and full name style.

Use setLocale and/or setFormat to modify.

Deprecated
  ICU 53

## ◆ TimeUnitFormat() [2/4]

icu::TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale,
|  | UErrorCode & | status )

Create TimeUnitFormat given locale, and full name style.

Deprecated
  ICU 53

## ◆ TimeUnitFormat() [3/4]

icu::TimeUnitFormat::TimeUnitFormat | ( | const Locale & | locale,
|  | UTimeUnitFormatStyle | style,
|  | UErrorCode & | status )

Create TimeUnitFormat given locale and style.

Deprecated
  ICU 53

## ◆ TimeUnitFormat() [4/4]

icu::TimeUnitFormat::TimeUnitFormat | ( | const TimeUnitFormat & |  | ) |

Copy constructor.

Deprecated
  ICU 53

## ◆ ~TimeUnitFormat()

virtual icu::TimeUnitFormat::~TimeUnitFormat | ( |  | ) |
| virtual

deconstructor

Deprecated
  ICU 53

## Member Function Documentation

## ◆ clone()

virtual TimeUnitFormat * icu::TimeUnitFormat::clone | ( |  | ) | const
| overridevirtual

Clone this Format object polymorphically.

The caller owns the result and should delete it when done.

Returns
  A copy of the object.

Deprecated
  ICU 53

Reimplemented from icu::MeasureFormat.

## ◆ getDynamicClassID()

virtual UClassID icu::TimeUnitFormat::getDynamicClassID | ( |  | ) | const
| overridevirtual

Returns a unique class ID POLYMORPHICALLY.

Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.

Returns
  The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.

Deprecated
  ICU 53

Reimplemented from icu::MeasureFormat.

## ◆ getStaticClassID()

static UClassID icu::TimeUnitFormat::getStaticClassID | ( |  | ) |
| static

Return the class ID for this class.

This is useful only for comparing to a return value from getDynamicClassID(). For example:

    .   Base* polymorphic_pointer = createPolymorphicObject();
    .   if (polymorphic_pointer->getDynamicClassID() ==
    .       erived::getStaticClassID()) ...

Returns
  The class ID for all objects of this class.

Deprecated
  ICU 53

## ◆ operator=()

TimeUnitFormat & icu::TimeUnitFormat::operator= | ( | const TimeUnitFormat & | other | ) |

Assignment operator.

Deprecated
  ICU 53

## ◆ parseObject()

virtual void icu::TimeUnitFormat::parseObject | ( | const UnicodeString & | source,
|  | Formattable & | result,
|  | ParsePosition & | pos ) const
| overridevirtual

Parse a TimeUnitAmount.

See also
  Format::parseObject(const UnicodeString&, Formattable&, ParsePosition&) const;

Deprecated
  ICU 53

Reimplemented from icu::MeasureFormat.

## ◆ setLocale()

void icu::TimeUnitFormat::setLocale | ( | const Locale & | locale,
|  | UErrorCode & | status )

Set the locale used for formatting or parsing.

Parameters

  locale | the locale to be set
  status | output param set to success/failure code on exit

Deprecated
  ICU 53

## ◆ setNumberFormat()

void icu::TimeUnitFormat::setNumberFormat | ( | const NumberFormat & | format,
|  | UErrorCode & | status )

Set the number format used for formatting or parsing.

Parameters

  format | the number formatter to be set
  status | output param set to success/failure code on exit

Deprecated
  ICU 53

## Friends And Related Symbol Documentation

## ◆ TimeUnitFormatReadSink

friend struct TimeUnitFormatReadSink
| friend

Definition at line 227 of file tmutfmt.h.

The documentation for this class was generated from the following file:

- i18n/unicode/tmutfmt.h