コード例 #1
0
  protected void nextIntervalDate(Calendar c, DateIntervalType intervalType, int intervals) {

    if (MILLENIUM.equals(intervalType)) {
      c.add(Calendar.YEAR, 1000 * intervals);
    } else if (CENTURY.equals(intervalType)) {
      c.add(Calendar.YEAR, 100 * intervals);
    } else if (DECADE.equals(intervalType)) {
      c.add(Calendar.YEAR, 10 * intervals);
    } else if (YEAR.equals(intervalType)) {
      c.add(Calendar.YEAR, intervals);
    } else if (QUARTER.equals(intervalType)) {
      c.add(Calendar.MONTH, 3 * intervals);
    } else if (MONTH.equals(intervalType)) {
      c.add(Calendar.MONTH, intervals);
    } else if (WEEK.equals(intervalType)) {
      c.add(Calendar.DAY_OF_MONTH, 7 * intervals);
    } else if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType)) {
      c.add(Calendar.DAY_OF_MONTH, intervals);
    } else if (HOUR.equals(intervalType)) {
      c.add(Calendar.HOUR_OF_DAY, intervals);
    } else if (MINUTE.equals(intervalType)) {
      c.add(Calendar.MINUTE, intervals);
    } else if (SECOND.equals(intervalType)) {
      c.add(Calendar.SECOND, intervals);
    } else {
      // Default to year to avoid infinite loops
      c.add(Calendar.YEAR, intervals);
    }
  }
コード例 #2
0
  public static String calculateName(DateIntervalType intervalType, Date d) {
    if (d == null) return null;

    Locale l = Locale.getDefault();
    if (MILLENIUM.equals(intervalType)
        || CENTURY.equals(intervalType)
        || DECADE.equals(intervalType)
        || YEAR.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy", l);
      return format.format(d);
    }
    if (QUARTER.equals(intervalType) || MONTH.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM", l);
      return format.format(d);
    }
    if (WEEK.equals(intervalType) || DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      return format.format(d);
    }
    if (HOUR.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
      return format.format(d);
    }
    if (MINUTE.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      return format.format(d);
    }
    if (SECOND.equals(intervalType)) {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      return format.format(d);
    }
    return format.format(d);
  }
コード例 #3
0
 protected Calendar firstIntervalDate(
     DateIntervalType intervalType, Date minDate, ColumnGroup columnGroup) {
   Calendar c = GregorianCalendar.getInstance();
   c.setLenient(false);
   c.setTime(minDate);
   if (YEAR.equals(intervalType)) {
     c.set(Calendar.MONTH, 0);
     c.set(Calendar.DAY_OF_MONTH, 1);
     c.set(Calendar.HOUR, 0);
     c.set(Calendar.MINUTE, 0);
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (QUARTER.equals(intervalType)) {
     int currentMonth = c.get(Calendar.MONTH);
     int firstMonthYear = columnGroup.getFirstMonthOfYear().getIndex();
     int rest = Quarter.getPositionInQuarter(firstMonthYear, currentMonth + 1);
     c.add(Calendar.MONTH, rest * -1);
     c.set(Calendar.DAY_OF_MONTH, 1);
     c.set(Calendar.HOUR, 0);
     c.set(Calendar.MINUTE, 0);
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (MONTH.equals(intervalType)) {
     c.set(Calendar.DAY_OF_MONTH, 1);
     c.set(Calendar.HOUR, 0);
     c.set(Calendar.MINUTE, 0);
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (DAY.equals(intervalType) || DAY_OF_WEEK.equals(intervalType) || WEEK.equals(intervalType)) {
     c.set(Calendar.HOUR, 0);
     c.set(Calendar.MINUTE, 0);
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (HOUR.equals(intervalType)) {
     c.set(Calendar.MINUTE, 0);
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (MINUTE.equals(intervalType)) {
     c.set(Calendar.SECOND, 0);
     c.set(Calendar.MILLISECOND, 0);
   }
   if (SECOND.equals(intervalType)) {
     c.set(Calendar.MILLISECOND, 0);
   }
   return c;
 }