yasuflatland-lf / damascus

⚔️ CRUD boilerplate generator for Liferay DXP
https://yasuflatland-lf.github.io/damascus-doc/
GNU Lesser General Public License v3.0
51 stars 35 forks source link

getDateTimeFromRequest need to create a empty time instead of throwing Exception when no parameters found #45

Closed yasuflatland-lf closed 6 years ago

yasuflatland-lf commented 7 years ago

In *LocalServiceImpl#getDateTimeFromRequest, this method should return alternative data instead of throwing an exception when no parameters for date found. Also in the exception, it needs to be printed on the console. The sample code is below.

    public Date getDateTimeFromRequest(PortletRequest request, String prefix) {
        int Year = ParamUtil.getInteger(request, prefix + "Year");
        int Month = ParamUtil.getInteger(request, prefix + "Month") + 1;
        int Day = ParamUtil.getInteger(request, prefix + "Day");
        int Hour = ParamUtil.getInteger(request, prefix + "Hour");
        int Minute = ParamUtil.getInteger(request, prefix + "Minute");
        int AmPm = ParamUtil.getInteger(request, prefix + "AmPm");

        if (AmPm == Calendar.PM) {
            Hour += 12;
        }

        LocalDateTime ldt;
        try {
            ldt = LocalDateTime.of(Year, Month, Day, Hour, Minute, 0);
        } catch (Throwable e) {
            e.printStackTrace();
            Date in = new Date();
            Instant instant = in.toInstant();
            return Date.from(instant);          
        }

        return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    }