Example usage for java.util Date equals

List of usage examples for java.util Date equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:com.github.pockethub.ui.gist.GistFragment.java

private void updateHeader(Gist gist) {
    Date createdAt = TimeUtils.stringToDate(gist.created_at);
    if (createdAt != null) {
        StyledText text = new StyledText();
        text.append(getString(R.string.prefix_created));
        text.append(createdAt);//ww w.j ava 2s  .c o  m
        created.setText(text);
        created.setVisibility(VISIBLE);
    } else
        created.setVisibility(GONE);

    Date updatedAt = TimeUtils.stringToDate(gist.updated_at);
    if (updatedAt != null && !updatedAt.equals(createdAt)) {
        StyledText text = new StyledText();
        text.append(getString(R.string.prefix_updated));
        text.append(updatedAt);
        updated.setText(text);
        updated.setVisibility(VISIBLE);
    } else
        updated.setVisibility(GONE);

    String desc = gist.description;
    if (!TextUtils.isEmpty(desc))
        description.setText(desc);
    else
        description.setText(R.string.no_description_given);

    ViewUtils.setGone(progress, true);
    ViewUtils.setGone(list, false);
}

From source file:org.jasig.schedassist.web.visitor.CreateAppointmentFormController.java

/**
 * Verify the startTime argument is within the window; throws a {@link ScheduleException} if not.
 * /*from   w  w  w .  jav a2 s . c  om*/
 * @param window
 * @param startTime
 * @throws SchedulingException
 */
protected void validateChosenStartTime(VisibleWindow window, Date startTime) throws SchedulingException {
    final Date currentWindowStart = window.calculateCurrentWindowStart();
    final Date currentWindowEnd = window.calculateCurrentWindowEnd();
    if (startTime.before(currentWindowStart) || startTime.equals(currentWindowEnd)
            || startTime.after(currentWindowEnd)) {
        throw new SchedulingException("requested time is no longer within visible window");
    }
}

From source file:org.candlepin.util.UtilTest.java

@Test
public void roundToMidnight() {
    Date now = new Date();
    Date midnight = Util.roundToMidnight(now);
    assertFalse(now.equals(midnight));

    Calendar cal = Calendar.getInstance();
    cal.setTime(midnight);//  www  .jav a2  s . c  o m
    assertEquals(23, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, cal.get(Calendar.MINUTE));
    assertEquals(59, cal.get(Calendar.SECOND));
    assertEquals(TimeZone.getDefault(), cal.getTimeZone());

    Date stillmidnight = Util.roundToMidnight(midnight);
    cal.setTime(stillmidnight);
    assertEquals(23, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, cal.get(Calendar.MINUTE));
    assertEquals(59, cal.get(Calendar.SECOND));
    assertEquals(TimeZone.getDefault(), cal.getTimeZone());
}

From source file:com.ms.commons.test.classloader.util.SimpleAntxLoader.java

