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:jp.terasoluna.fw.util.DateUtil.java

/**
 * ?????//from  ww  w .j  a  v a  2s  .  co  m
 *
 * @param date 
 * @return 
 */
public static int getWarekiYear(Date date) {
    for (int i = GENGO_BEGIN_DATES.length - 1; i >= 0; i--) {
        if (!date.before(GENGO_BEGIN_DATES[i])) {
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(date);
            int year = calendar.get(Calendar.YEAR);

            return year - GENGO_BEGIN_YEARS[i] + 1;
        }
    }
    throw new IllegalArgumentException("Wareki Gengo not found for " + date);
}

From source file:net.kamhon.ieagle.util.DateUtil.java

/**
 * consider time and date./*from w  w  w .j  av  a 2  s.  c o m*/
 * 
 * @param date
 * @param startDate
 * @param endDate
 * @return
 */
public static boolean isBetweenDateTime(Date date, Date startDate, Date endDate) {
    return (date.equals(startDate) || date.after(startDate)) && (date.equals(endDate) || date.before(endDate));
}

From source file:DateUtils.java

/** 
 * Returns the minimum of two dates. A null date is treated as being greater
 * than any non-null date. /*from   w  w  w . j  a  v a  2 s. c om*/
 */
public static Date min(Date d1, Date d2) {
    if (d1 == null && d2 == null)
        return null;
    if (d1 == null)
        return d2;
    if (d2 == null)
        return d1;
    return (d1.before(d2)) ? d1 : d2;
}

From source file:edu.sjsu.cmpe275.project.util.HtmlPageComposor.java

public static String orderReceipt(Reservation reservation) {
    //TODO: discount + total fee
    String bill = "";
    int total = 0;

    SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/YYYY");
    Date date = reservation.getCheckinDate();
    bill = "<table border='1' style='width:100%'>";
    bill += "<tr>";
    bill += "<th>Date</th>";
    bill += "<th>Room No</th>";
    bill += "<th>Base Price</th>";
    bill += "<th>Discount(%)</th>";
    bill += "<th>Final Fee</th>";
    bill += "</tr>";
    while (date.before(reservation.getCheckoutDate())) {

        for (Room room : reservation.getRoomList()) {
            bill += "<tr>";
            bill += "<td>" + sdf.format(date) + "</td>";
            bill += "<td>" + room.getRoomNo() + "</td>";
            bill += "<td>" + room.getBasePrice() + "</td>";
            bill += "<td>" + reservation.getDiscount() + "</td>";
            int fee = room.getBasePrice() * (100 - reservation.getDiscount()) / 100;
            total += fee;//from   w  ww .  j  a  v  a  2s. c  om
            bill += "<td>" + fee + "</td>";
            bill += "</tr>";
        }
        //increase one day
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DATE, 1);
        date = c.getTime();
    }
    bill += "</table>";
    bill += "<h3 align='right'>Total($): " + total + "</h3>";

    String page = "<html><body>" + "<h3>Dear " + reservation.getName().getFname() + ",</h3>"
            + "<h3>Thank you for choosing us serving you! Your room(s) have been checked out.</h3>"
            + "<h3>Here is the detail of bill:</h3>" + bill + "<h3>Regards,</h3>"
            + "<h3>CMPE275 Mini Hotel Team</h3>" + "</body></html>";
    return page;
}

From source file:org.callistasoftware.netcare.core.api.impl.ScheduledActivityImpl.java

