| java.lang.Object com.ibm.icu.text.DateTimePatternGenerator
DateTimePatternGenerator | public class DateTimePatternGenerator implements Freezable,Cloneable(Code) | | 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.
|
Inner Class :final public static class PatternInfo | |
Inner Class :public static class VariableField | |
Inner Class :public static class FormatParser | |
DAY | final public static int DAY(Code) | | |
DAYPERIOD | final public static int DAYPERIOD(Code) | | |
DAY_OF_WEEK_IN_MONTH | final public static int DAY_OF_WEEK_IN_MONTH(Code) | | |
DAY_OF_YEAR | final public static int DAY_OF_YEAR(Code) | | |
ERA | final public static int ERA(Code) | | |
FRACTIONAL_SECOND | final public static int FRACTIONAL_SECOND(Code) | | |
HOUR | final public static int HOUR(Code) | | |
MINUTE | final public static int MINUTE(Code) | | |
MONTH | final public static int MONTH(Code) | | |
QUARTER | final public static int QUARTER(Code) | | |
SECOND | final public static int SECOND(Code) | | |
TYPE_LIMIT | final public static int TYPE_LIMIT(Code) | | |
WEEKDAY | final public static int WEEKDAY(Code) | | |
WEEK_OF_MONTH | final public static int WEEK_OF_MONTH(Code) | | |
WEEK_OF_YEAR | final public static int WEEK_OF_YEAR(Code) | | |
YEAR | final public static int YEAR(Code) | | |
ZONE | final public static int ZONE(Code) | | |
DateTimePatternGenerator | protected DateTimePatternGenerator()(Code) | | Only for use by subclasses
|
add | public DateTimePatternGenerator add(String pattern, boolean override, PatternInfo returnInfo)(Code) | | 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 information is returned in PatternInfo.
Note that single-field patterns (like "MMM") are automatically added, and
don't need to be added explicitly!
Parameters: override - when existing values are to be overridden use true, otherwiseuse false. |
cloneAsThawed | public Object cloneAsThawed()(Code) | | Boilerplate for Freezable
|
freeze | public Object freeze()(Code) | | Boilerplate for Freezable
|
getAppendItemFormats | public String getAppendItemFormats(int field)(Code) | | Getter corresponding to setAppendItemFormats. Values below 0 or at or
above TYPE_LIMIT are illegal arguments.
Parameters: field - append pattern for field |
getAppendItemNames | public String getAppendItemNames(int field)(Code) | | Getter corresponding to setAppendItemNames. Values below 0 or at or above
TYPE_LIMIT are illegal arguments.
Parameters: field - name for field |
getBaseSkeleton | public String getBaseSkeleton(String pattern)(Code) | | 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" skeleton, such as "MMMdd" |
getBaseSkeletons | public Set getBaseSkeletons(Set result)(Code) | | Return a list of all the base skeletons (in canonical form) from this class
|
getBestPattern | public String getBestPattern(String skeleton)(Code) | | 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. |
getDateTimeFormat | public String getDateTimeFormat()(Code) | | Getter corresponding to setDateTimeFormat.
pattern |
getDecimal | public String getDecimal()(Code) | | Getter corresponding to setDecimal.
string corresponding to the decimal point |
getFields | public String getFields(String pattern)(Code) | | internal routine
Parameters: pattern - field value |
getRedundants | public Collection getRedundants(Collection output)(Code) | | 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 thesein internal order, supply a LinkedHashSet. If null, acollection is allocated. the collection with added elements. |
getSkeleton | public String getSkeleton(String pattern)(Code) | | 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" skeleton, such as "MMMdd" |
getSkeletons | public Map getSkeletons(Map result)(Code) | | 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 topattern. If you want to see the internal order being used,supply a LinkedHashMap. If the input value is null, then aLinkedHashMap is allocated.Issue: an alternate API would be to just return a list ofthe skeletons, and then have a separate routine to get fromskeleton to pattern. the input Map containing the values. |
isFrozen | public boolean isFrozen()(Code) | | Boilerplate for Freezable
|
isSingleField | public static boolean isSingleField(String skeleton)(Code) | | Determines whether a skeleton contains a single field
Parameters: skeleton - true or not |
replaceFieldTypes | public String replaceFieldTypes(String pattern, String skeleton)(Code) | | 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 Parameters: skeleton - pattern adjusted to match the skeleton fields widths andsubtypes. |
setAppendItemFormats | public void setAppendItemFormats(int field, String value)(Code) | | 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 ERA Parameters: value - pattern, such as "{0}, {1}" |
setAppendItemNames | public void setAppendItemNames(int field, String value)(Code) | | 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 - Parameters: value - |
setDateTimeFormat | public void setDateTimeFormat(String dateTimeFormat)(Code) | | 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 datepattern and {1} will be replaced by the time pattern. |
setDecimal | public void setDecimal(String decimal)(Code) | | 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 - |
|
|