gt:                 if (abbrevRelative) {
context: /*
   * Copyright (C) 2006 The Android Open Source Project
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package android.text.format;
  
  import com.android.internal.R;
  
  import android.content.Context;
  import android.content.res.Configuration;
  import android.content.res.Resources;
  
  import java.io.IOException;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.Formatter;
  import java.util.GregorianCalendar;
  import java.util.Locale;
  
  import libcore.icu.DateIntervalFormat;
  import libcore.icu.LocaleData;
  
  /**
   * This class contains various date-related utilities for creating text for things like
   * elapsed time and date ranges, strings for days of the week and months, and AM/PM text etc.
   */
  public class DateUtils
  {
      private static final Object sLock = new Object();
      private static Configuration sLastConfig;
      private static String sElapsedFormatMMSS;
      private static String sElapsedFormatHMMSS;
  
      public static final long SECOND_IN_MILLIS = 1000;
      public static final long MINUTE_IN_MILLIS = SECOND_IN_MILLIS * 60;
      public static final long HOUR_IN_MILLIS = MINUTE_IN_MILLIS * 60;
      public static final long DAY_IN_MILLIS = HOUR_IN_MILLIS * 24;
      public static final long WEEK_IN_MILLIS = DAY_IN_MILLIS * 7;
      /**
       * This constant is actually the length of 364 days, not of a year!
       */
      public static final long YEAR_IN_MILLIS = WEEK_IN_MILLIS * 52;
  
      // The following FORMAT_* symbols are used for specifying the format of
      // dates and times in the formatDateRange method.
      public static final int FORMAT_SHOW_TIME = 0x00001;
      public static final int FORMAT_SHOW_WEEKDAY = 0x00002;
      public static final int FORMAT_SHOW_YEAR = 0x00004;
      public static final int FORMAT_NO_YEAR = 0x00008;
      public static final int FORMAT_SHOW_DATE = 0x00010;
      public static final int FORMAT_NO_MONTH_DAY = 0x00020;
      @Deprecated
      public static final int FORMAT_12HOUR = 0x00040;
      @Deprecated
      public static final int FORMAT_24HOUR = 0x00080;
      @Deprecated
      public static final int FORMAT_CAP_AMPM = 0x00100;
      public static final int FORMAT_NO_NOON = 0x00200;
      @Deprecated
      public static final int FORMAT_CAP_NOON = 0x00400;
      public static final int FORMAT_NO_MIDNIGHT = 0x00800;
      @Deprecated
      public static final int FORMAT_CAP_MIDNIGHT = 0x01000;
      /**
       * @deprecated Use
       * {@link #formatDateRange(Context, Formatter, long, long, int, String) formatDateRange}
       * and pass in {@link Time#TIMEZONE_UTC Time.TIMEZONE_UTC} for the timeZone instead.
       */
      @Deprecated
      public static final int FORMAT_UTC = 0x02000;
      public static final int FORMAT_ABBREV_TIME = 0x04000;
      public static final int FORMAT_ABBREV_WEEKDAY = 0x08000;
      public static final int FORMAT_ABBREV_MONTH = 0x10000;
      public static final int FORMAT_NUMERIC_DATE = 0x20000;
      public static final int FORMAT_ABBREV_RELATIVE = 0x40000;
      public static final int FORMAT_ABBREV_ALL = 0x80000;
      @Deprecated
      public static final int FORMAT_CAP_NOON_MIDNIGHT = (FORMAT_CAP_NOON | FORMAT_CAP_MIDNIGHT);
      @Deprecated
      public static final int FORMAT_NO_NOON_MIDNIGHT = (FORMAT_NO_NOON | FORMAT_NO_MIDNIGHT);
  
      // Date and time format strings that are constant and don't need to be
      // translated.
      /**
       * This is not actually the preferred 24-hour date format in all locales.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final String HOUR_MINUTE_24 = "%H:%M";
      public static final String MONTH_FORMAT = "%B";
      /**
       * This is not actually a useful month name in all locales.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final String ABBREV_MONTH_FORMAT = "%b";
      public static final String NUMERIC_MONTH_FORMAT = "%m";
      public static final String MONTH_DAY_FORMAT = "%-d";
      public static final String YEAR_FORMAT = "%Y";
      public static final String YEAR_FORMAT_TWO_DIGITS = "%g";
      public static final String WEEKDAY_FORMAT = "%A";
      public static final String ABBREV_WEEKDAY_FORMAT = "%a";
  
      /** @deprecated Do not use. */
      public static final int[] sameYearTable = null;
  
      /** @deprecated Do not use. */
      public static final int[] sameMonthTable = null;
  
      /**
       * Request the full spelled-out name. For use with the 'abbrev' parameter of
       * {@link #getDayOfWeekString} and {@link #getMonthString}.
       *
       * @more <p>
       *       e.g. "Sunday" or "January"
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final int LENGTH_LONG = 10;
  
      /**
       * Request an abbreviated version of the name. For use with the 'abbrev'
       * parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
       *
       * @more <p>
       *       e.g. "Sun" or "Jan"
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final int LENGTH_MEDIUM = 20;
  
      /**
       * Request a shorter abbreviated version of the name.
       * For use with the 'abbrev' parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
       * @more
       * <p>e.g. "Su" or "Jan"
       * <p>In most languages, the results returned for LENGTH_SHORT will be the same as
       * the results returned for {@link #LENGTH_MEDIUM}.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final int LENGTH_SHORT = 30;
  
      /**
       * Request an even shorter abbreviated version of the name.
       * Do not use this.  Currently this will always return the same result
       * as {@link #LENGTH_SHORT}.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final int LENGTH_SHORTER = 40;
  
      /**
       * Request an even shorter abbreviated version of the name.
       * For use with the 'abbrev' parameter of {@link #getDayOfWeekString} and {@link #getMonthString}.
       * @more
       * <p>e.g. "S", "T", "T" or "J"
       * <p>In some languages, the results returned for LENGTH_SHORTEST will be the same as
       * the results returned for {@link #LENGTH_SHORT}.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static final int LENGTH_SHORTEST = 50;
  
      /**
       * Return a string for the day of the week.
       * @param dayOfWeek One of {@link Calendar#SUNDAY Calendar.SUNDAY},
       *               {@link Calendar#MONDAY Calendar.MONDAY}, etc.
       * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_SHORT},
       *               {@link #LENGTH_MEDIUM}, or {@link #LENGTH_SHORTEST}.
       *               Note that in most languages, {@link #LENGTH_SHORT}
       *               will return the same as {@link #LENGTH_MEDIUM}.
       *               Undefined lengths will return {@link #LENGTH_MEDIUM}
       *               but may return something different in the future.
       * @throws IndexOutOfBoundsException if the dayOfWeek is out of bounds.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static String getDayOfWeekString(int dayOfWeek, int abbrev) {
          LocaleData d = LocaleData.get(Locale.getDefault());
          String[] names;
          switch (abbrev) {
              case LENGTH_LONG:       names = d.longWeekdayNames;  break;
              case LENGTH_MEDIUM:     names = d.shortWeekdayNames; break;
              case LENGTH_SHORT:      names = d.shortWeekdayNames; break; // TODO
              case LENGTH_SHORTER:    names = d.shortWeekdayNames; break; // TODO
              case LENGTH_SHORTEST:   names = d.tinyWeekdayNames;  break;
              default:                names = d.shortWeekdayNames; break;
          }
          return names[dayOfWeek];
      }
  
      /**
       * Return a localized string for AM or PM.
       * @param ampm Either {@link Calendar#AM Calendar.AM} or {@link Calendar#PM Calendar.PM}.
       * @throws IndexOutOfBoundsException if the ampm is out of bounds.
       * @return Localized version of "AM" or "PM".
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static String getAMPMString(int ampm) {
          return LocaleData.get(Locale.getDefault()).amPm[ampm - Calendar.AM];
      }
  
      /**
       * Return a localized string for the month of the year.
       * @param month One of {@link Calendar#JANUARY Calendar.JANUARY},
       *               {@link Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
       * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_MEDIUM},
       *               or {@link #LENGTH_SHORTEST}.
       *               Undefined lengths will return {@link #LENGTH_MEDIUM}
       *               but may return something different in the future.
       * @return Localized month of the year.
       * @deprecated Use {@link java.text.SimpleDateFormat} instead.
       */
      @Deprecated
      public static String getMonthString(int month, int abbrev) {
          LocaleData d = LocaleData.get(Locale.getDefault());
          String[] names;
          switch (abbrev) {
              case LENGTH_LONG:       names = d.longMonthNames;  break;
              case LENGTH_MEDIUM:     names = d.shortMonthNames; break;
              case LENGTH_SHORT:      names = d.shortMonthNames; break;
              case LENGTH_SHORTER:    names = d.shortMonthNames; break;
              case LENGTH_SHORTEST:   names = d.tinyMonthNames;  break;
              default:                names = d.shortMonthNames; break;
          }
          return names[month];
      }
  
      /**
       * Returns a string describing the elapsed time since startTime.
       * @param startTime some time in the past.
       * @return a String object containing the elapsed time.
       * @see #getRelativeTimeSpanString(long, long, long)
       */
      public static CharSequence getRelativeTimeSpanString(long startTime) {
          return getRelativeTimeSpanString(startTime, System.currentTimeMillis(), MINUTE_IN_MILLIS);
      }
  
      /**
       * Returns a string describing 'time' as a time relative to 'now'.
       * <p>
       * Time spans in the past are formatted like "42 minutes ago".
       * Time spans in the future are formatted like "in 42 minutes".
       *
       * @param time the time to describe, in milliseconds
       * @param now the current time in milliseconds
       * @param minResolution the minimum timespan to report. For example, a time 3 seconds in the
       *     past will be reported as "0 minutes ago" if this is set to MINUTE_IN_MILLIS. Pass one of
       *     0, MINUTE_IN_MILLIS, HOUR_IN_MILLIS, DAY_IN_MILLIS, WEEK_IN_MILLIS
       */
      public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution) {
          int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_YEAR | FORMAT_ABBREV_MONTH;
          return getRelativeTimeSpanString(time, now, minResolution, flags);
      }
  
      /**
       * Returns a string describing 'time' as a time relative to 'now'.
       * <p>
       * Time spans in the past are formatted like "42 minutes ago". Time spans in
       * the future are formatted like "in 42 minutes".
       * <p>
       * Can use {@link #FORMAT_ABBREV_RELATIVE} flag to use abbreviated relative
       * times, like "42 mins ago".
       *
       * @param time the time to describe, in milliseconds
       * @param now the current time in milliseconds
       * @param minResolution the minimum timespan to report. For example, a time
       *            3 seconds in the past will be reported as "0 minutes ago" if
       *            this is set to MINUTE_IN_MILLIS. Pass one of 0,
       *            MINUTE_IN_MILLIS, HOUR_IN_MILLIS, DAY_IN_MILLIS,
       *            WEEK_IN_MILLIS
       * @param flags a bit mask of formatting options, such as
       *            {@link #FORMAT_NUMERIC_DATE} or
       *            {@link #FORMAT_ABBREV_RELATIVE}
       */
      public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution,
              int flags) {
          Resources r = Resources.getSystem();
          boolean abbrevRelative = (flags & (FORMAT_ABBREV_RELATIVE | FORMAT_ABBREV_ALL)) != 0;
  
          boolean past = (now >= time);
          long duration = Math.abs(now - time);
  
          int resId;
          long count;
          if (duration < MINUTE_IN_MILLIS && minResolution < MINUTE_IN_MILLIS) {
              count = duration / SECOND_IN_MILLIS;
              if (past) {
                  if (abbrevRelative) {
                      resId = com.android.internal.R.plurals.abbrev_num_seconds_ago;
                  } else {
                      resId = com.android.internal.R.plurals.num_seconds_ago;
                  }
              } else {
                  if (abbrevRelative) {
                      resId = com.android.internal.R.plurals.abbrev_in_num_seconds;
                  } else {
                      resId = com.android.internal.R.plurals.in_num_seconds;
                  }
              }
          } else if (duration < HOUR_IN_MILLIS && minResolution < HOUR_IN_MILLIS) {
              count = duration / MINUTE_IN_MILLIS;
              if (past) {
  