Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

In this page you can find the example usage for java.util Date before.

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:com.gst.infrastructure.entityaccess.service.FineractEntityAccessWriteServiceImpl.java

@Override
@Transactional// w w w  .  jav a  2s  . c  o m
public CommandProcessingResult createEntityToEntityMapping(Long relId, JsonCommand command) {

    try {

        this.fromApiJsonDeserializer.validateForCreate(command.json());

        final FineractEntityRelation mapId = this.fineractEntityRelationRepositoryWrapper
                .findOneWithNotFoundDetection(relId);

        final Long fromId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.fromEnityType);
        final Long toId = command.longValueOfParameterNamed(FineractEntityApiResourceConstants.toEntityType);
        final Date startDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.startDate);
        final Date endDate = command.DateValueOfParameterNamed(FineractEntityApiResourceConstants.endDate);

        fromApiJsonDeserializer.checkForEntity(relId.toString(), fromId, toId);
        if (startDate != null && endDate != null) {
            if (endDate.before(startDate)) {
                throw new FineractEntityToEntityMappingDateException(startDate.toString(), endDate.toString());
            }
        }

        final FineractEntityToEntityMapping newMap = FineractEntityToEntityMapping.newMap(mapId, fromId, toId,
                startDate, endDate);

        this.fineractEntityToEntityMappingRepository.save(newMap);

        return new CommandProcessingResultBuilder().withEntityId(newMap.getId())
                .withCommandId(command.commandId()).build();
    } catch (final DataIntegrityViolationException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:gov.nih.nci.firebird.service.periodic.DailyJobServiceBeanTest.java

private Date getExpectedTimerInitialDate() {
    Date expectedDate = new Date();
    expectedDate = DateUtils.setHours(expectedDate, 3);
    expectedDate = DateUtils.setMinutes(expectedDate, 0);
    expectedDate = DateUtils.setSeconds(expectedDate, 0);
    expectedDate = DateUtils.setMilliseconds(expectedDate, 0);
    if (expectedDate.before(new Date())) {
        expectedDate = DateUtils.addDays(expectedDate, 1);
    }//from   w w w  .  j  a va  2  s.  c o m
    return expectedDate;
}

From source file:org.jasig.schedassist.impl.SchedulingAssistantServiceImpl.java

@Override
public List<AvailableBlock> calculateVisitorConflicts(IScheduleVisitor visitor, IScheduleOwner owner,
        Date start, Date end) {

    Date[] windowBoundaries = calculateOwnerWindowBounds(owner);

    Date localStart = start;/*from   w ww  . j av a  2  s  . c o m*/
    if (start.before(windowBoundaries[0])) {
        localStart = windowBoundaries[0];
    }
    Date localEnd = end;
    if (end.after(windowBoundaries[1])) {
        localEnd = windowBoundaries[1];
    }

    AvailableSchedule availableSchedule = this.availableScheduleDao.retrieve(owner, localStart, localEnd);

    // get the VISITOR's Calendar data
    Calendar calendar = calendarDao.getCalendar(visitor.getCalendarAccount(), localStart, localEnd);

    // calculate a VisibleSchedule using the owner's availability but the Visitor's calendar data
    VisibleSchedule result = this.visibleScheduleBuilder.calculateVisitorConflicts(
            availableSchedule.getScheduleStartTime(), availableSchedule.getScheduleEndTime(), calendar,
            availableSchedule, owner.getPreferredMeetingDurations(), visitor);
    // return only the conflicts (the busy list)
    List<AvailableBlock> visitorConflicts = result.getBusyList();
    return visitorConflicts;
}

From source file:com.discovery.darchrow.date.DateUtil.java

/**
 * ??./*from  w ww .  j  a v a  2s. c  o  m*/
 * 
 * <pre>
 *  :2012-10-16 23:00:02
 * 
 * isInTime(date, "2012-10-10 22:59:00", "2012-10-18 22:59:00")
 * 
 * return true
 * </pre>
 * 
 * @param date
 *            ?
 * @param beginTimeDate
 *            the begin time date
 * @param endTimeDate
 *            the end time date
 * @return {@code  date after beginTimeDate&&?before endTimeDate,true}
 * @see Date#after(Date)
 * @see Date#before(Date)
 */
public static boolean isInTime(Date date, Date beginTimeDate, Date endTimeDate) {
    return date.after(beginTimeDate) && date.before(endTimeDate);
}

From source file:logdruid.data.MineResult.java

public File getFileForDate(Date date) {
    Iterator<Object[]> it = fileDates.iterator();
    while (it.hasNext()) {
        Object[] obj = it.next();
        if (logger.isDebugEnabled())
            logger.debug(/* w  ww  .ja v a  2 s  . c o  m*/
                    "1: " + (Date) obj[0] + "2: " + (Date) obj[1] + "3: " + ((FileRecord) obj[2]).getFile());
        if (date.after((Date) obj[0]) && date.before((Date) obj[1]))
            return (File) ((FileRecord) obj[2]).getFile();
    }
    return null;
}

From source file:SessionExpirationFilter.java

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest hReq = (HttpServletRequest) req;

    HttpSession session = hReq.getSession(false);
    if (null != session) {
        Date expirationDate = (Date) session.getAttribute("expirationDate");

        if (expirationDate == null)
            expirationDate = new Date(System.currentTimeMillis() + 1000000); // only
        // for/*from  w w  w.  j  a v a 2 s  .  c o  m*/
        // make
        // false
        // "expirationDate.before(new Date())"
        // in
        // the
        // first
        // execution

        if (expirationDate.before(new Date())) {
            session.invalidate();
            session = null;
        } else {
            // ignore requests marked as both ajaxCall and ignoreForSessionTimeout
            String isAjaxCall = hReq.getParameter("IsAjaxCall");
            String ignoreForSessionTimeout = hReq.getParameter("ignoreForSessionTimeout");
            boolean ignoreForTimeout = "1".equals(isAjaxCall) && ("1".equals(ignoreForSessionTimeout));
            if (ignoreForTimeout) {
                // Do nothing; don't update the session timestamp
            } else {
                session.setAttribute("expirationDate",
                        new Date(System.currentTimeMillis() + session.getMaxInactiveInterval() * 1000));
            }
        }
    }
    chain.doFilter(req, resp);
}

