Example usage for com.liferay.portal.kernel.util DateUtil getDaysBetween

List of usage examples for com.liferay.portal.kernel.util DateUtil getDaysBetween

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util DateUtil getDaysBetween.

Prototype

public static int getDaysBetween(Date date1, Date date2) 

Source Link

Usage

From source file:com.htmsd.slayer.service.impl.ShoppingItemServiceImpl.java

License:Open Source License

private void getItemJSONArray(long groupId, JSONArray jsonArray, List<ShoppingItem> shoppingItems,
        long currencyId) {

    double currencyRate = CommonUtil.getCurrentRate(currencyId);

    for (ShoppingItem shoppingItem : shoppingItems) {
        long imageId = shoppingItem.getSmallImage();
        double total = (currencyRate == 0) ? shoppingItem.getSellingPrice()
                : shoppingItem.getSellingPrice() / currencyRate;
        double MRP = (currencyRate == 0) ? shoppingItem.getMRP() : shoppingItem.getMRP() / currencyRate;
        String shortDescription = (Validator.isNotNull(shoppingItem.getShortDescription())
                ? shoppingItem.getShortDescription()
                : StringPool.BLANK);/*www .  ja v a 2s  .c  o m*/

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put(HConstants.ITEM_ID, shoppingItem.getItemId());
        jsonObject.put(HConstants.NAME, shoppingItem.getName());
        jsonObject.put(HConstants.DESCRIPTION, StringUtil.shorten(shoppingItem.getDescription(), 20));
        jsonObject.put(HConstants.TOTAL_PRICE, total);
        jsonObject.put("MRP", MRP);
        jsonObject.put(HConstants.IMAGE, CommonUtil.getThumbnailpath(imageId, groupId, false));
        jsonObject.put("shortDescription", StringUtil.shorten(shortDescription, 20));

        if (DateUtil.getDaysBetween(shoppingItem.getModifiedDate(), Calendar.getInstance().getTime()) >= 2) {
            jsonObject.put(HConstants.IS_NEW_ITEM, false);
        } else {
            jsonObject.put(HConstants.IS_NEW_ITEM, true);
        }

        jsonArray.put(jsonObject);
    }
}

From source file:com.rivetlogic.portlet.AnnouncerTools.java

License:Open Source License

/**
 * Show not completed./*from   w w  w.j  a  v a 2 s .  c om*/
 *
 * @param userId the user id
 * @param layoutPK the layout pk
 * @return true, if successful
 */
private static boolean showNotCompleted(String userId, String layoutPK) {
    Date currentDate = null;
    Date notCompletedDate = null;

    NotCompletedPK userLayoutPKNC = new NotCompletedPK();
    userLayoutPKNC.setLAYOUT_PK(layoutPK);
    userLayoutPKNC.setUSER_ID(userId);

    try {
        NotCompleted user = NotCompletedLocalServiceUtil.getNotCompleted(userLayoutPKNC);
        notCompletedDate = user.getPANEL_CLOSE_DATE();

        currentDate = new Date();

        int diff = DateUtil.getDaysBetween(currentDate, notCompletedDate);

        if (diff >= ONE_DAY) {
            return true;
        }
    } catch (PortalException e) {
        LOG.error(e);
    } catch (SystemException e) {
        LOG.error(e);
    }

    return false;
}