Top Inners Fields Constructors Methods
com.ibm.icu.impl

public Class RelativeDateFormat

extends DateFormat
Class Inheritance
Imports
java.text.FieldPosition, .ParsePosition, java.util.ArrayList, .Date, .List, .MissingResourceException, com.ibm.icu.lang.UCharacter, com.ibm.icu.text.BreakIterator, .DateFormat, .DisplayContext, .MessageFormat, .SimpleDateFormat, com.ibm.icu.util.Calendar, .TimeZone, .ULocale, .UResourceBundle

Author
srl

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
public static class

Field Summary

Modifier and TypeField and Description
private transient BreakIterator
private boolean
private boolean
private boolean
private boolean
private MessageFormat
private DateFormat
private String
private transient List<RelativeDateFormat.URelativeString>
pack-priv int
private SimpleDateFormat
pack-priv ULocale
private DateFormat
private String
pack-priv int
private static final long
Inherited from com.ibm.icu.text.DateFormat:
ABBR_GENERIC_TZABBR_MONTHABBR_MONTH_DAYABBR_MONTH_WEEKDAY_DAYABBR_QUARTERABBR_SPECIFIC_TZABBR_STANDALONE_MONTHABBR_UTC_TZABBR_WEEKDAYAM_PM_FIELDAM_PM_MIDNIGHT_NOON_FIELDcalendarDATE_FIELDDATE_SKELETONSDAYDAY_OF_WEEK_FIELDDAY_OF_WEEK_IN_MONTH_FIELDDAY_OF_YEAR_FIELDDEFAULTDOW_LOCAL_FIELDERA_FIELDEXTENDED_YEAR_FIELDFIELD_COUNTFLEXIBLE_DAY_PERIOD_FIELDFRACTIONAL_SECOND_FIELDFULLGENERIC_TZHOURHOUR0_FIELDHOUR1_FIELDHOUR24HOUR24_MINUTEHOUR24_MINUTE_SECONDHOUR_GENERIC_TZHOUR_MINUTEHOUR_MINUTE_GENERIC_TZHOUR_MINUTE_SECONDHOUR_MINUTE_TZHOUR_OF_DAY0_FIELDHOUR_OF_DAY1_FIELDHOUR_TZJP_ERA_2019_JAJP_ERA_2019_NARROWJP_ERA_2019_ROOTJULIAN_DAY_FIELDLOCATION_TZLONGMEDIUMMILLISECOND_FIELDMILLISECONDS_IN_DAY_FIELDMINUTEMINUTE_FIELDMINUTE_SECONDMONTHMONTH_DAYMONTH_FIELDMONTH_WEEKDAY_DAYNONENUM_MONTHNUM_MONTH_DAYNUM_MONTH_WEEKDAY_DAYnumberFormatQUARTERQUARTER_FIELDRELATIVERELATIVE_DEFAULTRELATIVE_FULLRELATIVE_LONGRELATIVE_MEDIUMRELATIVE_SHORTSECONDSECOND_FIELDSHORTSPECIFIC_TZSTANDALONE_DAY_FIELDSTANDALONE_MONTHSTANDALONE_MONTH_FIELDSTANDALONE_QUARTER_FIELDTIME_SEPARATORTIME_SKELETONSTIMEZONE_FIELDTIMEZONE_GENERIC_FIELDTIMEZONE_ISO_FIELDTIMEZONE_ISO_LOCAL_FIELDTIMEZONE_LOCALIZED_GMT_OFFSET_FIELDTIMEZONE_RFC_FIELDTIMEZONE_SPECIAL_FIELDWEEK_OF_MONTH_FIELDWEEK_OF_YEAR_FIELDWEEKDAYYEARYEAR_ABBR_MONTHYEAR_ABBR_MONTH_DAYYEAR_ABBR_MONTH_WEEKDAY_DAYYEAR_ABBR_QUARTERYEAR_FIELDYEAR_MONTHYEAR_MONTH_DAYYEAR_MONTH_WEEKDAY_DAYYEAR_NAME_FIELDYEAR_NUM_MONTHYEAR_NUM_MONTH_DAYYEAR_NUM_MONTH_WEEKDAY_DAYYEAR_QUARTERYEAR_WOY_FIELDZONE_SKELETONS

Constructor Summary

AccessConstructor and Description
public
RelativeDateFormat(int
The time style for the date and time.
timeStyle
,
int
The date style for the date and time.
dateStyle
,
ULocale
The locale for the date.
locale
,
Calendar
The calendar to be used
cal
)

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

