Example usage for org.joda.time Period Period

List of usage examples for org.joda.time Period Period

Introduction

In this page you can find the example usage for org.joda.time Period Period.

Prototype

private Period(int[] values, PeriodType type) 

Source Link

Document

Constructor used when we trust ourselves.

Usage

From source file:eu.esdihumboldt.hale.ui.views.report.properties.summary.DurationSection.java

License:Open Source License

@Override
protected void updateControl(Object input, Text control) {
    Report<?> report = (Report<?>) input;
    control.setText(PeriodFormat.wordBased()
            .print(new Period(report.getStartTime().getTime(), report.getTimestamp().getTime())));
}

From source file:factory.utils.Utils.java

public static String getHoursBetweenDays(Date startDate, Date endDate) throws Exception {

    if (startDate == null) {

        startDate = endDate;/*  w  w w . j  ava  2  s  .com*/
    }

    DateTime dt1 = new DateTime(startDate.getTime());
    DateTime dt2 = new DateTime(endDate.getTime());

    Period p = new Period(dt1, dt2);
    long hours = p.getDays() * 24 + p.getHours();
    long minutes = p.getMinutes();

    String format = String.format("%%0%dd", 2);

    return String.format(format, hours) + ":" + String.format(format, minutes);
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.MainServlet.java

License:BSD License

/**
 * Method to detect/handle account lock condition.
 * /*  w  ww  . j ava  2s  .  c o  m*/
 * @param username
 * @param password
 * @param session
 * @param req
 * @param resp
 * @param redictedUrl
 * @return account status
 * @throws Exception
 */
private String doValidateAccountStatus(String username, HttpSession session, HttpServletRequest req,
        HttpServletResponse resp, String redictedUrl) throws Exception {
    String retVal = "";
    logger.debug("doValidateAccountStatus: entered");

    //check locked state here
    String action = (String) session.getAttribute(Constants.ACTION_TOKEN);
    if (action != null && !action.equals(Constants.UNLOCK_TOKEN)) {
        //CADSRPASSW-29
        connect();
        PasswordChangeDAO dao = new PasswordChangeDAO(datasource);
        List arr = dao.getAccountStatus(username);
        if (arr == null || arr.size() != 2) {
            throw new Exception("Not able to check account status.");
        }
        retVal = (String) arr.get(PasswordChangeDAO.ACCOUNT_STATUS);

        //begin CADSRPASSW-55 - unlock manually as the "password_lock_time 60/1440" does not work
        //         String status = (String)arr.get(PasswordChangeDAO.ACCOUNT_STATUS);
        Date lockedDate = (Date) arr.get(PasswordChangeDAO.LOCK_DATE);
        logger.debug("LockedDate [" + lockedDate + "] Status [" + retVal + "]");
        Period period = null;
        boolean doUnlock = false;
        if (lockedDate != null && retVal != null && retVal.indexOf(Constants.LOCKED_STATUS) > -1) {
            DateTime now = new DateTime();
            period = new Period(new DateTime(lockedDate), now);
            if (period.getHours() >= 1) {
                doUnlock = true;
            }
        }

        if (doUnlock) {
            connect();
            PasswordChangeDAO dao1 = new PasswordChangeDAO(datasource);
            dao1.unlockAccount(username);
            logger.info("Over 1 hour, password lock release (" + period.getMinutes() + " minutes has passed).");
            //logger.debug("Getting the account status again ...");
            //retVal = (String)arr.get(PasswordChangeDAO.ACCOUNT_STATUS);
            retVal = Constants.OPEN_STATUS;
            logger.debug("Account status is [" + retVal + "] now");
        }
        //end CADSRPASSW-55 - unlock manually as the "password_lock_time 60/1440" does not work
        else if (retVal != null && retVal.indexOf(Constants.LOCKED_STATUS) > -1) {
            String tmp = "NOT ABLE TO CALCULATE PERIOD DUE to NULL LOCKED_DATE";
            if (period != null) {
                tmp = String.valueOf(period.getMinutes()) + " minutes has passed).";
            }
            logger.info("Less than 1 hour, password lock stays (" + tmp + ")"); //CADSRPASSW-87
            session.setAttribute(ERROR_MESSAGE_SESSION_ATTRIBUTE,
                    Messages.getString("PasswordChangeHelper.103"));
            logger.debug("Redirecting to '" + redictedUrl + "'");
            resp.sendRedirect(redictedUrl);
        }
    }

    logger.debug("doValidateAccountStatus: exiting with retVal [" + retVal + "] ...");

    return retVal;
}

From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.MainServlet.java

License:BSD License

private boolean isAnswerLockPeriodOver(String userID) throws Exception {
    boolean retVal = false;

    logger.debug("isAnswerLockExpired:entered");
    connect();// w  ww  . ja  va  2 s  . c  o  m
    PasswordChangeDAO dao = new PasswordChangeDAO(datasource);
    logger.debug("isAnswerLockExpired:before dao.findByPrimaryKey userid [" + userID + "]");
    UserSecurityQuestion qna = dao.findByPrimaryKey(userID);
    logger.debug("isAnswerLockExpired:qna [" + qna + "]");
    if (qna != null) {
        logger.debug("isAnswerLockExpired:qna not null [" + qna.toString() + "]");
        if (qna.getDateModified() == null) {
            throw new Exception("Security questions date modified is NULL or empty.");
        }
        DateTime now = new DateTime();
        logger.debug(
                "isAnswerLockExpired:last modified date for user '" + userID + "' is " + qna.getDateModified());
        Period period = new Period(new DateTime(qna.getDateModified()), now);
        if (period.getHours() >= 1) { //CADSRPASSW-51
            retVal = true;
            logger.info("isAnswerLockExpired:Over 1 hour for user '" + userID + "', answer limit count reset ("
                    + period.getMinutes() + " minutes has passed).");
        } else {
            logger.debug("isAnswerLockExpired:Not over 1 hour yet for user '" + userID + "', nothing is done ("
                    + period.getMinutes() + " minutes has passed).");
        }
    }

    logger.debug("isAnswerLockExpired:exiting ...");

    return retVal;
}

From source file:hello.H2p.java

License:Apache License

String procentWorkTime() {
    int procent = fileIdx * 100 / filesCount;
    String workTime = hmsFormatter.print(new Period(startMillis, new DateTime()));
    String procentSecond = " - html2pdf3 - (" + procent + "%, " + workTime + "s)";
    return procentSecond;
}

From source file:imas.inventory.sessionbean.YieldManagementSessionBean.java

@Override
public String getFlightFromNowToDepartureString(FlightEntity flight) {
    DateTime departureTime = new DateTime(flight.getDepartureDate().getTime());
    DateTime now = new DateTime();
    Period period = new Period(now, departureTime);
    int years = period.getYears();
    int months = period.getMonths();
    int days = 7 * period.getWeeks() + period.getDays();

    String res = "";
    if (years > 0) {
        if (years > 1) {
            res = res + years + " years ";
        } else {/*w  w  w  . j  av a2  s  .  co m*/
            res = "1 year ";
        }
    }
    if (months > 0) {
        if (months > 1) {
            res = res + months + " months ";
        } else {
            res = res + "1 month ";
        }
    }
    if (days > 0) {
        if (days > 1) {
            res = res + days + " days";
        } else {
            res = res + "1 day";
        }
    }

    return res;
}

From source file:ipr.projekt.dialogi.ZalozKontoDialog.java

private boolean mniejNiz18(int urDzien, int urMiesiac, int urRok) {

    DateTime now = new DateTime();
    DateTime dataUrodzenia = new DateTime(urRok, urMiesiac, urDzien, 0, 0);
    Period period = new Period(dataUrodzenia, now);
    if (period.getYears() < 18) {
        return true;
    }//from w  w w.j a  va 2  s.  c o m

    return false;
}

From source file:it.av.eatt.ocm.util.DateUtil.java

License:Apache License

/**
 * Return the period passed between the actual time and the given time
 * <p>The period is approximated to the biggest field:
 * Example if the period is 2 days and 3 hours the results is: 2 days 
 * /* ww  w  . j  a  v a 2 s  .c  om*/
 * @param time
 * @return the period
 */
public static String getPeriod(long time) {
    Period period = new Period(time, System.currentTimeMillis());
    //get the substring before the first "$" separator
    return StringUtils.substringBefore(DateUtil.standard().print(period), "$");
}

From source file:it.f2informatica.core.model.builder.ConsultantModelBuilder.java

License:Apache License

public ConsultantModelBuilder withBirthDate(Date birthDate) {
    consultant.setBirthDate(birthDate);//from ww w  .j  a  v a 2  s. c om
    if (birthDate != null) {
        Period periodFromBirthdayToday = new Period(new DateTime(birthDate), new DateTime());
        consultant.setAge(periodFromBirthdayToday.getYears());
    }
    return this;
}

From source file:it.f2informatica.webapp.utils.PeriodParser.java

License:Apache License

public String printTotalTimeOfPeriodWhichHasElapsed(Date from, Date to) {
    DateTime timeFrom = new DateTime(from);
    DateTime timeTo = (to != null) ? new DateTime(to) : new DateTime();
    Period period = new Period(timeFrom, timeTo);
    return "(" + appendYears(period) + appendMonths(period) + ")";
}