List of usage examples for java.util Calendar compareTo
private int compareTo(long t)
From source file:Main.java
/** * Creates a calendar object with the next absolute time determined by hour and minute * @param hourOfDay/*w w w.j av a 2 s . c o m*/ * @param minute * @return */ public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) { Calendar cal = Calendar.getInstance(); Calendar calNow = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); if (cal.compareTo(calNow) <= 0) { //Today's time passed, count to tomorrow cal.add(Calendar.DATE, 1); } return cal; }
From source file:org.openhab.binding.IEEE1888.trap.TrapManager.java
/** * If there are any updates, data were sened. * * @param itemName//w w w .j a v a2 s. c om * @param newState */ public static void putTrapData(String itemName, State newState) throws ParseException { if (!trapMap.containsKey(itemName)) { // If there is not trap, trap is never processed. return; } TrapInfo trapInfo = trapMap.get(itemName); Value pointValue = trapInfo.getPoint().getValue()[0]; String newValue = newState.toString(); Pattern STATE_CONFIG_PATTERN = Pattern.compile("(.*?)\\=(.*?)\\&(.*?)\\=(.*?)"); // analyze state Matcher matcher = STATE_CONFIG_PATTERN.matcher(newValue); if (matcher.find()) { String[] values = StringUtils.split(newValue, "&"); HashMap<String, String> keyValueMap = new HashMap<>(); for (String value : values) { keyValueMap.put(StringUtils.substringBefore(value, "="), StringUtils.substringAfter(value, "=")); } Calendar timeValue = Calendar.getInstance(); if (StringUtils.isNotBlank(keyValueMap.get("time"))) { Date dateTime = DateUtils.parseDate(keyValueMap.get("time"), TIME_FORMAT); timeValue.setTime(dateTime); } if ((timeValue.compareTo(pointValue.getTime()) == 0) && StringUtils.equals(keyValueMap.get("value"), pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(keyValueMap.get("value")); pointValue.setTime(timeValue); } else { if (StringUtils.equals(newValue, pointValue.getString())) { // If state was not changed, trap is not processed. return; } pointValue.setString(newValue); pointValue.setTime(Calendar.getInstance()); } // send data Map<String, Date> CallbackURLMap = trapInfo.getCallbackURLMap(); CallbackURLMap.keySet().forEach(key -> new Thread(() -> { sendData(key, trapInfo); }).start()); }
From source file:Main.java
public static boolean isCheckChangePermitted(Context context, Calendar date) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String limitActivePref = sharedPrefs.getString("active-date-key", "ALLOW_ALL"); Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); Calendar yesterday;// www . ja va2 s. c o m switch (limitActivePref) { case "ALLOW_CURRENT": return (date.compareTo(today) == 0); case "ALLOW_CURRENT_AND_NEXT_DAY": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_CURRENT_AND_NEXT_DAY_AND_WEEKEND": yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DATE, today.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY ? -2 : -1); return (date.compareTo(yesterday) >= 0); case "ALLOW_ALL": default: return true; } }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
/** * cal2?cal1??//w w w. j ava 2s . co m * * <pre> * * isExpiredForDays(2011-11-4 2011-11-4 ) 0 * isExpiredForDays(2011-11-42011-11-5 ) ?0 * isExpiredForDays(2011-11-52011-11-4 ) 0 * * </pre> */ public static int compareForDays(Calendar cal1, Calendar cal2) { if (isSameDay(cal1, cal2)) { return 0; } return cal1.compareTo(cal2); }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
public static boolean isExpiredForHours(Date date) { if (date == null) { return true; }/* w w w . j ava2 s.c o m*/ Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date); if (cal1.compareTo(cal2) > 0) {// ?? if (isSameDay(cal1, cal2)) {// ?? return false; } else { return true; } } else {// ??? return false; } }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
/** * ??,??//www . j a v a2 s . c o m * * <pre> * ?currentTime > date * ? 2011-11-4 ,isExpiredForDays(2011-11-4 ) false * ? 2011-11-5 ,isExpiredForDays(2011-11-4 ) true * * </pre> * * @param date * ? * @return true ?<code>true</code><code>null</code> * <code>true</code>,<code>false</code> */ public static boolean isExpiredForDays(Date date) { if (date == null) { return true; } Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date); if (cal1.compareTo(cal2) > 0) {// ?? if (isSameDay(cal1, cal2)) {// ?? return false; } else { return true; } } else {// ??? return false; } }
From source file:com.evozon.evoportal.my_account.util.MyAccountUtil.java
public static boolean hasPMReportsDataModified(AccountModelHolder oldModel, AccountModelHolder newModel) { DetailsManager detailsManager = new DetailsManager(oldModel.getDetailsModel(), newModel.getDetailsModel()); if (detailsManager.isEmailAddressChanged()) { return true; }// w w w . ja v a 2 s . c o m if (detailsManager.isLastNameChanged()) { return true; } if (detailsManager.isFirstNameChanged()) { return true; } if (detailsManager.isLicensePlateChanged()) { return true; } if (detailsManager.isPhoneNumberChanged()) { return true; } Calendar oldStartDate = resetToMidnight(oldModel.getFreeDaysModel().getStartDate()); Calendar newStartDate = resetToMidnight(newModel.getFreeDaysModel().getStartDate()); if (oldStartDate.compareTo(newStartDate) != 0) { return true; } EvoAddressModel oldPrimaryAddress = oldModel.getPrimaryAddress(); EvoAddressModel newPrimaryAddress = newModel.getPrimaryAddress(); if ((oldPrimaryAddress == null) && (newPrimaryAddress == null)) { return false; } else if ((oldPrimaryAddress != null) && (newPrimaryAddress == null)) { return true; } else if ((oldPrimaryAddress == null) && (newPrimaryAddress != null)) { return true; } EvoAddressManager addressManager = new EvoAddressManager(oldPrimaryAddress, newPrimaryAddress); if (addressManager.isStreetNameChanged()) { return true; } if (addressManager.isStreetNumberChanged()) { return true; } if (addressManager.isCityChanged()) { return true; } if (addressManager.isCountryCodeChanged()) { return true; } return false; }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
public static boolean _isExpiredForDays(Date date, int before) { if (date == null) { return true; }/*from w w w . j a v a 2s. co m*/ Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal2.setTime(DateUtils.addDays(date, -before)); if (cal1.compareTo(cal2) > 0) {// ?? if (isSameHour(cal1, cal2)) {// ??? return false; } else { return true; } } else {// ??? return false; } }
From source file:de.joinout.criztovyl.tools.files.FileList.java
/** * Calculates the newer of both {@link FileList}s. * @param a one {@link FileList}//from w ww . j a v a2s . co m * @param b another {@link FileList} * @return the newer {@link FileList} or <code>null</code> if one {@link FileList#getLastListDate()} is <code>null</code>. */ public static FileList getNewerFileList(FileList a, FileList b) { //Receive Calendars final Calendar aCal = a.getLastListDate(); final Calendar bCal = b.getLastListDate(); // Return if age is equal or one calendar is null if (aCal.compareTo(bCal) == 0 || aCal == null || bCal == null) return null; // Detect and return newer directory return aCal.compareTo(bCal) > 0 ? a : b; }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static boolean firstLessOrEqualSecond(Date firstDate, Date secondDate) { Calendar firstCalendarDate = Calendar.getInstance(); firstCalendarDate.setTime(firstDate); Calendar secondCalendarDate = Calendar.getInstance(); secondCalendarDate.setTime(secondDate); firstCalendarDate.set(Calendar.DAY_OF_MONTH, 1); return firstCalendarDate.compareTo(secondCalendarDate) <= 0; }