the number of days in "until-now"
dayDifference
(Calendar until)

public StringBuffer
format(Calendar
a Calendar set to the date and time to be formatted into a date/time string. When the calendar type is different from the internal calendar held by this DateFormat instance, the date and the time zone will be inherited from the input calendar, but other calendar field values will be calculated by the internal calendar.
cal
,
StringBuffer
the string buffer for the returning date/time string.
toAppendTo
,
FieldPosition
keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Implements abstract com.ibm.icu.text.DateFormat.format.

Formats a date into a date/time string.
private String

Returns:

the string, or NULL if none at that location.
getStringForDay
(int
day offset ( -1, 0, 1, etc.. ). Does not require sorting by offset.
day
)

Get the string at a specific offset.

private void
initCapitalizationContextInfo(ULocale locale)

Set capitalizationOfRelativeUnitsForListOrMenu, capitalizationOfRelativeUnitsForStandAlone

private Calendar

Returns:

the newly constructed fCalendar
initializeCalendar
(TimeZone
Zone to be adopted, or NULL for TimeZone::createDefault().
zone
,
ULocale
Locale of the calendar
locale
)

initializes fCalendar from parameters.

private MessageFormat
private synchronized void
loadDates()

Load the Date string array

public void
parse(String
The date/time string to be parsed
text
,
Calendar
The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar.
cal
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Implements abstract com.ibm.icu.text.DateFormat.parse.

Parses a date/time string according to the given parse position.
public void
setContext(DisplayContext
The DisplayContext value to set.
context
)

Overrides com.ibm.icu.text.DateFormat.setContext.

ICU

Inherited from com.ibm.icu.text.DateFormat:
cloneequalsformatformatformatgetAvailableLocalesgetAvailableULocalesgetBooleanAttributegetCalendargetContextgetDateInstancegetDateInstancegetDateInstancegetDateInstancegetDateInstancegetDateInstancegetDateInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetInstancegetInstancegetInstancegetInstancegetInstanceForSkeletongetInstanceForSkeletongetInstanceForSkeletongetInstanceForSkeletongetInstanceForSkeletongetNumberFormatgetPatternInstancegetPatternInstancegetPatternInstancegetPatternInstancegetPatternInstancegetTimeInstancegetTimeInstancegetTimeInstancegetTimeInstancegetTimeInstancegetTimeInstancegetTimeInstancegetTimeZonehashCodeisCalendarLenientisLenientparseparseparseObjectsetBooleanAttributesetCalendarsetCalendarLenientsetLenientsetNumberFormatsetTimeZone

Field Detail

capitalizationBrkIterback to summary
private transient BreakIterator capitalizationBrkIter
capitalizationInfoIsSetback to summary
private boolean capitalizationInfoIsSet
capitalizationOfRelativeUnitsForListOrMenuback to summary
private boolean capitalizationOfRelativeUnitsForListOrMenu
capitalizationOfRelativeUnitsForStandAloneback to summary
private boolean capitalizationOfRelativeUnitsForStandAlone
combinedFormatHasDateAtStartback to summary
private boolean combinedFormatHasDateAtStart
fCombinedFormatback to summary
private MessageFormat fCombinedFormat
fDateFormatback to summary
private DateFormat fDateFormat
fDatePatternback to summary
private String fDatePattern
fDatesback to summary
private transient List<RelativeDateFormat.URelativeString> fDates
fDateStyleback to summary
pack-priv int fDateStyle
fDateTimeFormatback to summary
private SimpleDateFormat fDateTimeFormat
fLocaleback to summary
pack-priv ULocale fLocale
fTimeFormatback to summary
private DateFormat fTimeFormat
Annotations
@SuppressWarnings:unused
fTimePatternback to summary
private String fTimePattern
fTimeStyleback to summary
pack-priv int fTimeStyle
serialVersionUIDback to summary
private static final long serialVersionUID

Hides com.ibm.icu.text.DateFormat.serialVersionUID.

serial version (generated)

Constructor Detail

RelativeDateFormatback to summary
public RelativeDateFormat(int timeStyle, int dateStyle, ULocale locale, Calendar cal)
Parameters
timeStyle:int

The time style for the date and time.

dateStyle:int

The date style for the date and time.

locale:ULocale

The locale for the date.

cal:Calendar

The calendar to be used

Method Detail

dayDifferenceback to summary
private static int dayDifference(Calendar until)
Returns:int

the number of days in "until-now"

formatback to summary
public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition fieldPosition)

Implements abstract com.ibm.icu.text.DateFormat.format.

Doc from com.ibm.icu.text.DateFormat.format.

Formats a date into a date/time string.

Parameters
cal:Calendar

a Calendar set to the date and time to be formatted into a date/time string. When the calendar type is different from the internal calendar held by this DateFormat instance, the date and the time zone will be inherited from the input calendar, but other calendar field values will be calculated by the internal calendar.

toAppendTo:StringBuffer

the string buffer for the returning date/time string.

fieldPosition:FieldPosition

keeps track of the position of the field within the returned string. On input: an alignment field, if desired. On output: the offsets of the alignment field. For example, given a time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat.YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that time field. For instance, formatting a Date to the time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.

Returns:StringBuffer

the formatted date/time string.

Annotations
@Override
getStringForDayback to summary
private String getStringForDay(int day)

Get the string at a specific offset.

Parameters
day:int

day offset ( -1, 0, 1, etc.. ). Does not require sorting by offset.

Returns:String

the string, or NULL if none at that location.

initCapitalizationContextInfoback to summary
private void initCapitalizationContextInfo(ULocale locale)

Set capitalizationOfRelativeUnitsForListOrMenu, capitalizationOfRelativeUnitsForStandAlone

initializeCalendarback to summary
private Calendar initializeCalendar(TimeZone zone, ULocale locale)

initializes fCalendar from parameters. Returns fCalendar as a convenience.

Parameters
zone:TimeZone

Zone to be adopted, or NULL for TimeZone::createDefault().

locale:ULocale

Locale of the calendar

Returns:Calendar

the newly constructed fCalendar

initializeCombinedFormatback to summary
private MessageFormat initializeCombinedFormat(Calendar cal, ULocale locale)
loadDatesback to summary
private synchronized void loadDates()

Load the Date string array

parseback to summary
public void parse(String text, Calendar cal, ParsePosition pos)

Implements abstract com.ibm.icu.text.DateFormat.parse.

Doc from com.ibm.icu.text.DateFormat.parse.

Parses a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Calendar that is equivalent to Date(837039928046). Before calling this method the caller should initialize the calendar in one of two ways (unless existing field information is to be kept): (1) clear the calendar, or (2) set the calendar to the current date (or to any date whose fields should be used to supply values that are missing in the parsed date). For example, Chinese calendar dates do not normally provide an era/cycle; in this case the calendar that is passed in should be set to a date within the era that should be assumed, normally the current era.

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

Parameters
text:String

The date/time string to be parsed

cal:Calendar

The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar.

pos:ParsePosition

On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.

Annotations
@Override
setContextback to summary
public void setContext(DisplayContext context)

Overrides com.ibm.icu.text.DateFormat.setContext.

Doc from com.ibm.icu.text.DateFormat.setContext.

ICU

Set a particular DisplayContext value in the formatter, such as CAPITALIZATION_FOR_STANDALONE.
Parameters
context:DisplayContext

The DisplayContext value to set.

Annotations
@Override
com.ibm.icu.impl back to summary

private final Class RelativeDateFormat.RelDateFmtDataSink

extends Sink
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
put(UResource.Key
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
,
UResource.Value
Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.
value
,
boolean
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.ibm.icu.impl.UResource.Sink.put.

Called once for each bundle (child-parent-...-root).

Constructor Detail

RelDateFmtDataSinkback to summary
private RelDateFmtDataSink()

Method Detail

putback to summary
public void put(UResource.Key key, UResource.Value value, boolean noFallback)

Implements abstract com.ibm.icu.impl.UResource.Sink.put.

Doc from com.ibm.icu.impl.UResource.Sink.put.

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.

Parameters
key:UResource.Key

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.

value:UResource.Value

Call getArray() or getTable() as appropriate. Then reuse for output values from Array and Table getters.

noFallback:boolean

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.

Annotations
@Override
com.ibm.icu.impl back to summary

public Class RelativeDateFormat.URelativeString

extends Object
Class Inheritance

Author
srl

Field Summary

Modifier and TypeField and Description
public int
public String

Constructor Summary

AccessConstructor and Description
pack-priv
URelativeString(int offset, String string)

pack-priv
URelativeString(String offset, String string)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

offsetback to summary
public int offset
stringback to summary
public String string

Constructor Detail

URelativeStringback to summary
pack-priv URelativeString(int offset, String string)
URelativeStringback to summary
pack-priv URelativeString(String offset, String string)