protected int readCacheFile(String svnUrl, String file, StringBuilder outContent) {

    File cacheDir = new File(CACHE_DIRECTORY);
    if (!(cacheDir.exists() && cacheDir.isDirectory())) {
        cacheDir.mkdirs();/* w w  w . j  ava2s  .  c om*/
    }

    File fileDate = new File(CACHE_DIRECTORY + "/" + convertSvnUrlToDegist(svnUrl) + file + ".date");
    File fileData = new File(CACHE_DIRECTORY + "/" + convertSvnUrlToDegist(svnUrl) + file + ".data");

    if (!fileDate.exists()) {
        return -1;
    }

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

    try {
        Date date = dateFormat.parse((FileUtils.readFileToString(fileDate)));
        Date now = dateFormat.parse(dateFormat.format(new Date()));

        if (now.equals(date)) {
            System.out.println("Read file:" + file + " from cache.");
            outContent.append(FileUtils.readFileToString(fileData));
            return 200;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }

    return -1;
}

From source file:org.eclipse.mylyn.internal.gerrit.core.GerritConnector.java

@Override
public boolean hasTaskChanged(TaskRepository repository, ITask task, TaskData taskData) {
    ITaskMapping taskMapping = getTaskMapping(taskData);
    Date repositoryDate = taskMapping.getModificationDate();
    Date localDate = task.getModificationDate();
    return repositoryDate == null || !repositoryDate.equals(localDate);
}

From source file:org.sofun.core.sport.SportsGraphTimeManager.java

/**
 * Checks sports graph elements (Season, Stage, Round and Game) and
 * transitioning their status when needed.
 * //  w ww.  j a v  a2  s .  co  m
 * @throws Exception
 */
// XXX DISABLED
// @Schedule(minute = "*/5", hour = "*", persistent = false)
public void check() throws Exception {

    if (!available) {
        return;
    } else {
        available = false;
    }

    try {

        // Update scheduled rounds start date
        for (TournamentRound round : sports.getTournamentRoundsByStatus(TournamentRoundStatus.SCHEDULED)) {
            Date first = null;
            for (TournamentGame game : round.getGames()) {
                Date startDate = game.getStartDate();
                if (first == null) {
                    first = startDate;
                } else if (startDate != null && startDate.compareTo(first) < 0) {
                    first = game.getStartDate();
                }
            }
            if (first != null && !first.equals(round.getStartDate())) {
                round.setStartDate(first);
                log.info("Updated start_date for round w/ uuid=" + round.getUUID());
            }
        }

        // Update scheduled stages start date
        for (TournamentStage stage : sports.getTournamentStagesByStatus(TournamentStageStatus.SCHEDULED)) {
            Date first = null;
            for (TournamentRound round : stage.getRounds()) {
                Date startDate = round.getStartDate();
                if (first == null) {
                    first = startDate;
                } else if (startDate != null && startDate.compareTo(first) < 0) {
                    first = round.getStartDate();
                }
            }
            if (first != null && !first.equals(stage.getStartDate())) {
                stage.setStartDate(first);
                log.info("Update start_date for stage w/ uuid=" + stage.getUUID());
            }
        }

        // Update scheduled seasons start date
        for (TournamentSeason season : sports.getTournamentSeasonsByStatus(TournamentSeasonStatus.SCHEDULED)) {
            Date first = null;
            for (TournamentStage stage : season.getStages()) {
                Date startDate = stage.getStartDate();
                if (first == null) {
                    first = startDate;
                } else if (startDate != null && startDate.compareTo(first) < 0) {
                    first = stage.getStartDate();
                }
            }
            if (first != null && !first.equals(season.getStartDate())) {
                season.setStartDate(first);
                log.info("Update start_date for season w/ uuid=" + season.getUUID());
            }
        }
    } finally {
        available = true;
    }

}

From source file:org.jasig.schedassist.portlet.webflow.FlowHelper.java

/**
 * Verify the startTime argument is within the window; return {@link #NO} if not.
 * /*from w  w w  . j  a  v  a2s.c om*/
 * @param window
 * @param startTime
 * @return {@link #YES} for valid, {@link #NO} for invalid
 */
public String validateChosenStartTime(VisibleWindow window, Date startTime) {
    final Date currentWindowEnd = window.calculateCurrentWindowEnd();
    if (startTime.before(window.calculateCurrentWindowStart()) || startTime.equals(currentWindowEnd)
            || startTime.after(currentWindowEnd)) {
        LOG.debug("selected startTime (" + startTime + ") is no longer within window " + window.getKey());
        return NO;
    }

    return YES;
}

From source file:com.qcadoo.mes.masterOrders.validators.OrderValidatorsMO.java

private boolean checkIfDeadlineIsCorrect(final Entity order, final Entity masterOrder) {
    Date deadlineFromMaster = masterOrder.getDateField(DEADLINE);
    Date deadlineFromOrder = order.getDateField(DEADLINE);
    if ((deadlineFromMaster == null && deadlineFromOrder == null)
            || (deadlineFromMaster == null && deadlineFromOrder != null)) {
        return true;
    }/*  ww  w  . j  a va2s  .c o m*/

    if ((deadlineFromMaster != null && deadlineFromOrder == null)) {
        return false;
    }

    if (deadlineFromOrder.equals(deadlineFromMaster)) {
        return true;
    }
    order.addError(order.getDataDefinition().getField(DEADLINE),
            "masterOrders.masterOrder.deadline.isIncorrect");
    return false;
}

From source file:org.asqatasun.webapp.validator.CreateContractFormValidator.java

/**
 *
 * @param userSubscriptionCommand//w  w w.ja  v  a2s  . c  o  m
 * @param errors
 * @return
 */
private boolean checkDates(CreateContractCommand createContractCommand, Errors errors) {
    Date beginDate = createContractCommand.getBeginDate();
    Date endDate = createContractCommand.getEndDate();
    if (beginDate == null) {
        errors.rejectValue(BEGIN_DATE_KEY, EMPTY_BEGIN_DATE_KEY);
        return false;
    }
    if (endDate == null) {
        errors.rejectValue(END_DATE_KEY, EMPTY_END_DATE_KEY);
        return false;
    }
    if (endDate.before(beginDate) || endDate.equals(beginDate)) {
        errors.rejectValue(BEGIN_DATE_KEY, END_DATE_ANTERIOR_TO_BEGIN_KEY);
        return false;
    }
    return true;
}

From source file:com.trenako.results.RollingStockResultsTests.java

@Test
public void shouldFillTheResultsByLastModifiedDates() {
    Date since = fulldate("2010/06/10 09:30:00");
    Date max = fulldate("2010/06/10 09:30:00");

    List<RollingStock> results = resultsByLastModified(10, false, since, max);
    RangeRequest range = buildRange(10);

    PaginatedResults<RollingStock> pagResults = new RollingStockResults(results, null, range);

    assertEquals(10, ((List<RollingStock>) pagResults.getItems()).size());
    assertTrue("Since date is different", since.equals(pagResults.getRange().getSince()));
    assertEquals(max, pagResults.getRange().getMax());
}