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:com.epam.training.storefront.forms.validation.SbgSopPaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final SopPaymentDetailsForm form = (SopPaymentDetailsForm) object; final Calendar start = parseDate(form.getStartMonth(), form.getStartYear()); final Calendar expiration = parseDate(form.getExpiryMonth(), form.getExpiryYear()); final Calendar current = Calendar.getInstance(); if (start != null) { if (start.after(current)) { errors.rejectValue("startMonth", "payment.startDate.past.invalid"); }//from w ww.j a v a 2 s . c o m if (expiration != null) { if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } } if (expiration != null) { if (expiration.before(current)) { errors.rejectValue("expiryMonth", "payment.expiryDate.future.invalid"); } } if (Boolean.TRUE.equals(form.getNewBillingAddress())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.titleCode", "address.title.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity", "address.townCity.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode", "address.postcode.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso", "address.country.invalid"); } }
From source file:com.sean.takeastand.storage.ScheduleEditor.java
private boolean setRepeatingAlarmNow(String startTime, String endTime) { //Set repeating alarm if in between start and end time Calendar rightNow = Calendar.getInstance(); Calendar startTimeDate = Utils.convertToCalendarTime(startTime, mContext); Calendar endTimeDate = Utils.convertToCalendarTime(endTime, mContext); if (startTimeDate.before(rightNow) && endTimeDate.after(rightNow)) { Log.i(TAG, "New alarm is within current day's timeframe. Starting RepeatingAlarm."); return true; } else {//from w w w . j av a 2 s . c om Log.i(TAG, "New alarm's repeating timeframe has either not begun or has already passed."); return false; } }
From source file:org.apache.archiva.redback.policy.DefaultUserSecurityPolicy.java
public void extensionPasswordExpiration(User user) throws MustChangePasswordException { if (passwordExpirationEnabled && !getUnlockableAccounts().contains(user.getUsername())) { Calendar expirationDate = Calendar.getInstance(); expirationDate.setTime(user.getLastPasswordChange()); expirationDate.add(Calendar.DAY_OF_MONTH, passwordExpirationDays); Calendar now = Calendar.getInstance(); if (now.after(expirationDate)) { log.info("User '{}' flagged for password expiry (expired on: {})", user.getUsername(), expirationDate);/* w w w. ja v a 2 s .co m*/ user.setPasswordChangeRequired(true); throw new MustChangePasswordException("Password Expired, You must change your password.", user); } } }
From source file:com.sean.takeastand.storage.ScheduleEditor.java
private Calendar nextAlarmTime(String time) { Calendar alarmTime = Utils.convertToCalendarTime(time, mContext); Calendar rightNow = Calendar.getInstance(); if (alarmTime.after(rightNow)) { return alarmTime; } else {//www . j av a 2 s.com //Alarm time was earlier today alarmTime.add(Calendar.DATE, 1); return alarmTime; } }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Returns a date code corresponding to a calendar roll of one month * @param dateStart The date start/* ww w . j a v a2 s .c om*/ * @param dateEnd The date end * @param arrayExcludedDays list of excluded days * @return A date code incremented with strDateRef parameter */ public static int getOccurrenceWithinTwoDates(Date dateStart, Date dateEnd, String[] arrayExcludedDays) { int cptDate = 0; Calendar calendar1 = new GregorianCalendar(); Calendar calendar2 = new GregorianCalendar(); calendar1.setTime(dateStart); calendar2.setTime(dateEnd); if (calendar1.equals(calendar2)) { String strDate = getDate(dateStart); if (isDayExcluded(getDayOfWeek(strDate), arrayExcludedDays)) { return cptDate; } return ++cptDate; } while (!calendar1.after(calendar2)) { if (!isDayExcluded(calendar1.get(Calendar.DAY_OF_WEEK), arrayExcludedDays)) { ++cptDate; } calendar1.add(Calendar.DATE, 1); } return cptDate; }
From source file:co.mafiagame.engine.util.PurgeTimer.java
@Override public void run() { Calendar twoDayAgo = Calendar.getInstance(); twoDayAgo.add(Calendar.DATE, -2); Calendar oneDayAgo = Calendar.getInstance(); oneDayAgo.add(Calendar.DATE, -1); gameContainer.getGames().forEach(game -> { Calendar gameLastUpdate = Calendar.getInstance(); gameLastUpdate.setTime(game.getLastUpdate()); if (twoDayAgo.after(gameLastUpdate)) commandExecutor.run(game.getInterfaceContext(), Constants.CMD.Internal.PURGE, new EmptyContext(game.getInterfaceContext(), game)); else if (oneDayAgo.after(gameLastUpdate)) commandExecutor.run(game.getInterfaceContext(), Constants.CMD.Internal.PURGE_ALARM, new EmptyContext(game.getInterfaceContext(), game)); });//from w w w . j ava 2s . c o m }
From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java
/** * Updates security's history with quote data if: * <li>security's history is not empty * <li>quote's date is one day after the last history bar * <li>current time is after the end of the financial day as per the security's end date. * // www . j av a 2 s. com * @param security * @param quote */ protected void updateHistory(Security security, Quote quote) { // update only if quote's date is the last history date + 1, and the current time is later than the end time in security settings History history = security.getHistory(); if (quote.getDate() != null && (!history.isEmpty())) { Calendar quoteCalendar = Calendar.getInstance(); quoteCalendar.setTime(quote.getDate()); quoteCalendar = new GregorianCalendar(quoteCalendar.get(Calendar.YEAR), quoteCalendar.get(Calendar.MONTH), quoteCalendar.get(Calendar.DAY_OF_MONTH)); Bar lastBar = history.get(history.size() - 1); Calendar lastBarDate = Calendar.getInstance(); lastBarDate.setTime(lastBar.getDate()); Calendar securityEndTime = Calendar.getInstance(); securityEndTime.setTime(quote.getDate()); securityEndTime.set(Calendar.HOUR_OF_DAY, security.getEndTime() / 60); securityEndTime.set(Calendar.MINUTE, security.getEndTime() % 60); securityEndTime.set(Calendar.SECOND, 0); securityEndTime.set(Calendar.MILLISECOND, 0); Calendar today = Calendar.getInstance(); if (quoteCalendar.getTime().after(lastBarDate.getTime()) && today.after(securityEndTime)) { Bar bar = new Bar(); bar.setDate(quoteCalendar.getTime()); bar.setOpen(security.getOpen().doubleValue()); bar.setHigh(security.getHigh().doubleValue()); bar.setLow(security.getLow().doubleValue()); bar.setClose(quote.getLast()); bar.setVolume(quote.getVolume()); history.add(bar); CorePlugin.getRepository().save(history); } } }
From source file:org.opencms.ade.publish.CmsPublishGroupHelper.java
/** * Gets the difference in days between to dates given as longs.<p> * /* w w w . j av a 2 s.co m*/ * The first date must be later than the second date. * * @param first the first date * @param second the second date * * @return the difference between the two dates in days */ public int getDayDifference(long first, long second) { if (first < second) { throw new IllegalArgumentException(); } Calendar firstDay = getStartOfDay(first); Calendar secondDay = getStartOfDay(second); int result = 0; while (firstDay.after(secondDay)) { firstDay.add(Calendar.DAY_OF_MONTH, -1); result += 1; } return result; }
From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.TracksUpdater.java
private boolean trackArtworkUpdated(TracksStore.Track track, ImageUtilities.ExpiringBitmap expiring) { expiring.lastModified = null;//from ww w .j a va 2s . c o m final HttpGet get = new HttpGet(track.getmArtworkUrl()); HttpEntity entity = null; try { final HttpResponse response = HttpManager.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); final Header header = response.getFirstHeader("Last-Modified"); if (header != null) { final Calendar calendar = GregorianCalendar.getInstance(); try { calendar.setTime(mLastModifiedFormat.parse(header.getValue())); expiring.lastModified = calendar; return calendar.after(track.getmLastModified()); } catch (ParseException e) { return false; } } } } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + track, e); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + track, e); } } } return false; }
From source file:org.openmrs.module.clinicalsummary.rule.util.ZScoreUtils.java
/** * Calculate the z-score value based on the stored values of the WHO standard * * @param patient the patient//w ww . j a v a 2s. c om * @param asOfDate the reference point for the z-score calculation * @param weight the weight of the patient * @return the calculated z-score */ public static Double calculateZScore(final Patient patient, final Date asOfDate, final Double weight) { Double zScore = null; Date birthDate = patient.getBirthdate(); // apparently there are records with null birth date if (birthDate != null) { Calendar birthCalendar = Calendar.getInstance(); birthCalendar.setTime(birthDate); birthCalendar.add(Calendar.YEAR, 5); Date fiveYars = birthCalendar.getTime(); Calendar todayCalendar = Calendar.getInstance(); todayCalendar.setTime(asOfDate); // only do processing for kids younger than 5 years old if (fiveYars.after(todayCalendar.getTime())) { // decide the gender. // our database contains both F or Female and M or Male Gender gender = null; if (StringUtils.equalsIgnoreCase(MALE_LONG_STRING, patient.getGender()) || StringUtils.equalsIgnoreCase(MALE_SHORT_STRING, patient.getGender())) gender = Gender.GENDER_MALE; else if (StringUtils.equalsIgnoreCase(FEMALE_LONG_STRING, patient.getGender()) || StringUtils.equalsIgnoreCase(FEMALE_SHORT_STRING, patient.getGender())) gender = Gender.GENDER_FEMALE; birthCalendar.setTime(birthDate); birthCalendar.add(Calendar.WEEK_OF_YEAR, 13); WeightStandard standard; UtilService utilService = Context.getService(UtilService.class); if (todayCalendar.after(birthCalendar)) { Integer ageInMonth = calculateAgeInMonth(patient.getBirthdate(), asOfDate); standard = utilService.getWeightStandard(gender, AgeUnit.UNIT_MONTH, ageInMonth); } else { Integer ageInWeek = calculateAgeInWeek(patient.getBirthdate(), asOfDate); standard = utilService.getWeightStandard(gender, AgeUnit.UNIT_WEEK, ageInWeek); } if (standard != null) zScore = zScore(standard.getCurve(), standard.getMean(), standard.getCoef(), weight); } if (log.isDebugEnabled()) log.debug("Patient: " + patient.getPatientId() + ", zscore: " + zScore); } return zScore; }