Example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDurationHMS

Introduction

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

Prototype

public static String formatDurationHMS(long durationMillis) 

Source Link

Document

Formats the time gap as a string.

The format used is ISO8601-like: H:m:s.S.

Usage

From source file:portal.util.UndeployScheduler.java

@Override
public void doJob() {
    Logger.info(" ------------INSIDE  doJob-------------");
    Query query = JPA.em().createQuery("select op from OfferPurchased as op");
    List<OfferPurchased> result = query.getResultList();
    Logger.info("No of Results retrieved : " + result.size());
    for (OfferPurchased record : result) {
        Date currentDate = new Date();
        Date expDate = record.getExpiration();

        // Get days from difference
        Integer days = Integer.parseInt(
                DurationFormatUtils.formatDurationHMS(expDate.getTime() - currentDate.getTime()).split(":")[0])
                / 24;//w ww .j a v a2 s  . co m

        final Collection<Integer> daysToSendMail = Lists.newArrayList(1, 2, 3, 4, 5, 7, 15, 30);
        if (expDate.before(currentDate)) {
            Logger.info("Lease has expired.");
            deleteOffer(record);
            Mails.sendExpiredEmail(record);
        } else if (daysToSendMail.contains(days)) {
            Logger.info("Lease is almost expired.");
            Mails.sendExtendEmail(record);
        }
    }
    Logger.info(" ------------EXITING  doJob-------------");
}