Home | History | Annotate | Download | only in text
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 2007-2015, International Business Machines Corporation and
      6  * others. All Rights Reserved.
      7  *******************************************************************************
      8  */
      9 package com.ibm.icu.text;
     10 
     11 import java.text.FieldPosition;
     12 import java.text.ParsePosition;
     13 import java.util.Date;
     14 
     15 import com.ibm.icu.impl.duration.BasicDurationFormat;
     16 import com.ibm.icu.util.ULocale;
     17 
     18 /**
     19  * This <b>deprecated</b> class implements a formatter over a duration in time
     20  * such as "2 days from now" or "3 hours ago".
     21  *
     22  * <p>Use MeasureFormat to format periods like "5 days, 3 hours";
     23  * use RelativeDateTimeFormatter to format relative dates like "5 days ago".
     24  *
     25  * @see MeasureFormat
     26  * @see RelativeDateTimeFormatter
     27  * @deprecated ICU 56 Use MeasureFormat or RelativeDateTimeFormatter instead.
     28  */
     29 @Deprecated
     30 public abstract class DurationFormat extends UFormat {
     31 
     32     private static final long serialVersionUID = -2076961954727774282L;
     33 
     34     /**
     35      * Construct a duration format for the specified locale
     36      * @deprecated ICU 56
     37      */
     38     @Deprecated
     39     public static DurationFormat getInstance(ULocale locale) {
     40         return BasicDurationFormat.getInstance(locale);
     41     }
     42 
     43 
     44     /**
     45      * Subclass interface
     46      * @internal
     47      * @deprecated This API is ICU internal only.
     48      */
     49     @Deprecated
     50     protected DurationFormat() {
     51     }
     52 
     53     /**
     54      * Subclass interface
     55      * @internal
     56      * @deprecated This API is ICU internal only.
     57      */
     58     @Deprecated
     59     protected DurationFormat(ULocale locale) {
     60         setLocale(locale,locale);
     61     }
     62 
     63     /**
     64      * Format an arbitrary object.
     65      * Defaults to a call to formatDurationFromNow() for either Long or Date objects.
     66      * @param object the object to format. Should be either a Long, Date, or javax.xml.datatype.Duration object.
     67      * @param toAppend the buffer to append to
     68      * @param pos the field position, may contain additional error messages.
     69      * @return the toAppend buffer
     70      * @deprecated ICU 56
     71      */
     72     @Deprecated
     73     @Override
     74     public abstract StringBuffer format(Object object, StringBuffer toAppend,
     75             FieldPosition pos);
     76 
     77     /**
     78      * DurationFormat cannot parse, by default. This method will throw an UnsupportedOperationException.
     79      * @deprecated ICU 56
     80      */
     81     @Override
     82     @Deprecated
     83     public Object parseObject(String source, ParsePosition pos) {
     84        throw new UnsupportedOperationException();
     85     }
     86 
     87     /**
     88      * Formats the duration between now and a target date.
     89      * <p>
     90      * This is a convenience method that calls
     91      * formatDurationFrom(long, long) using now
     92      * as the reference date, and the difference between now and
     93      * <code>targetDate.getTime()</code> as the duration.
     94      *
     95      * @param targetDate the ending date
     96      * @return the formatted time
     97      * @deprecated ICU 56
     98      */
     99     @Deprecated
    100     public abstract String formatDurationFromNowTo(Date targetDate);
    101 
    102     /**
    103      * Formats a duration expressed in milliseconds.
    104      * <p>
    105      * This is a convenience method that calls formatDurationFrom
    106      * using the current system time as the reference date.
    107      *
    108      * @param duration the duration in milliseconds
    109      * @return the formatted time
    110      * @deprecated ICU 56
    111      */
    112     @Deprecated
    113     public abstract String formatDurationFromNow(long duration);
    114 
    115     /**
    116      * Formats a duration expressed in milliseconds from a reference date.
    117      * <p>
    118      * The reference date allows formatters to use actual durations of
    119      * variable-length periods (like months) if they wish.
    120      * <p>
    121      * The duration is expressed as the number of milliseconds in the
    122      * past (negative values) or future (positive values) with respect
    123      * to a reference date (expressed as milliseconds in epoch).
    124      *
    125      * @param duration the duration in milliseconds
    126      * @param referenceDate the date from which to compute the duration
    127      * @return the formatted time
    128      * @deprecated ICU 56
    129      */
    130     @Deprecated
    131     public abstract String formatDurationFrom(long duration, long referenceDate);
    132 }
    133