Example usage for java.util Calendar after

List of usage examples for java.util Calendar after

Introduction

In this page you can find the example usage for java.util Calendar after.

Prototype

public boolean after(Object when) 

Source Link

Document

Returns whether this Calendar represents a time after the time represented by the specified Object.

Usage

From source file:org.nuxeo.ecm.core.api.security.ACE.java

/**
 * Returns the status of this ACE.//from   w w w .java2  s. c  o  m
 *
 * @since 7.4
 */
public Status getStatus() {
    Status status = Status.EFFECTIVE;
    Calendar now = new GregorianCalendar();
    if (begin != null && now.before(begin)) {
        status = Status.PENDING;
    }
    if (end != null && now.after(end)) {
        status = Status.ARCHIVED;
    }
    return status;
}

From source file:org.opencms.ade.publish.A_CmsPublishGroupHelper.java

/**
 * Gets the difference in days between to dates given as longs.<p>
 *
 * The first date must be later than the second date.
 *
 * @param first the first date//from   w  w w  . j  a v a2 s  .c om
 * @param second the second date
 *
 * @return the difference between the two dates in days
 */
public int getDayDifference(long first, long second) {

    Calendar firstDay = getStartOfDay(first);
    Calendar secondDay = getStartOfDay(second);
    int result = 0;
    if (first >= second) {
        while (firstDay.after(secondDay)) {
            firstDay.add(Calendar.DAY_OF_MONTH, -1);
            result += 1;
        }
    } else {
        while (secondDay.after(firstDay)) {
            secondDay.add(Calendar.DAY_OF_MONTH, -1);
            result -= 1;
        }
    }
    return result;
}

From source file:com.adobe.acs.commons.wcm.notifications.impl.SystemNotificationsImpl.java

private boolean isActiveNotification(final SlingHttpServletRequest request, final Resource resource) {
    if (JcrConstants.JCR_CONTENT.equals(resource.getName()) || REP_POLICY.equals(resource.getName())) {
        return false;
    }// ww  w .j a  v  a  2 s. c o  m

    final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
    final Page notificationPage = pageManager.getContainingPage(resource);

    if (notificationPage == null) {
        log.warn("Trying to get a invalid System Notification page at [ {} ]", resource.getPath());
        return false;
    } else if (this.isDismissed(request, notificationPage)) {
        // System Notification previously dismissed by the user
        return false;
    }

    // Looks like a valid Notification Page; now check if the properties are valid
    final ValueMap properties = notificationPage.getProperties();

    final boolean enabled = properties.get(PN_ENABLED, false);
    if (!enabled) {
        // Disabled
        return false;
    } else {
        final Calendar onTime = properties.get(PN_ON_TIME, Calendar.class);
        final Calendar offTime = properties.get(PN_OFF_TIME, Calendar.class);

        if (onTime == null && offTime == null) {
            // No on time or off time is set, but is enabled so always show
            return true;
        }

        final Calendar now = Calendar.getInstance();

        if (onTime != null && now.before(onTime)) {
            return false;
        }

        if (offTime != null && now.after(offTime)) {
            return false;
        }

        return true;
    }
}

From source file:net.solarnetwork.node.backup.test.FileSystemBackupServiceTest.java

@Test
public void backupMultiple() throws IOException {
    final ClassPathResource testResource1 = new ClassPathResource("test-context.xml",
            AbstractNodeTransactionalTest.class);
    final ClassPathResource testResource2 = new ClassPathResource("test-file.txt",
            FileSystemBackupServiceTest.class);
    final BackupService bs = service;
    final List<BackupResource> resources = new ArrayList<BackupResource>(1);
    final Calendar now = new GregorianCalendar();
    now.set(Calendar.MILLISECOND, 0);
    resources.add(new ResourceBackupResource(testResource1, "test.xml"));
    resources.add(new ResourceBackupResource(testResource2, "test.txt"));

    Backup result = bs.performBackup(resources);
    assertNotNull(result);//from  www . j  av a 2s  . co  m
    assertNotNull(result.getDate());
    assertTrue(!now.after(result.getDate()));
    assertNotNull(result.getKey());
    assertTrue(result.isComplete());

    // now let's verify we can get that file back out of the backup
    Collection<Backup> backups = bs.getAvailableBackups();
    assertNotNull(backups);
    assertEquals(1, backups.size());
    Backup b = backups.iterator().next();
    assertEquals(result.getKey(), b.getKey());
    assertEquals(result.getDate().getTime(), b.getDate().getTime());

    int count = 0;
    final BackupResourceIterable backupResources = bs.getBackupResources(b);
    try {
        for (BackupResource r : bs.getBackupResources(b)) {
            if (count == 0) {
                assertEquals("test.xml", r.getBackupPath());
                Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource1.getInputStream()),
                        FileCopyUtils.copyToByteArray(r.getInputStream()));
            } else if (count == 1) {
                assertEquals("test.txt", r.getBackupPath());
                Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource2.getInputStream()),
                        FileCopyUtils.copyToByteArray(r.getInputStream()));
            }
            count++;
        }
    } finally {
        backupResources.close();
    }
    assertEquals("Should have 2 backup resources", 2, count);
}

From source file:com.hacktx.android.activities.EventDetailActivity.java

/**
 * Returns if the feedback card should be displayed given current date and feedback status.
 * @return true if feedback hasn't been submitted, isn't ignored, and the event has ended
 *//*from  w w  w.  j a va  2 s . co  m*/