public static ScheduledActivity newFromEntity(ScheduledActivityEntity entity) {
    ScheduledActivityImpl scheduledActivity = new ScheduledActivityImpl();

    scheduledActivity.healthPlanName = entity.getActivityDefinitionEntity().getHealthPlan().getName();

    scheduledActivity.id = entity.getId();
    scheduledActivity.activityDefinition = ActivityDefinitionImpl
            .newFromEntity(entity.getActivityDefinitionEntity());

    Calendar cal = Calendar.getInstance();
    cal.setTime(entity.getScheduledTime());
    int day = cal.get(Calendar.DAY_OF_WEEK);
    scheduledActivity.day = new Option("weekday." + day, LocaleContextHolder.getLocale());

    cal.setTime(new Date());
    ApiUtil.dayBegin(cal);//from  w w w  .ja v  a  2 s .  c  o m
    Date time = entity.getScheduledTime();

    scheduledActivity.due = (time.compareTo(cal.getTime()) < 0);
    scheduledActivity.date = ApiUtil.formatDate(time);

    scheduledActivity.time = ApiUtil.formatTime(time);

    if (entity.getReportedTime() != null) {

        Calendar reportedCal = Calendar.getInstance();
        reportedCal.setTime(entity.getReportedTime());

        int repDay = reportedCal.get(Calendar.DAY_OF_WEEK);

        Date reportedTime = entity.getReportedTime();
        scheduledActivity.reportedDay = new Option("weekday." + repDay, LocaleContextHolder.getLocale());
        scheduledActivity.reportedDate = ApiUtil.formatDate(reportedTime);
        scheduledActivity.reportedTime = ApiUtil.formatTime(reportedTime);
        scheduledActivity.reported = new StringBuilder(scheduledActivity.reportedDate).append(" ")
                .append(scheduledActivity.reportedTime).toString();

        final Calendar act = Calendar.getInstance();
        act.setTime(entity.getActualTime());

        int actWeekday = act.get(Calendar.DAY_OF_WEEK);
        scheduledActivity.actDay = new Option("weekday." + actWeekday, LocaleContextHolder.getLocale());
        scheduledActivity.actDate = ApiUtil.formatDate(entity.getActualTime());
        scheduledActivity.actTime = ApiUtil.formatTime(entity.getActualTime());

    }
    if (entity.getActualTime() != null) {
        scheduledActivity.actualTime = ApiUtil.formatDate(entity.getActualTime()) + " "
                + ApiUtil.formatTime(entity.getActualTime());
    }

    // Scheduled time within one week?
    final Date oneWeek = new DateTime(System.currentTimeMillis()).plusWeeks(1).toDate();
    final Date scheduled = entity.getScheduledTime();

    if (scheduled.before(oneWeek) && entity.getReportedTime() == null) {
        scheduledActivity.setReportingPossible(true);
    } else {
        scheduledActivity.setReportingPossible(false);
    }

    scheduledActivity.setExtra(entity.isExtra());

    List<ActivityItemValuesEntity> activityEntities = entity.getActivities();
    scheduledActivity.activityItemValues = new ActivityItemValues[activityEntities.size()];
    for (int i = 0; i < scheduledActivity.activityItemValues.length; i++) {
        ActivityItemValuesEntity activityItemValuesEntity = activityEntities.get(i);
        if (activityItemValuesEntity instanceof MeasurementEntity) {
            scheduledActivity.activityItemValues[i] = MeasurementImpl
                    .newFromEntity((MeasurementEntity) activityItemValuesEntity);
        } else if (activityItemValuesEntity instanceof EstimationEntity) {
            scheduledActivity.activityItemValues[i] = EstimationImpl
                    .newFromEntity((EstimationEntity) activityItemValuesEntity);
        } else if (activityItemValuesEntity instanceof YesNoEntity) {
            scheduledActivity.activityItemValues[i] = YesNoImpl
                    .newFromEntity((YesNoEntity) activityItemValuesEntity);
        } else if (activityItemValuesEntity instanceof TextEntity) {
            scheduledActivity.activityItemValues[i] = TextImpl
                    .newFromEntity((TextEntity) activityItemValuesEntity);
        }
    }
    scheduledActivity.rejected = entity.isRejected();
    scheduledActivity.patient = PatientBaseViewImpl
            .newFromEntity(entity.getActivityDefinitionEntity().getHealthPlan().getForPatient());
    scheduledActivity.note = entity.getNote();

    scheduledActivity.comments = new ActivityComment[entity.getComments().size()];
    for (int i = 0; i < entity.getComments().size(); i++) {
        scheduledActivity.comments[i] = ActivityCommentImpl.newFromEntity(entity.getComments().get(i));
    }

    return scheduledActivity;
}

