Example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY

List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY.

Prototype

long MILLIS_PER_DAY

To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_DAY.

Click Source Link

Document

Number of milliseconds in a standard day.

Usage

From source file:phex.gui.dialogs.security.SecurityRuleDialog.java

private ExpiryDate createAfterExpiryDate() {
    Integer days = daysTF.getIntegerValue();
    if (days == null) {
        days = Integer.valueOf(0);
    }//from w ww .  ja  v  a  2 s . c o m
    Integer hours = hoursTF.getIntegerValue();
    if (hours == null) {
        hours = Integer.valueOf(0);
    }
    Integer minutes = minutesTF.getIntegerValue();
    if (minutes == null) {
        minutes = Integer.valueOf(0);
    }

    long currentTime = System.currentTimeMillis();
    currentTime += days.intValue() * DateUtils.MILLIS_PER_DAY + hours.intValue() * DateUtils.MILLIS_PER_HOUR
            + minutes.intValue() * DateUtils.MILLIS_PER_MINUTE;
    return ExpiryDate.getExpiryDate(currentTime);
}

From source file:phex.rules.consequence.BanHostConsequence.java

public void invoke(Search search, final RemoteFile remoteFile, Servent servent) {
    // handle a ban like a remove we dont like to see the RemoteHost
    // again in this consequence
    remoteFile.setFilteredRemoved(true);

    ExpiryDate expDate = ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 7);
    BanHostBatch.addDestAddress(remoteFile.getHostAddress(), expDate, servent.getSecurityService());
}

From source file:ru.codeinside.calendar.CalendarBasedDueDateCalculator.java

/**
 * ?? ?    /*  w  ww . j  a v a2s  .  co m*/
 *
 * @param startDate   
 * @param endDate    ? 
 * @return ?   
 */
@Override
public int countDays(Date startDate, Date endDate) {
    if (startDate == null)
        throw new IllegalArgumentException(
                "      NULL");
    if (endDate == null)
        throw new IllegalArgumentException(
                " ?     NULL");
    return (int) ((endDate.getTime() - startDate.getTime()) / DateUtils.MILLIS_PER_DAY);
}

From source file:ubic.gemma.web.taglib.common.auditAndSecurity.WhatsNewBoxTag.java

