Example usage for com.liferay.portal.kernel.util GetterUtil getDate

List of usage examples for com.liferay.portal.kernel.util GetterUtil getDate

Introduction

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

Prototype

public static Date getDate(String value, DateFormat dateFormat) 

Source Link

Document

Returns the String value as a Date.

Usage

From source file:com.liferay.jbpm.db.GraphSession.java

License:Open Source License

private Timestamp _getDate(String date, boolean greaterThan) {
    if (Validator.isNull(date)) {
        return null;
    } else {/*from   w w w .  ja v a 2 s  .  com*/
        Calendar calendar = Calendar.getInstance();

        DateFormat dateFormat = DateUtil.getISOFormat();

        calendar.setTime(GetterUtil.getDate(date, dateFormat));

        if (greaterThan) {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 23);
            calendar.set(Calendar.MINUTE, 59);
            calendar.set(Calendar.SECOND, 59);
            calendar.set(Calendar.MILLISECOND, 999);
        }

        TimeZone timeZone = TimeZone.getTimeZone(_timeZoneId);

        int offset = timeZone.getOffset(calendar.getTimeInMillis());

        return new Timestamp(calendar.getTimeInMillis() - offset);
    }
}

From source file:com.liferay.portlet.amazonrankings.util.AmazonRankingsWebCacheItem.java

License:Open Source License

protected Date getReleaseDate(String releaseDateAsString) {
    if (Validator.isNull(releaseDateAsString)) {
        return null;
    }// w ww . jav  a  2  s.c o  m

    DateFormat dateFormat = null;

    if (releaseDateAsString.length() > 7) {
        dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM-dd", Locale.US);
    } else {
        dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyy-MM", Locale.US);
    }

    return GetterUtil.getDate(releaseDateAsString, dateFormat);
}

From source file:com.liferay.portlet.expando.util.ExpandoConverterUtil.java

License:Open Source License

public static Serializable getAttributeFromString(int type, String attribute) {

    if (attribute == null) {
        return null;
    }//from w w  w  .j  ava2  s  .  c o m

    if (type == ExpandoColumnConstants.BOOLEAN) {
        return GetterUtil.getBoolean(attribute);
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
        return GetterUtil.getBooleanValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.DATE) {
        return GetterUtil.getDate(attribute, _getDateFormat());
    } else if (type == ExpandoColumnConstants.DATE_ARRAY) {
        return GetterUtil.getDateValues(StringUtil.split(attribute), _getDateFormat());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        return GetterUtil.getDouble(attribute);
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        return GetterUtil.getDoubleValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.FLOAT) {
        return GetterUtil.getFloat(attribute);
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        return GetterUtil.getFloatValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.INTEGER) {
        return GetterUtil.getInteger(attribute);
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        return GetterUtil.getIntegerValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.LONG) {
        return GetterUtil.getLong(attribute);
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        return GetterUtil.getLongValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.SHORT) {
        return GetterUtil.getShort(attribute);
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        return GetterUtil.getShortValues(StringUtil.split(attribute));
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        return StringUtil.split(attribute);
    } else {
        return attribute;
    }
}

From source file:com.liferay.portlet.journal.action.GetArticlesAction.java

License:Open Source License

protected List<JournalArticle> getArticles(HttpServletRequest request) throws Exception {

    long companyId = PortalUtil.getCompanyId(request);
    long groupId = ParamUtil.getLong(request, "groupId");
    String articleId = null;//from   w  w w.  j av a 2 s . c o  m
    Double version = null;
    String title = null;
    String description = null;
    String content = null;
    String type = ParamUtil.getString(request, "type");
    String[] structureIds = StringUtil.split(ParamUtil.getString(request, "structureId"));
    String[] templateIds = StringUtil.split(ParamUtil.getString(request, "templateId"));

    Date displayDateGT = null;

    String displayDateGTParam = ParamUtil.getString(request, "displayDateGT");

    if (Validator.isNotNull(displayDateGTParam)) {
        DateFormat displayDateGTFormat = DateUtil.getISOFormat(displayDateGTParam);

        displayDateGT = GetterUtil.getDate(displayDateGTParam, displayDateGTFormat);
    }

    if (_log.isDebugEnabled()) {
        _log.debug("displayDateGT is " + displayDateGT);
    }

    Date displayDateLT = null;

    String displayDateLTParam = ParamUtil.getString(request, "displayDateLT");

    if (Validator.isNotNull(displayDateLTParam)) {
        DateFormat displayDateLTFormat = DateUtil.getISOFormat(displayDateLTParam);

        displayDateLT = GetterUtil.getDate(displayDateLTParam, displayDateLTFormat);
    }

    if (displayDateLT == null) {
        displayDateLT = new Date();
    }

    if (_log.isDebugEnabled()) {
        _log.debug("displayDateLT is " + displayDateLT);
    }

    int status = WorkflowConstants.STATUS_APPROVED;
    Date reviewDate = null;
    boolean andOperator = true;
    int start = 0;
    int end = ParamUtil.getInteger(request, "delta", 5);
    String orderBy = ParamUtil.getString(request, "orderBy");
    String orderByCol = ParamUtil.getString(request, "orderByCol", orderBy);
    String orderByType = ParamUtil.getString(request, "orderByType");
    boolean orderByAsc = orderByType.equals("asc");

    OrderByComparator obc = new ArticleModifiedDateComparator(orderByAsc);

    if (orderByCol.equals("display-date")) {
        obc = new ArticleDisplayDateComparator(orderByAsc);
    }

    return JournalArticleServiceUtil.search(companyId, groupId, 0, articleId, version, title, description,
            content, type, structureIds, templateIds, displayDateGT, displayDateLT, status, reviewDate,
            andOperator, start, end, obc);
}