From source file:com.adobe.sign.utils.validator.ApiValidatorHelper.java

/**
 * Helper function to validate the dates passed to it.
 *
 * @param startDate The start date of search that needs to be validated.
 * @param endDate   The end date of search that needs to be validated.
 * @throws ApiException//from  w  ww . j  a  v  a 2 s. c  o m
 */
public static void validateStartAndEndDatesParameter(Date startDate, Date endDate) throws ApiException {
    validateParameter(startDate, SdkErrorCodes.INVALID_DATE);
    validateParameter(endDate, SdkErrorCodes.INVALID_DATE);

    if (endDate.before(startDate))
        throw new ApiException(SdkErrorCodes.INVALID_DATE);
}

From source file:com.projity.server.data.mspdi.ModifiedMSPDIReader.java

private static boolean CombineTimephasedDataIfOnSameDay(TimephasedDataType original,
        TimephasedDataType newData) {/*from w  ww .j  a v a  2s  . co  m*/
    boolean dataCombined = false;
    Date newStart = newData.getStart().getTime();
    Date newFinish = newData.getFinish().getTime();
    Date originalStart = original.getStart().getTime();
    Date originalFinish = original.getFinish().getTime();
    if (newStart.after(originalStart) && newFinish.before(originalFinish)) {
        long sumValue = XsdDuration.millis(original.getValue()) + XsdDuration.millis(newData.getValue());
        Duration combined = Duration.getInstance(sumValue / WorkCalendar.MILLIS_IN_MINUTE, TimeUnit.MINUTES);
        original.setValue(new XsdDuration(combined).toString());
        dataCombined = true;
    }

    return dataCombined;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.QcliveAbstractBaseIntegrationTest.java

/**
 * Checks that the last modified date of the given file is on or after the test start date
 *
 * @param file the file//from  ww w. j a  va  2s  .  c  o  m
 */
protected static void checkLastModified(final File file) {
    logger.info(" checkLastModified - IN");
    final Date lastModifiedDate = new Date(file.lastModified());
    assertFalse(lastModifiedDate.before(testStartDate));
    logger.info(" checkLastModified - OUT");
}

From source file:com.cisco.step.jenkins.plugins.jenkow.WfUtil.java

static void deployAllToEngine() {
    File repoDir = JenkowWorkflowRepository.getRepositoryDir();
    if (!repoDir.exists()) {
        LOGGER.info("no workflow source repository");
        return;//from   w w  w .java2 s . com
    }

    LOGGER.info("deploying all workflow engine");

    RepositoryService repoSvc = JenkowEngine.getEngine().getRepositoryService();
    Map<String, Date> deplTimes = new HashMap<String, Date>();
    for (Deployment depl : repoSvc.createDeploymentQuery().list()) {
        //System.out.println("  depl: id="+depl.getId()+" name="+depl.getName()+" time="+depl.getDeploymentTime());
        deplTimes.put(depl.getId(), depl.getDeploymentTime());
    }
    Map<String, Date> pDefTimes = new HashMap<String, Date>();
    for (ProcessDefinition pDef : repoSvc.createProcessDefinitionQuery().latestVersion().list()) {
        //System.out.println(" pDef:"+pDef+" deplId="+pDef.getDeploymentId()+" key="+pDef.getKey());
        Date t = deplTimes.get(pDef.getDeploymentId());
        if (t != null)
            pDefTimes.put(pDef.getKey(), t);
    }

    for (Iterator it = FileUtils.iterateFiles(repoDir, new String[] { Consts.WORKFLOW_EXT },
            /*recursive=*/true); it.hasNext();) {
        File wff = (File) it.next();
        String wfn = wff.getName();
        int p = wfn.lastIndexOf('.');
        if (p > -1)
            wfn = wfn.substring(0, p);
        Date prevDeplTime = pDefTimes.get(wfn);
        //System.out.println("  f="+wff+" wfn="+wfn+" deplTime="+prevDeplTime+" wff.lastModified="+new Date(wff.lastModified()));
        if (prevDeplTime == null || prevDeplTime.before(new Date(wff.lastModified()))) {
            try {
                WfUtil.deployToEngine(wff);
            } catch (FileNotFoundException e) {
                LOGGER.log(Level.SEVERE, "file not found " + wff, e);
            }
        }
    }
}

From source file:br.com.nordestefomento.jrimum.utilix.BancoUtil.java

/**
 * <p>/*from w  w w .ja v a2 s .co m*/
 * Calcula o fator de vencimento a partir da subtrao entre a DATA DE
 * VENCIMENTO de um ttulo e a DATA BASE fixada em 07/10/1997.
 * </p>
 * 
 * <p>
 * O fator de vencimento nada mais  que um referencial numrico de 4
 * dgitos que representa a quantidade de dias decorridos desde a data base
 * (07/10/1997) at a data de vencimento do ttulo. Ou seja, a diferena em
 * dias entre duas datas.
 * </p>
 * 
 * <p>
 * Exemplos:
 * </p>
 * <ul type="circule"> <li>07/10/1997 (Fator = 0);</li> <li>03/07/2000
 * (Fator = 1000);</li> <li>05/07/2000 (Fator = 1002);</li> <li>01/05/2002
 * (Fator = 1667);</li> <li>21/02/2025 (Fator = 9999).</li> </ul>
 * 
 * <p>
 * Funcionamento:
 * </p>
 * 
 * <ul type="square"> <li>Caso a data de vencimento seja anterior a data
 * base (Teoricamente fator negativo), uma exceo do tipo
 * IllegalArgumentException ser lanada.</li> <li>A data limite para o
 * clculo do fator de vencimento  21/02/2025 (Fator de vencimento = 9999).
 * Caso a data de vencimento seja posterior a data limite, uma exceo do
 * tipo IllegalArgumentException ser lanada.</li> </ul>
 * 
 * <p>
 * <strong>ATENO</strong>, esse clculo se refere a ttulos em cobrana,
 * ou melhor: BOLETOS. Desta forma, lembramos que a DATA BASE  uma norma da
 * FEBRABAN. Essa norma diz que todos os boletos emitidos a partir de 1 de
 * setembro de 2000 (primeiro dia til = 03/07/2000 - SEGUNDA) devem seguir
 * esta regra de clculo para compor a informao de vencimento no cdigo de
 * barras. Portanto, boletos no padro FEBRABAN quando capturados por
 * sistemas da rede bancria permitem que se possa realizar a operao
 * inversa, ou seja, adicionar  data base o fator de vencimento capturado.
 * Obtendo ento a data de vencimento deste boleto.
 * </p>
 * 
 * @param dataVencimento
 *            data de vencimento de um ttulo
 * @return fator de vencimento calculado
 * @throws IllegalArgumentException
 * 
 * @since 0.2
 */

public static int calculceFatorDeVencimento(Date dataVencimento) throws IllegalArgumentException {

    Date dataVencTruncada = null;
    int fator;

    if (isNull(dataVencimento)) {
        throw new IllegalArgumentException(
                "Impossvel realizar o clculo do fator" + " de vencimento de uma data nula.");
    } else {
        dataVencTruncada = DateUtils.truncate(dataVencimento, Calendar.DATE);
        if (dataVencTruncada.before(DATA_BASE_DO_FATOR_DE_VENCIMENTO)
                || dataVencTruncada.after(DATA_LIMITE_DO_FATOR_DE_VENCIMENTO)) {
            throw new IllegalArgumentException(
                    "Para o clculo do fator de" + " vencimento se faz necessrio informar uma data entre"
                            + " " + DateUtil.FORMAT_DD_MM_YYYY.format(DATA_BASE_DO_FATOR_DE_VENCIMENTO) + " e "
                            + DateUtil.FORMAT_DD_MM_YYYY.format(DATA_LIMITE_DO_FATOR_DE_VENCIMENTO));
        } else {
            fator = (int) DateUtil.calculeDiferencaEmDias(DATA_BASE_DO_FATOR_DE_VENCIMENTO, dataVencTruncada);
        }
    }

    return fator;
}