List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:fr.inria.ucn.Helpers.java
/** * /* w w w. j a va 2 s . c o m*/ * @param c * @return -1 if not at night-time (or feature disabled), else milliseconds until morning. */ public static long getNightEnd(Context c) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); if (!prefs.getBoolean(Constants.PREF_STOP_NIGHT, false)) return -1; int nstart = prefs.getInt(Constants.PREF_NIGHT_START, 23 * 3600); int nstop = prefs.getInt(Constants.PREF_NIGHT_STOP, 6 * 3600); Calendar nightstart = Calendar.getInstance(); nightstart.roll(Calendar.HOUR_OF_DAY, -1 * nightstart.get(Calendar.HOUR_OF_DAY)); nightstart.roll(Calendar.MINUTE, -1 * nightstart.get(Calendar.MINUTE)); nightstart.roll(Calendar.SECOND, -1 * nightstart.get(Calendar.SECOND)); nightstart.roll(Calendar.MILLISECOND, -1 * nightstart.get(Calendar.MILLISECOND)); nightstart.add(Calendar.SECOND, nstart); Calendar nightstop = Calendar.getInstance(); nightstop.roll(Calendar.HOUR_OF_DAY, -1 * nightstop.get(Calendar.HOUR_OF_DAY)); nightstop.roll(Calendar.MINUTE, -1 * nightstop.get(Calendar.MINUTE)); nightstop.roll(Calendar.SECOND, -1 * nightstop.get(Calendar.SECOND)); nightstop.roll(Calendar.MILLISECOND, -1 * nightstop.get(Calendar.MILLISECOND)); nightstop.add(Calendar.SECOND, nstop); if (nightstop.before(nightstart)) nightstop.add(Calendar.HOUR, 24); Log.d(Constants.LOGTAG, "nightstart " + nstart + " -> " + nightstart.toString()); Log.d(Constants.LOGTAG, "nightstop " + nstop + " -> " + nightstop.toString()); Calendar now = Calendar.getInstance(); if (now.after(nightstart) && now.before(nightstop)) { return nightstop.getTimeInMillis(); } else { return -1; } }
From source file:org.kuali.kfs.sys.batch.Job.java
/** * Checks if the current jobRunDate is within the cutoff window for the given run date from the RUN_DATE parameter. * The window is defined as midnight of the date specified in the parameter to the RUN_DATE_CUTOFF_TIME of the next day. * //from www . j a va 2 s . c o m * @param jobRunDate the time the job is attempting to start * @param runDateToCheck the current member of the appropriate RUN_DATE to check * @param dateTimeService an instance of the DateTimeService * @return true if jobRunDate is within the current runDateToCheck window, false otherwise */ protected static boolean withinCutoffWindowForDate(Date jobRunDate, Date runDateToCheck, DateTimeService dateTimeService, String[] cutOffWindow) { final Calendar jobRunCalendar = dateTimeService.getCalendar(jobRunDate); final Calendar beginWindow = getCutoffWindowBeginning(runDateToCheck, dateTimeService); final Calendar endWindow = getCutoffWindowEnding(runDateToCheck, dateTimeService, cutOffWindow); return jobRunCalendar.after(beginWindow) && jobRunCalendar.before(endWindow); }
From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java
/** * Applies the config to the given calendar. *//*www .ja va2 s . c om*/ public static Calendar applyConfig(Calendar cal, AstroChannelConfig config) { Calendar cCal = cal; if (config.getOffset() != null && config.getOffset() != 0) { Calendar cOffset = Calendar.getInstance(); cOffset.setTime(cCal.getTime()); cOffset.add(Calendar.MINUTE, config.getOffset()); cCal = cOffset; } Calendar cEarliest = adjustTime(cCal, getMinutesFromTime(config.getEarliest())); if (cCal.before(cEarliest)) { return cEarliest; } Calendar cLatest = adjustTime(cCal, getMinutesFromTime(config.getLatest())); if (cCal.after(cLatest)) { return cLatest; } return cCal; }
From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java
private static int determineDayOfMonth(ScheduleSpec spec, Calendar after, ScheduleCalendar result) { SortedSet<Integer> daysOfMonthSet = spec.getUnitValues().get(ScheduleUnit.DAYS_OF_MONTH); SortedSet<Integer> daysOfWeekSet = spec.getUnitValues().get(ScheduleUnit.DAYS_OF_WEEK); SortedSet<Integer> secondsSet = spec.getUnitValues().get(ScheduleUnit.SECONDS); SortedSet<Integer> minutesSet = spec.getUnitValues().get(ScheduleUnit.MINUTES); SortedSet<Integer> hoursSet = spec.getUnitValues().get(ScheduleUnit.HOURS); int dayOfMonth; // If days of week is a wildcard, just go by days of month if (spec.getOptionalDayOfMonthOperator() != null || spec.getOptionalDayOfWeekOperator() != null) { boolean isWeek = false; CronParameter op = spec.getOptionalDayOfMonthOperator(); if (spec.getOptionalDayOfMonthOperator() == null) { op = spec.getOptionalDayOfWeekOperator(); isWeek = true;//from w w w. ja v a2 s . c om } // may return the current day or a future day in the same month, // and may advance the "after" date to the next month int currentYYMMDD = getTimeYYYYMMDD(after); increaseAfterDayOfMonthSpecialOp(op.getOperator(), op.getDay(), op.getMonth(), isWeek, after); int rolledYYMMDD = getTimeYYYYMMDD(after); // if rolled then reset time portion if (rolledYYMMDD > currentYYMMDD) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); return after.get(Calendar.DAY_OF_MONTH); } // rolling backwards is not allowed else if (rolledYYMMDD < currentYYMMDD) { throw new IllegalStateException( "Failed to evaluate special date op, rolled date less then current date"); } else { Calendar work = (Calendar) after.clone(); work.set(Calendar.SECOND, result.getSecond()); work.set(Calendar.MINUTE, result.getMinute()); work.set(Calendar.HOUR_OF_DAY, result.getHour()); if (!work.after(after)) { // new date is not after current date, so bump after.add(Calendar.DAY_OF_MONTH, 1); result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); increaseAfterDayOfMonthSpecialOp(op.getOperator(), op.getDay(), op.getMonth(), isWeek, after); } return after.get(Calendar.DAY_OF_MONTH); } } else if (daysOfWeekSet == null) { dayOfMonth = nextValue(daysOfMonthSet, after.get(Calendar.DAY_OF_MONTH)); if (dayOfMonth != after.get(Calendar.DAY_OF_MONTH)) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); } if (dayOfMonth == -1) { dayOfMonth = nextValue(daysOfMonthSet, 0); after.add(Calendar.MONTH, 1); } } // If days of weeks is not a wildcard and days of month is a wildcard, go by days of week only else if (daysOfMonthSet == null) { // Loop to find the next day of month that works for the specified day of week values while (true) { dayOfMonth = after.get(Calendar.DAY_OF_MONTH); int dayOfWeek = after.get(Calendar.DAY_OF_WEEK) - 1; // If the day matches neither the day of month nor the day of week if (!daysOfWeekSet.contains(dayOfWeek)) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); after.add(Calendar.DAY_OF_MONTH, 1); } else { break; } } } // Both days of weeks and days of month are not a wildcard else { // Loop to find the next day of month that works for either day of month OR day of week while (true) { dayOfMonth = after.get(Calendar.DAY_OF_MONTH); int dayOfWeek = after.get(Calendar.DAY_OF_WEEK) - 1; // If the day matches neither the day of month nor the day of week if ((!daysOfWeekSet.contains(dayOfWeek)) && (!daysOfMonthSet.contains(dayOfMonth))) { result.setSecond(nextValue(secondsSet, 0)); result.setMinute(nextValue(minutesSet, 0)); result.setHour(nextValue(hoursSet, 0)); after.add(Calendar.DAY_OF_MONTH, 1); } else { break; } } } return dayOfMonth; }
From source file:org.oscarehr.PMmodule.caisi_integrator.CaisiIntegratorManager.java
public static boolean haveAllRemoteFacilitiesSyncedIn(int seconds, boolean useCachedData) throws MalformedURLException { boolean synced = true; Calendar timeConsideredStale = Calendar.getInstance(); timeConsideredStale.add(Calendar.SECOND, -seconds); List<CachedFacility> remoteFacilities = getRemoteFacilities(useCachedData); for (CachedFacility remoteFacility : remoteFacilities) { Calendar lastDataUpdate = remoteFacility.getLastDataUpdate(); if (lastDataUpdate == null || timeConsideredStale.after(lastDataUpdate)) { return false; }/*from ww w . j av a 2 s.c om*/ } return synced; }
From source file:org.kuali.rice.kew.util.Utilities.java
public static boolean checkDateRanges(String fromDate, String toDate) { try {/*from w ww.j av a 2s.c o m*/ Date parsedDate = CoreApiServiceLocator.getDateTimeService().convertToDate(fromDate.trim()); Calendar fromCalendar = Calendar.getInstance(); fromCalendar.setLenient(false); fromCalendar.setTime(parsedDate); fromCalendar.set(Calendar.HOUR_OF_DAY, 0); fromCalendar.set(Calendar.MINUTE, 0); fromCalendar.set(Calendar.SECOND, 0); fromCalendar.set(Calendar.MILLISECOND, 0); parsedDate = CoreApiServiceLocator.getDateTimeService().convertToDate(toDate.trim()); Calendar toCalendar = Calendar.getInstance(); toCalendar.setLenient(false); toCalendar.setTime(parsedDate); toCalendar.set(Calendar.HOUR_OF_DAY, 0); toCalendar.set(Calendar.MINUTE, 0); toCalendar.set(Calendar.SECOND, 0); toCalendar.set(Calendar.MILLISECOND, 0); if (fromCalendar.after(toCalendar)) { return false; } return true; } catch (Exception ex) { return false; } }
From source file:com.joinsystem.goku.common.utils.DateUtil.java
/** * /*from w ww. j ava 2 s . c o m*/ * * @param d1 * @param d2 * @return */ public static int diffDays(Calendar d1, Calendar d2) { if (d1.after(d2)) { java.util.Calendar swap = d1; d1 = d2; d2 = swap; } int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); int y2 = d2.get(Calendar.YEAR); if (d1.get(Calendar.YEAR) != y2) { d1 = (Calendar) d1.clone(); do { days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);// d1.add(Calendar.YEAR, 1); } while (d1.get(Calendar.YEAR) != y2); } return days; }
From source file:org.shengrui.oa.util.UtilDateTime.java
/** * /*from w w w . j av a 2s . co m*/ * @param week * @param startDate * @param endDate * @return; * @author Zhao.Xiang */ public static List<Date> getDatesByWeekInDateRange(String week, Integer count, int weekSeed, Calendar startDate, Calendar endDate) { if (startDate.after(endDate)) { Calendar tmp = startDate; startDate = endDate; endDate = tmp; } List<Date> dates = new ArrayList<Date>(); int ct = 0; int cweekDay = week2int.get(week); int sweekDay = startDate.get(Calendar.DAY_OF_WEEK); //int eweekDay = endDate.get(Calendar.DAY_OF_WEEK); int offset = getIntervalDays(startDate, endDate); if (offset == 0) { if (cweekDay == sweekDay) { } } else { Calendar clop = startDate; int oftday = (clop.get(Calendar.DAY_OF_WEEK) == 1 ? 8 : clop.get(Calendar.DAY_OF_WEEK)) - week2int.get(week); oftday = oftday % 8 > 0 ? Math.abs(oftday - 7) : oftday; // System.out.println(oftday); clop.add(Calendar.DAY_OF_WEEK, Math.abs(oftday)); if (!clop.after(endDate)) { dates.add(clop.getTime()); // System.out.println(toDateString(clop.getTime())); ct++; } //while(ct < count){ while (count != null ? (ct < count) : true) { clop.add(Calendar.DAY_OF_WEEK, weekSeed); if (clop.after(endDate)) { break; } dates.add(clop.getTime()); // System.out.println(toDateString(clop.getTime())); ct++; } } return dates; }
From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java
/** * When we create the historic for a manual practice, this method permit to fill part of the historic corresponding * to the validity of the last mark//from www. j a v a2 s .c o m * * @param beginDate Date of creation of the mark * @param mark The mark * @param todayCal Calendar set on today * @param endValidity Date of end of validity of the mark * @return a map which contains information to display for the historic */ private static Map fillExtensionMap(Date beginDate, float mark, Calendar todayCal, Calendar endValidity) { Map extension = new HashMap<Date, Float>(); extension.put(beginDate, mark); if (endValidity.after(todayCal)) { extension.put(todayCal.getTime(), mark); } else { extension.put(endValidity.getTime(), mark); } return extension; }
From source file:CalendarComparator.java
public int compare(Object x, Object y) { Calendar xcal = (Calendar) x; Calendar ycal = (Calendar) y; if (xcal.before(ycal)) return -1; if (xcal.after(ycal)) return 1; return 0;//from www .ja v a 2s .c o m }