private boolean shouldShowFeedbackCard() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    Calendar now = Calendar.getInstance();
    Calendar end = Calendar.getInstance();

    try {
        end.setTime(formatter.parse(event.getEndDate()));
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return now.after(end) && !UserStateStore.getFeedbackIgnored(this, event.getId())
            && !UserStateStore.getFeedbackSubmitted(this, event.getId());
}

From source file:com.swdouglass.joid.Association.java

public boolean hasExpired() {
    Calendar now = Calendar.getInstance();
    Calendar expired = Calendar.getInstance();
    expired.setTime(issuedDate);//from   ww  w .  j a va  2 s.  c  om
    expired.add(Calendar.SECOND, lifetime.intValue());
    if (log.isDebugEnabled()) {
        log.debug("now: " + now.toString());
        log.debug("issuedDate: " + issuedDate.toString());
        log.debug("expired: " + expired.toString());
        log.debug("now.after(expired): " + now.after(expired));
    }
    return now.after(expired);
}

From source file:com.square.tarificateur.noyau.util.validation.ValidationInfosAdhesionUtil.java

private void validerDateSignature(RapportDto rapportErreurs, Calendar dateSignature) {
    // La date de signature doit tre antrieure  la date courante
    final Calendar dateNow = Calendar.getInstance();
    if (dateSignature != null && dateSignature.after(dateNow)) {
        rapportErreurs.ajoutRapport("dateSignature",
                messageSourceUtil.get(MessageKeyUtil.ERREUR_DATE_SIGNATURE_POSTERIEURE), true);
    }//w w  w  . j a va 2 s  .com
}

From source file:com.baidu.rigel.biplatform.ac.util.TimeRangeDetail.java

/**
 * ???//from   w  w w. j av a 2s.c om
 * @return 
 */
public String[] getDays() {

    if (StringUtils.isBlank(this.start)) {
        throw new IllegalArgumentException("start can not be null for timerange");
    }
    if (StringUtils.isBlank(this.end)) {
        throw new IllegalArgumentException("end can not be null for timerange");
    }

    Calendar startCalen = Calendar.getInstance();
    Calendar endCalen = Calendar.getInstance();
    try {
        startCalen.setTime(sdf.parse(start));
        endCalen.setTime(sdf.parse(end));
    } catch (ParseException e) {
        e.printStackTrace();
    }

    List<String> days = Lists.newArrayList();
    do {
        days.add(sdf.format(startCalen.getTime()));
        startCalen.add(Calendar.DAY_OF_MONTH, 1);
    } while (endCalen.equals(startCalen) || endCalen.after(startCalen));

    return days.toArray(new String[0]);
}

From source file:vn.webapp.controller.cp.AcademicYearController.java

/**
 * Save a paper//w  w  w . j  a  v  a2s  .c  o  m
 * @param paperValid
 * @param result
 * @param model
 * @param session
 * @return String
 */
@RequestMapping(value = "saveAcademicYear", method = RequestMethod.POST)
public String saveAcademicYear(HttpServletRequest request,
        @Valid @ModelAttribute("academicYearAdd") AcademicYearValidation academicYearValidation,
        BindingResult result, Map model, HttpSession session) {
    /*
     * Get list of paper category and journalList
     */

    /*
     * Put data back to view
     */
    if (result.hasErrors()) {
        return "cp.addAcademicYear";
    } else {
        /*
         * Prepare data for inserting DB
         */
        String aYCode = academicYearValidation.getACAYEAR_Code();
        String aYStartDate = academicYearValidation.getACAYEAR_FromDate();
        String aYEndDate = academicYearValidation.getACAYEAR_ToDate();
        academicYearService.save(aYCode, aYStartDate, aYEndDate);

        AcademicYear aY = academicYearService.loadByCode(aYCode);
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();

        try {
            start.setTime(dateFormat.parse(aYStartDate));
            end.setTime(dateFormat.parse(aYEndDate));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int i = 1;
        while (end.after(start)) {
            Weeks week = new Weeks();
            String code = aYCode + i + "";
            String weekStart = dateFormat.format(start.getTime());
            start.add(Calendar.DATE, 6);
            String weekEnd = dateFormat.format(start.getTime());
            weeksService.save(code, i, weekStart, weekEnd, aY);
            start.add(Calendar.DATE, 1);
        }

        List<AcademicYear> academicYearList = academicYearService.list();

        /*
         * Put data back to view
         */
        model.put("academicYearList", academicYearList);
        return "cp.academicYears";
    }
}

From source file:com.likya.myra.jef.controller.BaseSchedulerController.java

/**
 * @param dependencyArray/*  w w  w  . j av  a 2 s  .  c o m*/
 * @return the maximum end date of the dependent jobs
 */
protected Calendar getMaxBaseDate(Item[] dependencyArray) {

    Calendar maxBaseDate = jobQueue.get(dependencyArray[0].getJsId()).getAbstractJobType().getManagement()
            .getTimeManagement().getJsRealTime().getStopTime();

    // System.err.println("Current : " + MyraDateUtils.getDate(maxBaseDate.getTime()));
    for (Item item : dependencyArray) {
        AbstractJobType depJob = jobQueue.get(item.getJsId()).getAbstractJobType();
        Calendar stopTime = depJob.getManagement().getTimeManagement().getJsRealTime().getStopTime();
        // System.err.println("Dep Job : " + item.getJsId() + " Time " + MyraDateUtils.getDate(maxBaseDate.getTime()));
        if (stopTime.after(maxBaseDate)) {
            maxBaseDate = stopTime;
        }
    }

    // System.err.println("After : " + MyraDateUtils.getDate(maxBaseDate.getTime()));

    return maxBaseDate;

}