class EntityUtil {

	public static Date getNextStartTime(Date startTime, Frequency frequency, TimeZone timezone, Date now) {
		if (startTime.after(now))
			return startTime;

		Calendar startCal = Calendar.getInstance(timezone);
		startCal.setTime(startTime);

		int count = 0;
		switch (frequency.getTimeUnit()) {
		case months:
			count = (int) ((now.getTime() - startTime.getTime()) / MONTH_IN_MS);
			break;
		case days:
			count = (int) ((now.getTime() - startTime.getTime()) / DAY_IN_MS);
			break;
		case hours:
			count = (int) ((now.getTime() - startTime.getTime()) / HOUR_IN_MS);
			break;
		case minutes:
			count = (int) ((now.getTime() - startTime.getTime()) / MINUTE_IN_MS);
			break;
		default:
		}

		if (count > 2) {
			startCal.add(frequency.getTimeUnit().getCalendarUnit(), ((count - 2) / frequency.getFrequency()) * frequency.getFrequency());
		}
		while (startCal.getTime().before(now)) {
			startCal.add(frequency.getTimeUnit().getCalendarUnit(), frequency.getFrequency());
		}
		return startCal.getTime();
	}

}