For most users, ordinary use of DateIntervalFormat does not need to create DateIntervalInfo object directly. DateIntervalFormat will take care of it when creating a date interval formatter when user pass in skeleton and locale.
For power users, who want to create their own date interval patterns, or want to re-set date interval patterns, they could do so by directly creating DateIntervalInfo and manipulating it.
Logically, the interval patterns are mappings from (skeleton, the_largest_different_calendar_field) to (date_interval_pattern).
A skeleton
The calendar fields we support for interval formatting are: year, month, date, day-of-week, am-pm, hour, hour-of-day, minute, and second (though we do not currently have specific intervalFormat data for skeletons with seconds). Those calendar fields can be defined in the following order: year > month > date > am-pm > hour > minute > second The largest different calendar fields between 2 calendars is the first different calendar field in above order. For example: the largest different calendar fields between "Jan 10, 2007" and "Feb 20, 2008" is year.
There is a set of pre-defined static skeleton strings. There are pre-defined interval patterns for those pre-defined skeletons in locales' resource files. For example, for a skeleton YEAR_ABBR_MONTH_DAY, which is "yMMMd", in en_US, if the largest different calendar field between date1 and date2 is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy", such as "Jan 10, 2007 - Jan 10, 2008". If the largest different calendar field between date1 and date2 is "month", the date interval pattern is "MMM d - MMM d, yyyy", such as "Jan 10 - Feb 10, 2007". If the largest different calendar field between date1 and date2 is "day", the date interval pattern is ""MMM d-d, yyyy", such as "Jan 10-20, 2007". For date skeleton, the interval patterns when year, or month, or date is different are defined in resource files. For time skeleton, the interval patterns when am/pm, or hour, or minute is different are defined in resource files.
There are 2 dates in interval pattern. For most locales, the first date in an interval pattern is the earlier date. There might be a locale in which the first date in an interval pattern is the later date. We use fallback format for the default order for the locale. For example, if the fallback format is "{0} - {1}", it means the first date in the interval pattern for this locale is earlier date. If the fallback format is "{1} - {0}", it means the first date is the later date. For a particular interval pattern, the default order can be overridden by prefixing "latestFirst:" or "earliestFirst:" to the interval pattern. For example, if the fallback format is "{0}-{1}", but for skeleton "yMMMd", the interval pattern when day is different is "latestFirst:d-d MMM yy", it means by default, the first date in interval pattern is the earlier date. But for skeleton "yMMMd", when day is different, the first date in "d-d MMM yy" is the later date.
The recommended way to create a DateIntervalFormat object is to pass in the locale. By using a Locale parameter, the DateIntervalFormat object is initialized with the pre-defined interval patterns for a given or default locale.
Users can also create DateIntervalFormat object by supplying their own interval patterns. It provides flexibility for power usage.
After a DateIntervalInfo object is created, clients may modify the interval patterns using setIntervalPattern function as so desired. Currently, users can only set interval patterns when the following calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH, DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND. Interval patterns when other calendar fields are different is not supported.
DateIntervalInfo objects are cloneable. When clients obtain a DateIntervalInfo object, they can feel free to modify it as necessary.
DateIntervalInfo are not expected to be subclassed. Data for a calendar is loaded out of resource bundles. Through ICU 4.4, date interval patterns are only supported in the Gregorian calendar; non-Gregorian calendars are supported from ICU 4.4.1.
| Modifier and Type | Class and Description |
|---|---|
| private static class | DateIntervalInfo.DateIntervalSink
Sink for enumerating all of the date interval skeletons. |
| public static class | DateIntervalInfo.PatternInfo
PatternInfo class saves the first and second part of interval pattern, and whether the interval pattern is earlier date first. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final String[] | |
| private static String | |
| pack-priv static final int | |
| private static final ICUCache | |
| private static String | |
| private static String | |
| private String | |
| private boolean | |
| private Map | |
| private transient boolean | |
| private transient volatile boolean | |
| private static String | |
| private static String | |
| private static final int | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| public | DateIntervalInfo(ULocale
the interval patterns are loaded from the appropriate
calendar data (specified calendar or default calendar)
in this locale. locale)Construct DateIntervalInfo for the given locale, |
| public | DateIntervalInfo(Locale
the interval patterns are loaded from the appropriate
calendar data (specified calendar or default calendar)
in this locale. locale)Construct DateIntervalInfo for the given |
| Modifier and Type | Method and Description |
|---|---|
| public Object | |
| public DateIntervalInfo | cloneAsThawed()
Implements com. |
| private static Map | |
| private Object | |
| public boolean | equals(Object
the reference object with which to compare. a)Overrides java. |
| public DateIntervalInfo | |
| public static DateIntervalInfo. | Returns: pattern info objectinterval pattern intervalPattern, boolean whether the first date in intervalPattern
is earlier date or later date laterDateFirst)
Deprecated
This API is ICU internal only.
Break interval patterns as 2 part and save them into pattern info.
|
| pack-priv DateIntervalFormat. | |
| public boolean | |
| public String | |
| public DateIntervalInfo. | Returns: interval pattern return null if interval pattern is not found.the skeleton skeleton, int the largest different calendar field field)Get the interval pattern given the largest different calendar field. |
| public Map | |
| public Map | getRawPatterns()
Deprecated
This API is ICU internal only.
Get the internal patterns, with a deep clone for safety.
|
| public int | |
| private void | |
| private void | initializeFromReadOnlyPatterns(DateIntervalInfo
must have read-only fIntervalPatterns. dii)Initialize this object |
| public boolean | isFrozen()
Implements com. |
| pack-priv static void | parseSkeleton(String
skeleton to be parsed skeleton, int[] parsed skeleton field width skeletonFieldWidth)Parse skeleton, save each field's width. |
| public void | setFallbackIntervalPattern(String
fall-back interval pattern. fallbackPattern)Re-set the fallback interval pattern. |
| public void | setIntervalPattern(String
the skeleton on which interval pattern based skeleton, int the largest different calendar unit. lrgDiffCalUnit, String the interval pattern on the largest different
calendar unit.
For example, if lrgDiffCalUnit is
"year", the interval pattern for en_US when year
is different could be "'from' yyyy 'to' yyyy". intervalPattern)Provides a way for client to build interval patterns. |
| private void | |
| private DateIntervalInfo. | |
| private void | |
| private static int | |
| private static boolean |
| CALENDAR_FIELD_TO_PATTERN_LETTER | back to summary |
|---|---|
| pack-priv static final String[] CALENDAR_FIELD_TO_PATTERN_LETTER | |
| CALENDAR_KEY | back to summary |
|---|---|
| private static String CALENDAR_KEY | |
| currentSerialVersion | back to summary |
|---|---|
| pack-priv static final int currentSerialVersion | |
| DIICACHE | back to summary |
|---|---|
| private static final ICUCache<String, DateIntervalInfo> DIICACHE | |
| EARLIEST_FIRST_PREFIX | back to summary |
|---|---|
| private static String EARLIEST_FIRST_PREFIX | |
| FALLBACK_STRING | back to summary |
|---|---|
| private static String FALLBACK_STRING | |
| fFallbackIntervalPattern | back to summary |
|---|---|
| private String fFallbackIntervalPattern | |
| fFirstDateInPtnIsLaterDate | back to summary |
|---|---|
| private boolean fFirstDateInPtnIsLaterDate | |
| fIntervalPatterns | back to summary |
|---|---|
| private Map<String, Map<String, DateIntervalInfo. | |
| fIntervalPatternsReadOnly | back to summary |
|---|---|
| private transient boolean fIntervalPatternsReadOnly | |
| frozen | back to summary |
|---|---|
| private transient volatile boolean frozen | |
| INTERVAL_FORMATS_KEY | back to summary |
|---|---|
| private static String INTERVAL_FORMATS_KEY | |
| LATEST_FIRST_PREFIX | back to summary |
|---|---|
| private static String LATEST_FIRST_PREFIX | |
| MINIMUM_SUPPORTED_CALENDAR_FIELD | back to summary |
|---|---|
| private static final int MINIMUM_SUPPORTED_CALENDAR_FIELD | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| DateIntervalInfo | back to summary |
|---|---|
| public DateIntervalInfo()
Deprecated This API is ICU internal only. Create empty instance. It does not initialize any interval patterns except that it initialize default fall-back pattern as "{0} - {1}", which can be reset by setFallbackIntervalPattern(). It should be followed by setFallbackIntervalPattern() and setIntervalPattern(), and is recommended to be used only for power users who wants to create their own interval patterns and use them to create date interval formatter.
| |
| DateIntervalInfo | back to summary |
|---|---|
| public DateIntervalInfo(ULocale locale) Construct DateIntervalInfo for the given locale, | |
| DateIntervalInfo | back to summary |
|---|---|
| public DateIntervalInfo(Locale locale) Construct DateIntervalInfo for the given | |
| clone | back to summary |
|---|---|
| public Object clone() Overrides java. Clone this object. | |
| cloneAsThawed | back to summary |
|---|---|
| public DateIntervalInfo cloneAsThawed() Implements com. Doc from com. Provides for the clone operation. Any clone is initially unfrozen. | |
| cloneIntervalPatterns | back to summary |
|---|---|
| private static Map | |
| cloneUnfrozenDII | back to summary |
|---|---|
| private Object cloneUnfrozenDII() | |
| equals | back to summary |
|---|---|
| public boolean equals(Object a) Overrides java. Override equals
| |
| freeze | back to summary |
|---|---|
| public DateIntervalInfo freeze() Implements com. Doc from com. Freezes the object.
| |
| genPatternInfo | back to summary |
|---|---|
| public static DateIntervalInfo. Deprecated This API is ICU internal only. Break interval patterns as 2 part and save them into pattern info.
| |
| getBestSkeleton | back to summary |
|---|---|
| pack-priv DateIntervalFormat. | |
| getDefaultOrder | back to summary |
|---|---|
| public boolean getDefaultOrder() Get default order -- whether the first date in pattern is later date or not. return default date ordering in interval pattern. true if the first date in pattern is later date, false otherwise.
| |
| getFallbackIntervalPattern | back to summary |
|---|---|
| public String getFallbackIntervalPattern() Get the fallback interval pattern. | |
| getIntervalPattern | back to summary |
|---|---|
| public DateIntervalInfo. Get the interval pattern given the largest different calendar field.
| |
| getPatterns | back to summary |
|---|---|
| public Map Deprecated This API is ICU internal only.
| |
| getRawPatterns | back to summary |
|---|---|
| public Map Deprecated This API is ICU internal only. Get the internal patterns, with a deep clone for safety.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Override hashcode
| |
| initializeData | back to summary |
|---|---|
| private void initializeData(ULocale locale) | |
| initializeFromReadOnlyPatterns | back to summary |
|---|---|
| private void initializeFromReadOnlyPatterns(DateIntervalInfo dii) Initialize this object
| |
| isFrozen | back to summary |
|---|---|
| public boolean isFrozen() Implements com. Doc from com. Determines whether the object has been frozen or not. | |
| parseSkeleton | back to summary |
|---|---|
| pack-priv static void parseSkeleton(String skeleton, int[] skeletonFieldWidth) Parse skeleton, save each field's width. It is used for looking for best match skeleton, and adjust pattern field width.
| |
| setFallbackIntervalPattern | back to summary |
|---|---|
| public void setFallbackIntervalPattern(String fallbackPattern) Re-set the fallback interval pattern. In construction, default fallback pattern is set as "{0} - {1}". And constructor taking locale as parameter will set the fallback pattern as what defined in the locale resource file. This method provides a way for user to replace the fallback pattern.
| |
| setIntervalPattern | back to summary |
|---|---|
| public void setIntervalPattern(String skeleton, int lrgDiffCalUnit, String intervalPattern) Provides a way for client to build interval patterns. User could construct DateIntervalInfo by providing a list of skeletons and their patterns. For example:
DateIntervalInfo dIntervalInfo = new DateIntervalInfo();
dIntervalInfo.setIntervalPattern("yMd", Calendar.YEAR, "'from' yyyy-M-d 'to' yyyy-M-d");
dIntervalInfo.setIntervalPattern("yMMMd", Calendar.MONTH, "'from' yyyy MMM d 'to' MMM d");
dIntervalInfo.setIntervalPattern("yMMMd", Calendar.DAY, "yyyy MMM d-d");
dIntervalInfo.setFallbackIntervalPattern("{0} ~ {1}");
Restriction:
Currently, users can only set interval patterns when the following
calendar fields are different: ERA, YEAR, MONTH, DATE, DAY_OF_MONTH,
DAY_OF_WEEK, AM_PM, HOUR, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND.
Interval patterns when other calendar fields are different are
not supported.
| |
| setIntervalPattern | back to summary |
|---|---|
| private void setIntervalPattern(String skeleton, String lrgDiffCalUnit, DateIntervalInfo. | |
| setIntervalPatternInternally | back to summary |
|---|---|
| private DateIntervalInfo. | |
| setup | back to summary |
|---|---|
| private void setup(ULocale locale) | |
| splitPatternInto2Part | back to summary |
|---|---|
| private static int splitPatternInto2Part(String intervalPattern) | |
| stringNumeric | back to summary |
|---|---|
| private static boolean stringNumeric(int fieldWidth, int anotherFieldWidth, char patternLetter) | |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | ACCEPTED_PATTERN_LETTERS
Accepted pattern letters: Calendar.YEAR Calendar.MONTH Calendar.DATE Calendar.AM_PM Calendar.HOUR Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND |
| private static final String | |
| private static final String | |
| pack-priv DateIntervalInfo | |
| pack-priv String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| private String | |
| public void | processSkeletonTable(UResource.
Processes the patterns for a skeleton table. |
| public void | put(UResource.
Initially the key string of the enumeration-start resource.
Empty if the enumeration starts at the top level of the bundle.
Reuse for output values from Array and Table getters. key,Call getArray() or getTable() as appropriate.
Then reuse for output values from Array and Table getters. value,true if the bundle has no parent;
that is, its top-level table has the nofallback attribute,
or it is the root bundle of a locale tree. noFallback)Implements abstract com. |
| private void | setIntervalPatternIfAbsent(String currentSkeleton, String lrgDiffCalUnit, UResource.
Stores the interval pattern for the current skeleton in the internal data structure if it's not present. |
| private CharSequence | Returns: Pattern letterProcesses the pattern letter |
| ACCEPTED_PATTERN_LETTERS | back to summary |
|---|---|
| private static final String ACCEPTED_PATTERN_LETTERS Accepted pattern letters: Calendar.YEAR Calendar.MONTH Calendar.DATE Calendar.AM_PM Calendar.HOUR Calendar.HOUR_OF_DAY Calendar.MINUTE Calendar.SECOND Calendar.MILLISECOND | |
| DATE_INTERVAL_PATH_PREFIX | back to summary |
|---|---|
| private static final String DATE_INTERVAL_PATH_PREFIX | |
| DATE_INTERVAL_PATH_SUFFIX | back to summary |
|---|---|
| private static final String DATE_INTERVAL_PATH_SUFFIX | |
| dateIntervalInfo | back to summary |
|---|---|
| pack-priv DateIntervalInfo dateIntervalInfo | |
| nextCalendarType | back to summary |
|---|---|
| pack-priv String nextCalendarType | |
| DateIntervalSink | back to summary |
|---|---|
| public DateIntervalSink(DateIntervalInfo dateIntervalInfo) | |
| getAndResetNextCalendarType | back to summary |
|---|---|
| public String getAndResetNextCalendarType() Returns and resets the next calendar type.
| |
| getCalendarTypeFromPath | back to summary |
|---|---|
| private String getCalendarTypeFromPath(String path) Extracts the calendar type from the path
| |
| processSkeletonTable | back to summary |
|---|---|
| public void processSkeletonTable(UResource. Processes the patterns for a skeleton table. | |
| put | back to summary |
|---|---|
| public void put(UResource. Implements abstract com. Doc from com. Called once for each bundle (child-parent-...-root). The value is normally an array or table resource, and implementations of this method normally iterate over the tree of resource items stored there.
| |
| setIntervalPatternIfAbsent | back to summary |
|---|---|
| private void setIntervalPatternIfAbsent(String currentSkeleton, String lrgDiffCalUnit, UResource. Stores the interval pattern for the current skeleton in the internal data structure if it's not present. | |
| validateAndProcessPatternLetter | back to summary |
|---|---|
| private CharSequence validateAndProcessPatternLetter(CharSequence patternLetter) Processes the pattern letter
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | |
| private final boolean | |
| private final String | |
| private final String | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | PatternInfo(String
The first part of interval pattern. firstPart, String The second part of interval pattern. secondPart, boolean Whether the first date in interval patter is later date or not. firstDateInPtnIsLaterDate)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the specified object is equal to this PatternInfo.The object to be compared. a)Overrides java. PatternInfo for equality.
|
| public boolean | Returns: Whether the first date in interval patter is later date or not.Returns whether the first date in interval patter is later date or not. |
| public String | Returns: The first part of interval pattern.Returns the first part of interval pattern. |
| public String | Returns: The second part of interval pattern.Returns the second part of interval pattern. |
| public int | Returns: A hash code value for this object.Overrides java. PatternInfo.
|
| public String |
| currentSerialVersion | back to summary |
|---|---|
| pack-priv static final int currentSerialVersion | |
| fFirstDateInPtnIsLaterDate | back to summary |
|---|---|
| private final boolean fFirstDateInPtnIsLaterDate | |
| fIntervalPatternFirstPart | back to summary |
|---|---|
| private final String fIntervalPatternFirstPart | |
| fIntervalPatternSecondPart | back to summary |
|---|---|
| private final String fIntervalPatternSecondPart | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| PatternInfo | back to summary |
|---|---|
| public PatternInfo(String firstPart, String secondPart, boolean firstDateInPtnIsLaterDate) Constructs a | |
| equals | back to summary |
|---|---|
| public boolean equals(Object a) Overrides java. Compares the specified object with this | |
| firstDateInPtnIsLaterDate | back to summary |
|---|---|
| public boolean firstDateInPtnIsLaterDate() Returns whether the first date in interval patter is later date or not.
| |
| getFirstPart | back to summary |
|---|---|
| public String getFirstPart() Returns the first part of interval pattern. | |
| getSecondPart | back to summary |
|---|---|
| public String getSecondPart() Returns the second part of interval pattern. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns the hash code of this | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |