Class DateTimePatternGenerator
- All Implemented Interfaces:
Freezable<DateTimePatternGenerator>, Cloneable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate classprivate classprivate static classprivate static classstatic enumField display name width constants for getFieldDisplayNameprivate static classprivate static enumstatic classDeprecated.This API is ICU internal only.static final classPatternInfo supplies output parameters for addPattern(...).private static classprivate static classprivate static classA compact storage mechanism for skeleton field strings.static classDeprecated.This API is ICU internal only. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]private static final DateTimePatternGenerator.DisplayWidthThe field name width for use in appendItemsprivate static final intprivate String[]private static final String[]private static final String[]private static final String[]private static final DateTimePatternGenerator.DisplayWidth[]private static final intprivate String[]static final intstatic final intstatic final intstatic final intprivate static final booleanprivate Stringprivate charprivate static final intprivate static ICUCache<String, DateTimePatternGenerator> static final intprivate static final intprivate static final String[]private String[][]private static final intstatic final intprivate booleanstatic final intprivate static final String[]private static final intstatic final intOption mask for forcing the width of all date and time fields.static final intOption mask for forcing the width of hour field.static final intDeprecated.This API is ICU internal only.static final intDefault option mask used forgetBestPattern(String, int)andreplaceFieldTypes(String, String, int).static final intDeprecated.This API is ICU internal only.static final intprivate static final intstatic final intprivate static final intprivate static final intprivate static final intstatic final intstatic final intprivate static final intprivate static final intprivate static final intprivate TreeMap<DateTimePatternGenerator.DateTimeMatcher, DateTimePatternGenerator.PatternWithSkeletonFlag> private static final intstatic final intDeprecated.ICU 58 The numeric value may change over time, see ICU ticket #12420.private static final int[][]static final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidaddCLDRData(DateTimePatternGenerator.PatternInfo returnInfo, ULocale uLocale) private voidaddICUPatterns(DateTimePatternGenerator.PatternInfo returnInfo, ULocale uLocale) addPattern(String pattern, boolean override, DateTimePatternGenerator.PatternInfo returnInfo) Adds a pattern to the generator.addPatternWithSkeleton(String pattern, String skeletonToUse, boolean override, DateTimePatternGenerator.PatternInfo returnInfo) Deprecated.This API is ICU internal only.private StringadjustFieldTypes(DateTimePatternGenerator.PatternWithMatcher patternWithMatcher, DateTimePatternGenerator.DateTimeMatcher inputRequest, EnumSet<DateTimePatternGenerator.DTPGflags> flags, int options) private voidclone()Returns a copy of thisDateTimePatternGeneratorobject.Provides for the clone operation.private voidconsumeShortTimePattern(String shortTimePattern, DateTimePatternGenerator.PatternInfo returnInfo) private voidfreeze()Freezes the object.private voidgetAllowedHourFormats(ULocale uLocale) private String[]getAllowedHourFormatsLangCountry(String language, String country) private StringgetAppendFormat(int foundMask) static intDeprecated.This API is ICU internal only.static intgetAppendFormatNumber(String string) Deprecated.This API is ICU internal only.getAppendItemFormat(int field) Getter corresponding to setAppendItemFormats.getAppendItemName(int field) Getter corresponding to setAppendItemName.private StringgetAppendName(int foundMask) getBaseSkeleton(String pattern) Utility to return a unique base skeleton from a given pattern.getBaseSkeletons(Set<String> result) Return a list of all the base skeletons (in canonical form) from this classprivate StringgetBestAppending(DateTimePatternGenerator.DateTimeMatcher source, int missingFields, DateTimePatternGenerator.DistanceInfo distInfo, DateTimePatternGenerator.DateTimeMatcher skipMatcher, EnumSet<DateTimePatternGenerator.DTPGflags> flags, int options) We only get called here if we failed to find an exact skeleton.getBestPattern(String skeleton) Return the best pattern matching the input skeleton.getBestPattern(String skeleton, int options) Return the best pattern matching the input skeleton.private StringgetBestPattern(String skeleton, DateTimePatternGenerator.DateTimeMatcher skipMatcher, int options) getBestRaw(DateTimePatternGenerator.DateTimeMatcher source, int includeMask, DateTimePatternGenerator.DistanceInfo missingFields, DateTimePatternGenerator.DateTimeMatcher skipMatcher) private StringgetCalendarTypeToUse(ULocale uLocale) private static chargetCanonicalChar(int field, char reference) Gets the canonical character associated with the specified field (ERA, YEAR, etc).private static intgetCanonicalIndex(String s, boolean strict) Get the canonical index, or return -1 if illegal.Deprecated.This API is ICU internal only.private static intGetter corresponding to setDateTimeFormat.getDateTimeFormat(int style) Getter corresponding to setDateTimeFormat.Getter corresponding to setDecimal.Return the default hour cycle.charDeprecated.This API is ICU internal only.static DateTimePatternGeneratorCreate empty generator, to be constructed with addPattern(...) etc.getFieldDisplayName(int field, DateTimePatternGenerator.DisplayWidth width) The general interface to get a display name for a particular date/time field, in one of several possible display widths.Deprecated.This API is ICU internal only.private static Stringstatic DateTimePatternGeneratorgetFrozenInstance(ULocale uLocale) Deprecated.This API is ICU internal only.static DateTimePatternGeneratorConstruct a flexible generator according to data for the defaultFORMATlocale.static DateTimePatternGeneratorgetInstance(ULocale uLocale) Construct a flexible generator according to data for a given locale.static DateTimePatternGeneratorgetInstance(Locale locale) Construct a flexible generator according to data for a given locale.static DateTimePatternGeneratorgetInstanceNoStdPat(ULocale uLocale) Deprecated.This API is ICU internal only.private static StringgetRedundants(Collection<String> output) Deprecated.This API is ICU internal only.getSkeleton(String pattern) Utility to return a unique skeleton from a given pattern.getSkeletonAllowingDuplicates(String pattern) Deprecated.This API is ICU internal only.getSkeletons(Map<String, String> result) Return a list of all the skeletons (in canonical form) from this class, and the patterns that they map to.private intgetTopBitNumber(int foundMask) private voidhackTimes(DateTimePatternGenerator.PatternInfo returnInfo, String shortTimePattern) private voidprivate booleanThis function checks the corresponding slot of CLDR_AVAIL_FORMAT_KEY[] has been added to DateTimePatternGenerator.booleanisFrozen()Determines whether the object has been frozen or not.static booleanisSingleField(String skeleton) Deprecated.This API is ICU internal only.private StringmapSkeletonMetacharacters(String skeleton, EnumSet<DateTimePatternGenerator.DTPGflags> flags) replaceFieldTypes(String pattern, String skeleton) Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.replaceFieldTypes(String pattern, String skeleton, int options) Adjusts the field types (width and subtype) of a pattern to match what is in a skeleton.voidsetAppendItemFormat(int field, String value) An AppendItem format is a pattern used to append a field if there is no good match.voidsetAppendItemName(int field, String value) Sets the names of fields, eg "era" in English for ERA.private voidsetAvailableFormat(String key) Add key to HashSet cldrAvailableFormatKeys.voidsetDateTimeFormat(int style, String dateTimeFormat) dateTimeFormats are message patterns used to compose combinations of date and time patterns.voidsetDateTimeFormat(String dateTimeFormat) The date time format is a message format pattern used to compose date and time patterns.private voidsetDateTimeFromCalendar(ULocale uLocale) voidsetDecimal(String decimal) The decimal value is used in formatting fractions of seconds.private voidsetDecimalSymbols(ULocale uLocale) voidsetDefaultHourFormatChar(char defaultHourFormatChar) Deprecated.This API is ICU internal only.private voidsetFieldDisplayName(int field, DateTimePatternGenerator.DisplayWidth width, String value) Deprecated.This API is ICU internal only.private static StringshowMask(int mask) booleanskeletonsAreSimilar(String id, String skeleton) Deprecated.This API is ICU internal only.
-
Field Details
-
DEBUG
private static final boolean DEBUG- See Also:
-
LAST_RESORT_ALLOWED_HOUR_FORMAT
-
LOCALE_TO_ALLOWED_HOUR
-
ERA
public static final int ERA- See Also:
-
YEAR
public static final int YEAR- See Also:
-
QUARTER
public static final int QUARTER- See Also:
-
MONTH
public static final int MONTH- See Also:
-
WEEK_OF_YEAR
public static final int WEEK_OF_YEAR- See Also:
-
WEEK_OF_MONTH
public static final int WEEK_OF_MONTH- See Also:
-
WEEKDAY
public static final int WEEKDAY- See Also:
-
DAY
public static final int DAY- See Also:
-
DAY_OF_YEAR
public static final int DAY_OF_YEAR- See Also:
-
DAY_OF_WEEK_IN_MONTH
public static final int DAY_OF_WEEK_IN_MONTH- See Also:
-
DAYPERIOD
public static final int DAYPERIOD- See Also:
-
HOUR
public static final int HOUR- See Also:
-
MINUTE
public static final int MINUTE- See Also:
-
SECOND
public static final int SECOND- See Also:
-
FRACTIONAL_SECOND
public static final int FRACTIONAL_SECOND- See Also:
-
ZONE
public static final int ZONE- See Also:
-
TYPE_LIMIT
Deprecated.ICU 58 The numeric value may change over time, see ICU ticket #12420.One more than the highest normal field number.- See Also:
-
APPENDITEM_WIDTH
The field name width for use in appendItems -
APPENDITEM_WIDTH_INT
private static final int APPENDITEM_WIDTH_INT -
CLDR_FIELD_WIDTH
-
MATCH_NO_OPTIONS
public static final int MATCH_NO_OPTIONSDefault option mask used forgetBestPattern(String, int)andreplaceFieldTypes(String, String, int).- See Also:
-
MATCH_HOUR_FIELD_LENGTH
public static final int MATCH_HOUR_FIELD_LENGTHOption mask for forcing the width of hour field.- See Also:
-
MATCH_MINUTE_FIELD_LENGTH
Deprecated.This API is ICU internal only.Option mask for forcing the width of minute field.- See Also:
-
MATCH_SECOND_FIELD_LENGTH
Deprecated.This API is ICU internal only.Option mask for forcing the width of second field.- See Also:
-
MATCH_ALL_FIELDS_LENGTH
public static final int MATCH_ALL_FIELDS_LENGTHOption mask for forcing the width of all date and time fields.- See Also:
-
skeleton2pattern
private TreeMap<DateTimePatternGenerator.DateTimeMatcher, DateTimePatternGenerator.PatternWithSkeletonFlag> skeleton2pattern -
basePattern_pattern
-
decimal
-
dateTimeFormats
-
appendItemFormats
-
fieldDisplayNames
-
defaultHourFormatChar
private char defaultHourFormatChar -
frozen
private volatile boolean frozen -
current
-
fp
-
_distanceInfo
-
allowedHourFormats
-
FRACTIONAL_MASK
private static final int FRACTIONAL_MASK- See Also:
-
SECOND_AND_FRACTIONAL_MASK
private static final int SECOND_AND_FRACTIONAL_MASK- See Also:
-
DTPNG_CACHE
-
CLDR_FIELD_APPEND
-
CLDR_FIELD_NAME
-
FIELD_NAME
-
CANONICAL_ITEMS
-
CANONICAL_SET
-
cldrAvailableFormatKeys
-
DATE_MASK
private static final int DATE_MASK- See Also:
-
TIME_MASK
private static final int TIME_MASK- See Also:
-
DELTA
private static final int DELTA- See Also:
-
NUMERIC
private static final int NUMERIC- See Also:
-
NONE
private static final int NONE- See Also:
-
NARROW
private static final int NARROW- See Also:
-
SHORTER
private static final int SHORTER- See Also:
-
SHORT
private static final int SHORT- See Also:
-
LONG
private static final int LONG- See Also:
-
EXTRA_FIELD
private static final int EXTRA_FIELD- See Also:
-
MISSING_FIELD
private static final int MISSING_FIELD- See Also:
-
types
private static final int[][] types
-
-
Constructor Details
-
DateTimePatternGenerator
protected DateTimePatternGenerator()Only for use by subclasses
-
-
Method Details
-
getEmptyInstance
Create empty generator, to be constructed with addPattern(...) etc. -
getInstance
Construct a flexible generator according to data for the defaultFORMATlocale.- See Also:
-
getInstance
Construct a flexible generator according to data for a given locale.- Parameters:
uLocale- The locale to pass.
-
getInstance
Construct a flexible generator according to data for a given locale.- Parameters:
locale- TheLocaleto pass.
-
getFrozenInstance
Deprecated.This API is ICU internal only.Construct a frozen instance of DateTimePatternGenerator for a given locale. This method returns a cached frozen instance of DateTimePatternGenerator, so less expensive than the regular factory method.- Parameters:
uLocale- The locale to pass.- Returns:
- A frozen DateTimePatternGenerator.
-
getInstanceNoStdPat
Deprecated.This API is ICU internal only.Construct a non-frozen instance of DateTimePatternGenerator for a given locale that skips using the standard date and time patterns. Because this is different than the normal instance for the locale, it does not set or use the cache.- Parameters:
uLocale- The locale to pass.
-
initData
-
addICUPatterns
-
getCalendarTypeToUse
-
consumeShortTimePattern
private void consumeShortTimePattern(String shortTimePattern, DateTimePatternGenerator.PatternInfo returnInfo) -
fillInMissing
private void fillInMissing() -
addCLDRData
-
setDateTimeFromCalendar
-
setDecimalSymbols
-
getAllowedHourFormatsLangCountry
-
getAllowedHourFormats
-
getDefaultHourFormatChar
Deprecated.This API is ICU internal only. -
setDefaultHourFormatChar
Deprecated.This API is ICU internal only. -
hackTimes
-
getFilteredPattern
-
getAppendFormatNumber
Deprecated.This API is ICU internal only. -
getAppendFormatNumber
Deprecated.This API is ICU internal only. -
getCLDRFieldAndWidthNumber
-
getBestPattern
Return the best pattern matching the input skeleton. It is guaranteed to have all of the fields in the skeleton.Example code:
import java.util.Date; import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.DateTimePatternGenerator; import com.ibm.icu.text.SimpleDateFormat; import com.ibm.icu.util.GregorianCalendar; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; ... final String[] skeletons = { "yQQQQ", // year + full name of quarter, i.e., 4th quarter 1999 "yMMMM", // year + full name of month, i.e., October 1999 "MMMMd", // full name of month + day of the month, i.e., October 25 "hhmm", // 12-hour-cycle format, i.e., 1:32 PM "jjmm" // preferred hour format for the given locale, i.e., 24-hour-cycle format for fr_FR }; final ULocale[] locales = { new ULocale ("en_US"), new ULocale ("fr_FR"), new ULocale ("zh_CN"), }; DateTimePatternGenerator dtfg = null; Date date= new GregorianCalendar(1999,9,13,23,58,59).getTime(); System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR","zh_CN"); for (String skeleton:skeletons) { System.out.printf("%-20s", skeleton); for (ULocale locale:locales) { // create a DateTimePatternGenerator instance for given locale dtfg = DateTimePatternGenerator.getInstance(locale); // use getBestPattern method to get the best pattern for the given skeleton String pattern = dtfg.getBestPattern(skeleton); // Constructs a SimpleDateFormat with the best pattern generated above and the given locale SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); // Get the format of the given date System.out.printf("%-35s",sdf.format(date)); } System.out.println("\n"); } /** output of the sample code: ************************************************************************************************************* Skeleton en_US fr_FR zh_CN yQQQQ 4th quarter 1999 4e trimestre 1999 1999年第四季度 yMMMM October 1999 octobre 1999 1999年10月 MMMMd October 13 13 octobre 10月13日 hhmm 11:58 PM 11:58 PM 下午11:58 jjmm 11:58 PM 23:58 下午11:58 **************************************************************************************************************/// Use DateTime.getPatternInstance to produce the same Date/Time format with predefined constant field value final String[] dtfskeleton = { DateFormat.YEAR_QUARTER, // year + full name of quarter, i.e., 4th quarter 1999 DateFormat.YEAR_MONTH, // year + full name of month, i.e., October 1999 DateFormat.MONTH_DAY // full name of month + day of the month, i.e., October 25 }; System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR","zh_CN"); for (String skeleton:dtfskeleton) { System.out.printf("%-20s", skeleton); for (ULocale locale:locales) { // Use DateFormat.getPatternInstance to get the date/time format for the locale, // and apply the format to the given date String df=DateFormat.getPatternInstance(skeleton,locale).format(date); System.out.printf("%-35s",df); } System.out.println("\n"); } /** output of the sample code: ************************************************************************************************************ Skeleton en_US fr_FR zh_CN yQQQQ 4th quarter 1999 4e trimestre 1999 1999年第四季度 yMMMM October 1999 octobre 1999 1999年10月 MMMMd October 13 13 octobre 10月13日 ************************************************************************************************************/- Parameters:
skeleton- The skeleton is a pattern containing only the variable fields. For example, "MMMdd" and "mmhh" are skeletons.- Returns:
- Best pattern matching the input skeleton.
-
getBestPattern
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.options- MATCH_xxx options for forcing the length of specified fields in the returned pattern to match those in the skeleton (when this would not happen otherwise). For default behavior, use MATCH_NO_OPTIONS.- Returns:
- Best pattern matching the input skeleton (and options).
-
getBestPattern
private String getBestPattern(String skeleton, DateTimePatternGenerator.DateTimeMatcher skipMatcher, int options) -
mapSkeletonMetacharacters
private String mapSkeletonMetacharacters(String skeleton, EnumSet<DateTimePatternGenerator.DTPGflags> flags) -
addPattern
public DateTimePatternGenerator addPattern(String pattern, boolean override, DateTimePatternGenerator.PatternInfo returnInfo) 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 overridden. Otherwise, the previous value is retained. In either case, the conflicting information is returned in PatternInfo.Note that single-field patterns (like "MMM") are automatically added, and don't need to be added explicitly!
Example code:
Date date= new GregorianCalendar(1999,9,13,23,58,59).getTime(); ULocale locale = ULocale.FRANCE; // Create an DateTimePatternGenerator instance for the given locale DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale); SimpleDateFormat format = new SimpleDateFormat(gen.getBestPattern("MMMMddHmm"), locale); DateTimePatternGenerator.PatternInfo returnInfo = new DateTimePatternGenerator.PatternInfo(); // Add '. von' to the existing pattern gen.addPattern("dd'. von' MMMM", true, returnInfo); // Apply the new pattern format.applyPattern(gen.getBestPattern("MMMMddHmm")); System.out.println("New Pattern for FRENCH: "+format.toPattern()); System.out.println("Date Time in new Pattern: "+format.format(date)); /** output of the sample code: ************************************************************************************************** New Pattern for FRENCH: dd. 'von' MMMM HH:mm Date Time in new Pattern: 13. von octobre 23:58 *************************************************************************************************/- Parameters:
pattern- Pattern to add.override- When existing values are to be overridden use true, otherwise use false.returnInfo- Returned information.
-
addPatternWithSkeleton
@Deprecated public DateTimePatternGenerator addPatternWithSkeleton(String pattern, String skeletonToUse, boolean override, DateTimePatternGenerator.PatternInfo returnInfo) Deprecated.This API is ICU internal only.addPatternWithSkeleton: If skeletonToUse is specified, then an availableFormats entry is being added. In this case: 1. We pass that skeleton to DateTimeMatcher().set instead of having it derive a skeleton from the pattern. 2. If the new entry's skeleton or basePattern does match an existing entry but that entry also had a skeleton specified (i.e. it was also from availableFormats), then the new entry does not override it regardless of the value of the override parameter. This prevents later availableFormats entries from a parent locale overriding earlier ones from the actual specified locale. However, availableFormats entries *should* override entries with matching skeleton whose skeleton was derived (i.e. entries derived from the standard date/time patters for the specified locale). 3. When adding the pattern (skeleton2pattern.put, basePattern_pattern.put), we set a field to indicate that the added entry had a specified skeleton. -
getSkeleton
-
getSkeletonAllowingDuplicates
Deprecated.This API is ICU internal only.Same as getSkeleton, but allows duplicates- Parameters:
pattern- Input pattern, such as "dd/MMM"- Returns:
- skeleton, such as "MMMdd"
-
getCanonicalSkeletonAllowingDuplicates
Deprecated.This API is ICU internal only.Same as getSkeleton, but allows duplicates and returns a string using canonical pattern chars- Parameters:
pattern- Input pattern, such as "ccc, d LLL"- Returns:
- skeleton, such as "MMMEd"
-
getBaseSkeleton
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"- Returns:
- skeleton, such as "MMMdd"
-
getSkeletons
Return a list of all the skeletons (in canonical form) from this class, and the patterns that they map to.- Parameters:
result- an output Map in which to place the mapping from skeleton to pattern. If you want to see the internal order being used, supply a LinkedHashMap. If the input value is null, then a LinkedHashMap is allocated.Issue: an alternate API would be to just return a list of the skeletons, and then have a separate routine to get from skeleton to pattern.
- Returns:
- the input Map containing the values.
-
getBaseSkeletons
-
replaceFieldTypes
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.Example code:
Date date= new GregorianCalendar(1999,9,13,23,58,59).getTime(); TimeZone zone = TimeZone.getTimeZone("Europe/Paris"); ULocale locale = ULocale.FRANCE; DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale); SimpleDateFormat format = new SimpleDateFormat("EEEE d MMMM y HH:mm:ss zzzz",locale); format.setTimeZone(zone); String pattern = format.toPattern(); System.out.println("Pattern before replacement:"); System.out.println(pattern); System.out.println("Date/Time format in fr_FR:"); System.out.println(format.format(date)); // Replace zone "zzzz" in the pattern with "vvvv" String newPattern = gen.replaceFieldTypes(pattern, "vvvv"); // Apply the new pattern format.applyPattern(newPattern); System.out.println("Pattern after replacement:"); System.out.println(newPattern); System.out.println("Date/Time format in fr_FR:"); System.out.println(format.format(date)); /** output of the sample code: *************************************************************************************************** Pattern before replacement: EEEE d MMMM y HH:mm:ss zzzz Date/Time format in fr_FR: jeudi 14 octobre 1999 05:58:59 heure avancée d’Europe centrale Pattern after replacement: EEEE d MMMM y HH:mm:ss vvvv Date/Time format in fr_FR: jeudi 14 octobre 1999 05:58:59 heure de l’Europe centrale **************************************************************************************************/- Parameters:
pattern- input patternskeleton- For the pattern to match to.- Returns:
- pattern adjusted to match the skeleton fields widths and subtypes.
-
replaceFieldTypes
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 patternskeleton- For the pattern to match to.options- MATCH_xxx options for forcing the length of specified fields in the returned pattern to match those in the skeleton (when this would not happen otherwise). For default behavior, use MATCH_NO_OPTIONS.- Returns:
- pattern adjusted to match the skeleton fields widths and subtypes.
-
setDateTimeFormat
The date time format is a message format pattern used to compose date and time patterns. The default value is "{1} {0}", where {1} will be replaced by the date pattern and {0} 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 "{1} {0}". 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". There are four DateTimeFormats in a DateTimePatternGenerator object, corresponding to date styles DateFormat.FULL..DateFormat.SHORT. This method sets all of them to the specified pattern. To set them individually, see setDateTimeFormat(int style, ...).
- Parameters:
dateTimeFormat- message format pattern, where {1} will be replaced by the date pattern and {0} will be replaced by the time pattern.
-
getDateTimeFormat
Getter corresponding to setDateTimeFormat. There are four DateTimeFormats in a DateTimePatternGenerator object, corresponding to date styles DateFormat.FULL..DateFormat.SHORT. This method gets the style for DateFormat.MEDIUM (the default). To get them individually, see getDateTimeFormat(int style).- Returns:
- pattern
-
setDateTimeFormat
dateTimeFormats are message patterns used to compose combinations of date and time patterns. There are four length styles, corresponding to the inferred style of the date pattern: - DateFormat.FULL (for date pattern with weekday and long month), else - DateFormat.LONG (for a date pattern with long month), else - DateFormat.MEDIUM (for a date pattern with abbreviated month), else - DateFormat.SHORT (for any other date pattern). For details on dateTimeFormats, see https://www.unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats. The default pattern in the root locale for all styles is "{1} {0}".- Parameters:
style- one of DateFormat.FULL..DateFormat.SHORT. An exception will be thrown if out of range.dateTimeFormat- the new dateTimeFormat to set for the specified style
-
getDateTimeFormat
Getter corresponding to setDateTimeFormat.- Parameters:
style- one of DateFormat.FULL..DateFormat.SHORT. An exception will be thrown if out of range.- Returns:
- the current dateTimeFormat for the specified style.
-
setDecimal
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- The decimal to set to.
-
getDecimal
Getter corresponding to setDecimal.- Returns:
- string corresponding to the decimal point
-
getRedundants
Deprecated.This API is ICU internal only.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:
output- stores the redundant patterns that are removed. To get these in internal order, supply a LinkedHashSet. If null, a collection is allocated.- Returns:
- the collection with added elements.
-
setAppendItemFormat
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 ERAvalue- pattern, such as "{0}, {1}"
-
getAppendItemFormat
Getter corresponding to setAppendItemFormats. Values below 0 or at or above TYPE_LIMIT are illegal arguments.- Parameters:
field- The index to retrieve the append item formats.- Returns:
- append pattern for field
-
setAppendItemName
Sets the names of fields, 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- Index of the append item names.value- The value to set the item to.
-
getAppendItemName
Getter corresponding to setAppendItemName. Values below 0 or at or above TYPE_LIMIT are illegal arguments. Note: The more general method for getting date/time field display names is getFieldDisplayName.- Parameters:
field- The index to get the append item name.- Returns:
- name for field
- See Also:
-
getDefaultHourCycle
Return the default hour cycle. -
setFieldDisplayName
@Deprecated private void setFieldDisplayName(int field, DateTimePatternGenerator.DisplayWidth width, String value) Deprecated.This API is ICU internal only.The private interface to set a display name for a particular date/time field, in one of several possible display widths.- Parameters:
field- The field type, such as ERA.width- The desired DisplayWidth, such as DisplayWidth.ABBREVIATED.value- The display name to set
-
getFieldDisplayName
The general interface to get a display name for a particular date/time field, in one of several possible display widths.- Parameters:
field- The field type, such as ERA.width- The desired DisplayWidth, such as DisplayWidth.ABBREVIATED.- Returns:
- The display name for the field
-
isSingleField
Deprecated.This API is ICU internal only.Determines whether a skeleton contains a single field- Parameters:
skeleton- The skeleton to determine if it contains a single field.- Returns:
- true or not
-
setAvailableFormat
Add key to HashSet cldrAvailableFormatKeys.- Parameters:
key- of the availableFormats in CLDR
-
isAvailableFormatSet
This function checks the corresponding slot of CLDR_AVAIL_FORMAT_KEY[] has been added to DateTimePatternGenerator. The function is to avoid the duplicate availableFomats added to the pattern map from parent locales.- Parameters:
key- of the availableFormatMask in CLDR- Returns:
- true if the corresponding slot of CLDR_AVAIL_FORMAT_KEY[] has been added to DateTimePatternGenerator.
-
isFrozen
public boolean isFrozen()Determines whether the object has been frozen or not.- Specified by:
isFrozenin interfaceFreezable<DateTimePatternGenerator>
-
freeze
Freezes the object.- Specified by:
freezein interfaceFreezable<DateTimePatternGenerator>- Returns:
- the object itself.
-
cloneAsThawed
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawedin interfaceFreezable<DateTimePatternGenerator>
-
clone
Returns a copy of thisDateTimePatternGeneratorobject. -
skeletonsAreSimilar
Deprecated.This API is ICU internal only.Used by CLDR tooling; not in ICU4C. Note, this will not work correctly with normal skeletons, since fields that should be related in the two skeletons being compared - like EEE and ccc, or y and U - will not be sorted in the same relative place as each other when iterating over both TreeSets being compare, using TreeSet's "natural" code point ordering (this could be addressed by initializing the TreeSet with a comparator that compares fields first by their index from getCanonicalIndex()). However if comparing canonical skeletons from getCanonicalSkeletonAllowingDuplicates it will be OK regardless, since in these skeletons all fields are normalized to the canonical pattern char for those fields - M or L to M, E or c to E, y or U to y, etc. - so corresponding fields will sort in the same way for both TreeMaps. -
getSet
-
checkFrozen
private void checkFrozen() -
getBestAppending
private String getBestAppending(DateTimePatternGenerator.DateTimeMatcher source, int missingFields, DateTimePatternGenerator.DistanceInfo distInfo, DateTimePatternGenerator.DateTimeMatcher skipMatcher, EnumSet<DateTimePatternGenerator.DTPGflags> flags, int options) We only get called here if we failed to find an exact skeleton. We have broken it into date + time, and look for the pieces. If we fail to find a complete skeleton, we compose in a loop until we have all the fields. -
getAppendName
-
getAppendFormat
-
getTopBitNumber
private int getTopBitNumber(int foundMask) - Parameters:
foundMask-
-
addCanonicalItems
private void addCanonicalItems() -
getBestRaw
private DateTimePatternGenerator.PatternWithMatcher getBestRaw(DateTimePatternGenerator.DateTimeMatcher source, int includeMask, DateTimePatternGenerator.DistanceInfo missingFields, DateTimePatternGenerator.DateTimeMatcher skipMatcher) -
adjustFieldTypes
private String adjustFieldTypes(DateTimePatternGenerator.PatternWithMatcher patternWithMatcher, DateTimePatternGenerator.DateTimeMatcher inputRequest, EnumSet<DateTimePatternGenerator.DTPGflags> flags, int options) -
getFields
Deprecated.This API is ICU internal only.internal routine- Parameters:
pattern- The pattern that is passed.- Returns:
- field value
-
showMask
-
getName
-
getCanonicalIndex
Get the canonical index, or return -1 if illegal.- Parameters:
s-strict- TODO
-
getCanonicalChar
private static char getCanonicalChar(int field, char reference) Gets the canonical character associated with the specified field (ERA, YEAR, etc).
-