Beispiel #1
0
  /*
   * dateStrings[0] = TODAY_TEXT
   * dateStrings[1] = YESTERDAY_TEXT
   */
  public static String getNiceTimeString(Calendar cal) {
    final String[] dateText = CityAlarmApplication.getAppResources().dateText;

    Calendar calNow = Calendar.getInstance();

    Calendar calTime = Calendar.getInstance();
    calTime.setTimeInMillis(cal.getTimeInMillis());

    // check for today and yesterday
    boolean isToday = false;
    boolean isYesterday = false;

    if (calNow.get(Calendar.YEAR) == calTime.get(Calendar.YEAR)) {
      if (calNow.get(Calendar.DAY_OF_YEAR) == calTime.get(Calendar.DAY_OF_YEAR)) isToday = true;
    }

    calNow.add(Calendar.DAY_OF_YEAR, -1);

    if (calNow.get(Calendar.YEAR) == calTime.get(Calendar.YEAR)) {
      if (calNow.get(Calendar.DAY_OF_YEAR) == calTime.get(Calendar.DAY_OF_YEAR)) isYesterday = true;
    }

    String text = Utils.getTimeString(calTime);

    if (isToday) {
      text = dateText[0] + ", " + Utils.getTimeOnlyString(calTime);
    }

    if (isYesterday) {
      text = dateText[1] + ", " + Utils.getTimeOnlyString(calTime);
    }

    return text;
  }