Class RelativeDateFormat

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class RelativeDateFormat
    extends DateFormat
    See Also:
    Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        serial version (generated)
        See Also:
        Constant Field Values
      • fDatePattern

        private java.lang.String fDatePattern
      • fTimePattern

        private java.lang.String fTimePattern
      • fDateStyle

        int fDateStyle
      • fTimeStyle

        int fTimeStyle
      • combinedFormatHasDateAtStart

        private boolean combinedFormatHasDateAtStart
      • capitalizationInfoIsSet

        private boolean capitalizationInfoIsSet
      • capitalizationOfRelativeUnitsForListOrMenu

        private boolean capitalizationOfRelativeUnitsForListOrMenu
      • capitalizationOfRelativeUnitsForStandAlone

        private boolean capitalizationOfRelativeUnitsForStandAlone
      • capitalizationBrkIter

        private transient BreakIterator capitalizationBrkIter
    • Constructor Detail

      • RelativeDateFormat

        public RelativeDateFormat​(int timeStyle,
                                  int dateStyle,
                                  ULocale locale,
                                  Calendar cal)
        Parameters:
        timeStyle - The time style for the date and time.
        dateStyle - The date style for the date and time.
        locale - The locale for the date.
        cal - The calendar to be used
    • Method Detail

      • format

        public java.lang.StringBuffer format​(Calendar cal,
                                             java.lang.StringBuffer toAppendTo,
                                             java.text.FieldPosition fieldPosition)
        Description copied from class: DateFormat
        Formats a date into a date/time string.
        Specified by:
        format in class DateFormat
        Parameters:
        cal - 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 - the string buffer for the returning date/time string.
        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:
        the formatted date/time string.
      • parse

        public void parse​(java.lang.String text,
                          Calendar cal,
                          java.text.ParsePosition pos)
        Description copied from class: DateFormat
        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).

        Specified by:
        parse in class DateFormat
        Parameters:
        text - The date/time string to be parsed
        cal - 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 - 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.
        See Also:
        DateFormat.setLenient(boolean)
      • setContext

        public void setContext​(DisplayContext context)
        Description copied from class: DateFormat
        Set a particular DisplayContext value in the formatter, such as CAPITALIZATION_FOR_STANDALONE.
        Overrides:
        setContext in class DateFormat
        Parameters:
        context - The DisplayContext value to set.
      • getStringForDay

        private java.lang.String getStringForDay​(int day)
        Get the string at a specific offset.
        Parameters:
        day - day offset ( -1, 0, 1, etc.. ). Does not require sorting by offset.
        Returns:
        the string, or NULL if none at that location.
      • loadDates

        private void loadDates()
        Load the Date string array
      • initCapitalizationContextInfo

        private void initCapitalizationContextInfo​(ULocale locale)
        Set capitalizationOfRelativeUnitsForListOrMenu, capitalizationOfRelativeUnitsForStandAlone
      • dayDifference

        private static int dayDifference​(Calendar until)
        Returns:
        the number of days in "until-now"
      • initializeCalendar

        private Calendar initializeCalendar​(TimeZone zone,
                                            ULocale locale)
        initializes fCalendar from parameters. Returns fCalendar as a convenience.
        Parameters:
        zone - Zone to be adopted, or NULL for TimeZone::createDefault().
        locale - Locale of the calendar
        status - Error code
        Returns:
        the newly constructed fCalendar