public void adjustDate(Date d) { if (DateIntervalType.MILLENIUM.equals(type)) { d.setYear(d.getYear() + (int) quantity * 1000); } if (DateIntervalType.CENTURY.equals(type)) { d.setYear(d.getYear() + (int) quantity * 100); } if (DateIntervalType.DECADE.equals(type)) { d.setYear(d.getYear() + (int) quantity * 10); } if (DateIntervalType.YEAR.equals(type)) { d.setYear(d.getYear() + (int) quantity); } if (DateIntervalType.QUARTER.equals(type)) { d.setMonth(d.getMonth() + (int) quantity * 3); } if (DateIntervalType.MONTH.equals(type)) { d.setMonth(d.getMonth() + (int) quantity); } if (DateIntervalType.WEEK.equals(type)) { d.setDate(d.getDate() + (int) quantity * 7); } if (DateIntervalType.DAY.equals(type)) { d.setDate(d.getDate() + (int) quantity); } if (DateIntervalType.HOUR.equals(type)) { d.setHours(d.getHours() + (int) quantity); } if (DateIntervalType.MINUTE.equals(type)) { d.setMinutes(d.getMinutes() + (int) quantity); } if (DateIntervalType.SECOND.equals(type)) { d.setSeconds(d.getSeconds() + (int) quantity); } }
protected Date calculateStartTime() { Date startDate = getStartTime(); if (timeMode == null || TimeMode.NOW.equals(timeMode)) { return startDate; } if (DateIntervalType.MILLENIUM.equals(intervalType)) { int base = startDate.getYear() / 1000; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 1000); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.CENTURY.equals(intervalType)) { int base = startDate.getYear() / 100; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 100); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.DECADE.equals(intervalType)) { int base = startDate.getYear() / 10; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 10); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.YEAR.equals(intervalType)) { int month = startDate.getMonth(); int firstMonth = firstMonthOfYear.getIndex() - 1; int yearInc = 0; if (TimeMode.BEGIN.equals(timeMode)) yearInc = month < firstMonth ? -1 : 0; else yearInc = month < firstMonth ? 0 : 1; startDate.setYear(startDate.getYear() + yearInc); startDate.setMonth(firstMonth); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.QUARTER.equals(intervalType)) { int month = startDate.getMonth(); int firstMonth = Quarter.getQuarterFirstMonth(firstMonthOfYear.getIndex(), month + 1) - 1; int yearInc = 0; int monthInc = 3; if (TimeMode.BEGIN.equals(timeMode)) { yearInc = firstMonth > month ? -1 : 0; monthInc = 0; } startDate.setYear(startDate.getYear() + yearInc); startDate.setMonth(firstMonth + monthInc); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.MONTH.equals(intervalType)) { startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setMonth(startDate.getMonth() + 1); } } if (DateIntervalType.DAY.equals(intervalType)) { startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setDate(startDate.getDate() + 1); } } if (DateIntervalType.HOUR.equals(intervalType)) { startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setHours(startDate.getHours() + 1); } } if (DateIntervalType.MINUTE.equals(intervalType)) { startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setMinutes(startDate.getMinutes() + 1); } } return startDate; }