- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- Search for |

- Alphabetical List
- Data Structures
- Class Hierarchy
- Data Fields

# DateTimePatternGenerator Class Reference

This class provides flexible generation of date format patterns, like "yy-MM-dd". More...

`#include <dtptngen.h>`

Inheritance diagram for DateTimePatternGenerator:

## Public Member Functions
virtual | ~DateTimePatternGenerator ()
| Destructor.
DateTimePatternGenerator * | clone () const
| Clone DateTimePatternGenerator object.
UBool | operator== (const DateTimePatternGenerator &other) const
| Return true if another object is semantically equal to this one.
UBool | operator!= (const DateTimePatternGenerator &other) const
| Return true if another object is semantically unequal to this one.
UnicodeString | getSkeleton (const UnicodeString &pattern, UErrorCode &status)
| Utility to return a unique skeleton from a given pattern.
UnicodeString | getBaseSkeleton (const UnicodeString &pattern, UErrorCode &status)
| Utility to return a unique base skeleton from a given pattern.
UDateTimePatternConflict | addPattern (const UnicodeString &pattern, UBool override, UnicodeString &conflictingPattern, UErrorCode &status)
| Adds a pattern to the generator.
void | setAppendItemFormat (UDateTimePatternField field, const UnicodeString &value)
| An AppendItem format is a pattern used to append a field if there is no good match.
const UnicodeString & | getAppendItemFormat (UDateTimePatternField field) const
| Getter corresponding to setAppendItemFormat.
void | setAppendItemName (UDateTimePatternField field, const UnicodeString &value)
| Sets the names of field, eg "era" in English for ERA.
const UnicodeString & | getAppendItemName (UDateTimePatternField field) const
| Getter corresponding to setAppendItemNames.
void | setDateTimeFormat (const UnicodeString &dateTimeFormat)
| The date time format is a message format pattern used to compose date and time patterns.
const UnicodeString & | getDateTimeFormat () const
| Getter corresponding to setDateTimeFormat.
UnicodeString | getBestPattern (const UnicodeString &skeleton, UErrorCode &status)
| Return the best pattern matching the input skeleton.
UnicodeString | replaceFieldTypes (const UnicodeString &pattern, const UnicodeString &skeleton, UErrorCode &status)
| Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.
StringEnumeration * | getSkeletons (UErrorCode &status) const
| Return a list of all the skeletons (in canonical form) from this class.
const UnicodeString & | getPatternForSkeleton (const UnicodeString &skeleton) const
| Get the pattern corresponding to a given skeleton.
StringEnumeration * | getBaseSkeletons (UErrorCode &status) const
| Return a list of all the base skeletons (in canonical form) from this class.
StringEnumeration * | getRedundants (UErrorCode &status)
| Return a list of redundant patterns are those which if removed, make no difference in the resulting getBestPattern values.
void | setDecimal (const UnicodeString &decimal)
| The decimal value is used in formatting fractions of seconds.
const UnicodeString & | getDecimal () const
| Getter corresponding to setDecimal.
virtual UClassID | getDynamicClassID () const
| ICU "poor man's RTTI", returns a UClassID for the actual class.
## Static Public Member Functions
static DateTimePatternGenerator * | createInstance (UErrorCode &status)
| Construct a flexible generator according to default locale.
static DateTimePatternGenerator * | createInstance (const Locale &uLocale, UErrorCode &status)
| Construct a flexible generator according to data for a given locale.
static DateTimePatternGenerator * | createEmptyInstance (UErrorCode &status)
| Create an empty generator, to be constructed with addPattern(.
static UClassID | getStaticClassID (void)
| ICU "poor man's RTTI", returns a UClassID for this class.

## Detailed Description

This class provides flexible generation of date format patterns, like "yy-MM-dd".

The user can build up the generator by adding successive patterns. Once that is done, a query can be made using a "skeleton", which is a pattern which just includes the desired fields and lengths. The generator will return the "best fit" pattern corresponding to that skeleton.

The main method people will use is getBestPattern(String skeleton), since normally this class is pre-built with data from a particular locale. However, generators can be built directly from other data as well.

Issue: may be useful to also have a function that returns the list of fields in a pattern, in order, since we have that internally. That would be useful for getting the UI order of field elements.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

Definition at line 42 of file dtptngen.h.

## Constructor & Destructor Documentation

virtual DateTimePatternGenerator::~DateTimePatternGenerator | ( |  | ) | `[virtual]`

Destructor.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

## Member Function Documentation

static DateTimePatternGenerator* DateTimePatternGenerator::createInstance | ( | UErrorCode & | status | ) | `[static]`

Construct a flexible generator according to default locale.

Parameters:

  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

static DateTimePatternGenerator* DateTimePatternGenerator::createInstance | ( | const Locale & | uLocale,
|  | UErrorCode & | status |
| ) |  |  | `[static]`

Construct a flexible generator according to data for a given locale.

Parameters:

  | uLocale |
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

static DateTimePatternGenerator* DateTimePatternGenerator::createEmptyInstance | ( | UErrorCode & | status | ) | `[static]`

Create an empty generator, to be constructed with addPattern(.

..) etc.

Parameters:

  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

DateTimePatternGenerator* DateTimePatternGenerator::clone | ( |  | ) | const

Clone DateTimePatternGenerator object.

Clients are responsible for deleting the DateTimePatternGenerator object cloned.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UBool DateTimePatternGenerator::operator== | ( | const DateTimePatternGenerator & | other | ) | const

Return true if another object is semantically equal to this one.

Parameters:

  | other | the DateTimePatternGenerator object to be compared with.

Returns:
  true if other is semantically equal to this.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UBool DateTimePatternGenerator::operator!= | ( | const DateTimePatternGenerator & | other | ) | const

Return true if another object is semantically unequal to this one.

Parameters:

  | other | the DateTimePatternGenerator object to be compared with.

Returns:
  true if other is semantically unequal to this.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UnicodeString DateTimePatternGenerator::getSkeleton | ( | const UnicodeString & | pattern,
|  | UErrorCode & | status |
| ) |  |  |

Utility to return a unique skeleton from a given pattern.

For example, both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".

Parameters:

  | pattern | Input pattern, such as "dd/MMM"
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  skeleton such as "MMMdd"

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UnicodeString DateTimePatternGenerator::getBaseSkeleton | ( | const UnicodeString & | pattern,
|  | UErrorCode & | status |
| ) |  |  |

Utility to return a unique base skeleton from a given pattern.

This is the same as the skeleton, except that differences in length are minimized so as to only preserve the difference between string and numeric form. So for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd" (notice the single d).

Parameters:

  | pattern | Input pattern, such as "dd/MMM"
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  base skeleton, such as "Md"

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UDateTimePatternConflict DateTimePatternGenerator::addPattern | ( | const UnicodeString & | pattern,
|  | UBool | override,
|  | UnicodeString & | conflictingPattern,
|  | UErrorCode & | status |
| ) |  |  |

Adds a pattern to the generator.

If the pattern has the same skeleton as an existing pattern, and the override parameter is set, then the previous value is overriden. Otherwise, the previous value is retained. In either case, the conflicting status is set and previous vale is stored in conflicting pattern.

Note that single-field patterns (like "MMM") are automatically added, and don't need to be added explicitly!

Parameters:

  | pattern | Input pattern, such as "dd/MMM"
  | override | When existing values are to be overridden use true, otherwise use false.
  | conflictingPattern | Previous pattern with the same skeleton.
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  conflicting status. The value could be UDATPG_NO_CONFLICT, UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

void DateTimePatternGenerator::setAppendItemFormat | ( | UDateTimePatternField | field,
|  | const UnicodeString & | value |
| ) |  |  |

An AppendItem format is a pattern used to append a field if there is no good match.

For example, suppose that the input skeleton is "GyyyyMMMd", and there is no matching pattern internally, but there is a pattern matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the G. The way these two are conjoined is by using the AppendItemFormat for G (era). So if that value is, say "{0}, {1}" then the final resulting pattern is "d-MM-yyyy, G".

There are actually three available variables: {0} is the pattern so far, {1} is the element we are adding, and {2} is the name of the element.

This reflects the way that the CLDR data is organized.

Parameters:

  | field | such as UDATPG_ERA_FIELD.
  | value | pattern, such as "{0}, {1}"

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

const UnicodeString& DateTimePatternGenerator::getAppendItemFormat | ( | UDateTimePatternField | field | ) | const

Getter corresponding to setAppendItemFormat.

Values below 0 or at or above UDATPG_FIELD_COUNT are illegal arguments.

Parameters:

  | field | such as UDATPG_ERA_FIELD.

Returns:
  append pattern for field

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

void DateTimePatternGenerator::setAppendItemName | ( | UDateTimePatternField | field,
|  | const UnicodeString & | value |
| ) |  |  |

Sets the names of field, eg "era" in English for ERA.

These are only used if the corresponding AppendItemFormat is used, and if it contains a {2} variable.

This reflects the way that the CLDR data is organized.

Parameters:

  | field | such as UDATPG_ERA_FIELD.
  | value | name of the field

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

const UnicodeString& DateTimePatternGenerator::getAppendItemName | ( | UDateTimePatternField | field | ) | const

Getter corresponding to setAppendItemNames.

Values below 0 or at or above UDATPG_FIELD_COUNT are illegal arguments.

Parameters:

  | field | such as UDATPG_ERA_FIELD.

Returns:
  name for field

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

void DateTimePatternGenerator::setDateTimeFormat | ( | const UnicodeString & | dateTimeFormat | ) |

The date time format is a message format pattern used to compose date and time patterns.

The default value is "{0} {1}", where {0} will be replaced by the date pattern and {1} will be replaced by the time pattern.

This is used when the input skeleton contains both date and time fields, but there is not a close match among the added patterns. For example, suppose that this object was created by adding "dd-MMM" and "hh:mm", and its datetimeFormat is the default "{0} {1}". Then if the input skeleton is "MMMdhmm", there is not an exact match, so the input skeleton is broken up into two components "MMMd" and "hmm". There are close matches for those two skeletons, so the result is put together with this pattern, resulting in "d-MMM h:mm".

Parameters:

  | dateTimeFormat | message format pattern, here {0} will be replaced by the date pattern and {1} will be replaced by the time pattern.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

const UnicodeString& DateTimePatternGenerator::getDateTimeFormat | ( |  | ) | const

Getter corresponding to setDateTimeFormat.

Returns:
  DateTimeFormat.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UnicodeString DateTimePatternGenerator::getBestPattern | ( | const UnicodeString & | skeleton,
|  | UErrorCode & | status |
| ) |  |  |

Return the best pattern matching the input skeleton.

It is guaranteed to have all of the fields in the skeleton.

Parameters:

  | skeleton | The skeleton is a pattern containing only the variable fields. For example, "MMMdd" and "mmhh" are skeletons.
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  bestPattern The best pattern found from the given skeleton.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

UnicodeString DateTimePatternGenerator::replaceFieldTypes | ( | const UnicodeString & | pattern,
|  | const UnicodeString & | skeleton,
|  | UErrorCode & | status |
| ) |  |  |

Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.

That is, if you supply a pattern like "d-M H:m", and a skeleton of "MMMMddhhmm", then the input pattern is adjusted to be "dd-MMMM hh:mm". This is used internally to get the best match for the input skeleton, but can also be used externally.

Parameters:

  | pattern | Input pattern
  | skeleton | The skeleton is a pattern containing only the variable fields. For example, "MMMdd" and "mmhh" are skeletons.
  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  pattern adjusted to match the skeleton fields widths and subtypes.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

StringEnumeration* DateTimePatternGenerator::getSkeletons | ( | UErrorCode & | status | ) | const

Return a list of all the skeletons (in canonical form) from this class.

Call getPatternForSkeleton() to get the corresponding pattern.

Parameters:

  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  StringEnumeration with the skeletons. The caller must delete the object.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

const UnicodeString& DateTimePatternGenerator::getPatternForSkeleton | ( | const UnicodeString & | skeleton | ) | const

Get the pattern corresponding to a given skeleton.

Parameters:

  | skeleton |

Returns:
  pattern corresponding to a given skeleton.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

StringEnumeration* DateTimePatternGenerator::getBaseSkeletons | ( | UErrorCode & | status | ) | const

Return a list of all the base skeletons (in canonical form) from this class.

Parameters:

  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  a StringEnumeration with the base skeletons. The caller must delete the object.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

StringEnumeration* DateTimePatternGenerator::getRedundants | ( | UErrorCode & | status | ) |

Return a list of redundant patterns are those which if removed, make no difference in the resulting getBestPattern values.

This method returns a list of them, to help check the consistency of the patterns used to build this generator.

Parameters:

  | status | Output param set to success/failure code on exit, which must not indicate a failure before the function call.

Returns:
  a StringEnumeration with the redundant pattern. The caller must delete the object.

Internal:
  Do not use. This API is for interal use only. ICU 3.8

void DateTimePatternGenerator::setDecimal | ( | const UnicodeString & | decimal | ) |

The decimal value is used in formatting fractions of seconds.

If the skeleton contains fractional seconds, then this is used with the fractional seconds. For example, suppose that the input pattern is "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and the decimal string is ",". Then the resulting pattern is modified to be "H:mm:ss,SSSS"

Parameters:

  | decimal |

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

const UnicodeString& DateTimePatternGenerator::getDecimal | ( |  | ) | const

Getter corresponding to setDecimal.

Returns:
  UnicodeString corresponding to the decimal point

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

virtual UClassID DateTimePatternGenerator::getDynamicClassID | ( |  | ) | const`[virtual]`

ICU "poor man's RTTI", returns a UClassID for the actual class.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

Implements UObject.

static UClassID DateTimePatternGenerator::getStaticClassID | ( | void |  | ) | `[static]`

ICU "poor man's RTTI", returns a UClassID for this class.

Draft:
  This API may be changed in the future versions and was introduced in ICU 3.8

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

- dtptngen.h