From source file:org.esupportail.dining.web.feed.DiningFeed.java

public boolean isClosed(Restaurant r) {

    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

    Date reopenningDate = new Date(0);
    Date todayDate = new Date();

    try {//  w ww  .  j  a v  a  2s. c om
        reopenningDate = sf.parse(r.getClosing());
    } catch (ParseException e) {
        e.printStackTrace();
    }

    if (todayDate.before(reopenningDate)) {
        return true;
    }

    return false;
}

From source file:com.andco.salasucc.bean.nuevaBean.java

public List<Date> generaFechasRecurrentes(Date fechaInicio, Date fechaFin) {
    List<Date> listaFechas = new ArrayList<>();
    Calendar c = Calendar.getInstance();
    while (fechaInicio.before(fechaFin)) {
        c.setTime(fechaInicio);//from ww  w .j  a va 2  s .  c o m
        listaFechas.add(c.getTime());
        c.add(Calendar.DATE, 7);
        fechaInicio = c.getTime();
    }
    return listaFechas;
}

From source file:com.mobileman.projecth.business.impl.PatientMedicationServiceImpl.java

/** 
 * {@inheritDoc}/*  w w w . j  a  v  a  2s  .com*/
 * @see com.mobileman.projecth.business.PatientMedicationService#addConsumedMedication(java.lang.Long, java.lang.Long, java.lang.Long, double, com.mobileman.projecth.domain.util.medication.MedicationFrequency, java.util.Date, java.util.Date, java.lang.String)
 */
@Override
public void addConsumedMedication(Long patientId, Long diseaseId, Long medicationId, double standarUnitsTaken,
        MedicationFrequency frequency, Date startDate, Date endDate, String comment)
        throws IllegalArgumentException {
    if (log.isDebugEnabled()) {
        log.debug("addConsumedMedication(" + patientId + ", " + diseaseId + ", " + medicationId + ", "
                + standarUnitsTaken + ", " + frequency + ", " + startDate + ", " + endDate + ") - start"); //$NON-NLS-1$
    }

    if (patientId == null) {
        throw new IllegalArgumentException("patientId must not be null");
    }

    if (diseaseId == null) {
        throw new IllegalArgumentException("diseaseId must not be null");
    }

    if (medicationId == null) {
        throw new IllegalArgumentException("medicationId must not be null");
    }

    if (standarUnitsTaken <= 0.0d) {
        throw new IllegalArgumentException("standarUnitsTaken must not be zero or negative value");
    }

    if (frequency == null) {
        throw new IllegalArgumentException("frequency must not be null");
    }

    if (endDate == null) {
        endDate = startDate;
    }

    Patient patient = patientDao.findById(patientId);
    patient.setLastUpdate(new Date());
    Medication medication = medicationDao.findById(medicationId);
    Disease disease = diseaseDao.findById(diseaseId);

    Date date = startDate;
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(startDate);
    Date timestamp = new Date();
    while (date.before(endDate) || date.equals(endDate)) {
        PatientMedication patientMedication = new PatientMedication();
        patientMedication.setTimestamp(timestamp);
        patientMedication.setPatient(patient);
        patientMedication.setMedication(medication);
        patientMedication.setComment(comment);
        patientMedication.setConsumptionDate(date);
        patientMedication.setDisease(disease);
        patientMedication.setAmount(new BigDecimal(standarUnitsTaken));
        patientMedicationDao.save(patientMedication);

        if (frequency.equals(MedicationFrequency.ONE_TIME)) {
            break;
        }

        switch (frequency) {
        case DAILY:
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            break;
        case WEEKLY:
            calendar.add(Calendar.WEEK_OF_YEAR, 1);
            break;
        case BI_WEEKLY:
            calendar.add(Calendar.WEEK_OF_YEAR, 2);
            break;
        default:
            break;
        }

        date = calendar.getTime();
    }

    if (log.isDebugEnabled()) {
        log.debug("addConsumedMedication(Long, Long, Long, double) - returns"); //$NON-NLS-1$
    }
}