@Override
public int doStartTag() throws JspException {

    Collection<ExpressionExperiment> newExpressionExperiments = whatsNew.getNewExpressionExperiments();
    Collection<ArrayDesign> newArrayDesigns = whatsNew.getNewArrayDesigns();
    Collection<ExpressionExperiment> updatedExpressionExperiments = whatsNew.getUpdatedExpressionExperiments();
    Collection<ArrayDesign> updatedArrayDesigns = whatsNew.getUpdatedArrayDesigns();
    // don't show things that are "new" as "updated" too (if they were updated after being loaded)
    updatedExpressionExperiments.removeAll(newExpressionExperiments);
    updatedArrayDesigns.removeAll(newArrayDesigns);

    StringBuilder buf = new StringBuilder();

    if (newArrayDesigns.size() == 0 && newExpressionExperiments.size() == 0
            && updatedExpressionExperiments.size() == 0 && updatedArrayDesigns.size() == 0) {
        buf.append("<input type='hidden' name='nothing new' />");
    } else {/*from   w  w w. j a v a  2  s  .com*/
        buf.append(" <strong>Changes in the");
        Date date = whatsNew.getDate();
        Date now = Calendar.getInstance().getTime();
        long millis = now.getTime() - date.getTime();
        double days = millis / (double) DateUtils.MILLIS_PER_DAY;
        if (days > 0.9 && days < 2.0) {
            buf.append(" last day");
        } else if (days < 8) {
            buf.append(" last week");
        } else {
            NumberFormat nf = NumberFormat.getIntegerInstance();
            buf.append(" last " + nf.format(days) + " days");
        }
        buf.append("</strong> ");
        buf.append("<p>");

        int numEEs = newExpressionExperiments.size();
        int numADs = newArrayDesigns.size();
        int updatedAds = updatedArrayDesigns.size();
        int updatedEEs = updatedExpressionExperiments.size();

        if (numEEs > 0) {
            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ExpressionExperiment ee : newExpressionExperiments) {
                ids.add(ee.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/expressionExperiment/showAllExpressionExperiments.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + numEEs + " new data set" + (numEEs > 1 ? "s" : "") + "</a>.<br />");
        }
        if (numADs > 0) {

            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ArrayDesign ad : newArrayDesigns) {
                // buf.append( ad.getId() + "," );
                ids.add(ad.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/arrays/showAllArrayDesigns.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + numADs + " new platform" + (numADs > 1 ? "s" : "") + "</a>.<br />");
        }

        if (updatedEEs > 0) {
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            int count = 0;
            for (ExpressionExperiment ee : updatedExpressionExperiments) {
                ids.add(ee.getId());

                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/expressionExperiment/showAllExpressionExperiments.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + updatedEEs + " updated data set" + (updatedEEs > 1 ? "s" : "") + "</a>.<br />");

        }

        if (updatedAds > 0) {
            int count = 0;
            boolean tooMany = false;
            List<Long> ids = new ArrayList<Long>();
            for (ArrayDesign ad : updatedArrayDesigns) {
                ids.add(ad.getId());
                if (++count > MAX_NEW_ITEMS) {
                    tooMany = true;
                    break;
                }
            }
            buf.append("<a " + (tooMany ? "title='View the first " + MAX_NEW_ITEMS + "'" : "")
                    + " href=\"/Gemma/arrays/showAllArrayDesigns.html?id=");
            buf.append(StringUtils.join(ids, ","));
            buf.append("\">" + updatedAds + " updated platform" + (updatedAds > 1 ? "s" : "") + "</a>.<br />");

        }

        buf.append("</p>");
    }

    try {
        pageContext.getOut().print(buf.toString());
    } catch (Exception ex) {
        throw new JspException("ContactTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}

From source file:uk.ac.ebi.metabolights.repository.dao.StudyDAOTest.java

@Test
public void testStatusesForSubmitter() throws Exception {

    // Get the full study
    Study study = studyDAO.getStudy(inconsistent.getAcc(), owner.getApiToken());

    assertEquals("Default status of a study must be submitted", LiteStudy.StudyStatus.SUBMITTED,
            study.getStudyStatus());/* w w w  . java 2s.  c om*/

    // Change the statuses as owner
    Study savedStudy = updateStatus(study, owner, LiteStudy.StudyStatus.INCURATION, false);
    updateStatus(study, owner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.PUBLIC, true);

    updateStatus(study, notOwner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.PUBLIC, true);
    assertFalse("Public release date has been changed",
            DateUtils.isSameDay(new Date(), savedStudy.getStudyPublicReleaseDate()));

    // Change the status as curator
    updateStatus(study, curator, LiteStudy.StudyStatus.INCURATION, false);

    // Change the statuses as owner, shouldn't be allowed.
    updateStatus(study, owner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.PUBLIC, true);

    updateStatus(study, notOwner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.PUBLIC, true);
    assertFalse("Public release date has been changed",
            DateUtils.isSameDay(new Date(), savedStudy.getStudyPublicReleaseDate()));

    updateStatus(study, curator, LiteStudy.StudyStatus.INREVIEW, false);
    // Change the statuses as owner, shouldn't be allowed.
    updateStatus(study, owner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.PUBLIC, true);

    updateStatus(study, notOwner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.PUBLIC, true);

    assertFalse("Public release date has been changed",
            DateUtils.isSameDay(new Date(), savedStudy.getStudyPublicReleaseDate()));

    // Make it public
    savedStudy = updateStatus(study, curator, LiteStudy.StudyStatus.PUBLIC, false);

    assertTrue("Public release date not updated when changing study to public",
            DateUtils.isSameDay(new Date(), savedStudy.getStudyPublicReleaseDate()));

    // Change the statuses as owner, shouldn't be allowed.
    updateStatus(study, owner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, owner, LiteStudy.StudyStatus.PUBLIC, true);

    updateStatus(study, notOwner, LiteStudy.StudyStatus.SUBMITTED, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INCURATION, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.INREVIEW, true);
    updateStatus(study, notOwner, LiteStudy.StudyStatus.PUBLIC, true);

    // Make study Private again
    updateStatus(study, curator, LiteStudy.StudyStatus.SUBMITTED, false);

    // Change the release date to yesterday
    studyDAO.updateReleaseDate(inconsistent.getAcc(), new Date(new Date().getTime() - DateUtils.MILLIS_PER_DAY),
            owner.getApiToken());

    // Make study INCURATION again
    savedStudy = updateStatus(study, owner, LiteStudy.StudyStatus.INCURATION, false);

    assertFalse("Public release date updated when changing study to INCURATION and date has passed",
            DateUtils.isSameDay(new Date(), savedStudy.getStudyPublicReleaseDate()));

    // Make study READY again this should change de public release date to today and the status to public
    updateStatus(savedStudy, curator, LiteStudy.StudyStatus.INREVIEW, false);

}