Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

In this page you can find the example usage for java.util Calendar clear.

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:org.kuali.kra.budget.summary.BudgetSummaryServiceImpl.java

protected Date getLeapDay(Date date) {
    Calendar c1 = Calendar.getInstance();
    c1.clear();
    c1.set(getYear(date), 1, 29);//from  w  w  w  .j  a v a  2 s. c om
    return new java.sql.Date(c1.getTime().getTime());

}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testParseZone() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();
    cal.set(2003, Calendar.JULY, 10, 16, 33, 20);

    final DateParser fdf = getInstance(yMdHmsSZ, NEW_YORK, Locale.US);

    assertEquals(cal.getTime(), fdf.parse("2003-07-10T15:33:20.000 -0500"));
    assertEquals(cal.getTime(), fdf.parse("2003-07-10T15:33:20.000 GMT-05:00"));
    assertEquals(cal.getTime(), fdf.parse("2003-07-10T16:33:20.000 Eastern Daylight Time"));
    assertEquals(cal.getTime(), fdf.parse("2003-07-10T16:33:20.000 EDT"));

    cal.setTimeZone(TimeZone.getTimeZone("GMT-3"));
    cal.set(2003, Calendar.FEBRUARY, 10, 9, 0, 0);

    assertEquals(cal.getTime(), fdf.parse("2003-02-10T09:00:00.000 -0300"));

    cal.setTimeZone(TimeZone.getTimeZone("GMT+5"));
    cal.set(2003, Calendar.FEBRUARY, 10, 15, 5, 6);

    assertEquals(cal.getTime(), fdf.parse("2003-02-10T15:05:06.000 +0500"));
}

From source file:com.clustercontrol.calendar.factory.SelectCalendar.java

public ArrayList<CalendarDetailInfo> getCalendarWeek(CalendarInfo info, Integer year, Integer month,
        Integer day) throws CalendarNotFound {
    m_log.trace("calendarId:" + info.getCalendarId() + ", year:" + year + ", month:" + month + ", day:" + day);
    long validFrom = info.getValidTimeFrom();
    long validTo = info.getValidTimeTo();
    ArrayList<CalendarDetailInfo> ret = new ArrayList<CalendarDetailInfo>();
    Calendar startCalendar = HinemosTime.getCalendarInstance();
    startCalendar.clear();
    startCalendar.set(year, month - 1, day, 0, 0, 0);
    long startTime = startCalendar.getTimeInMillis();
    Calendar endCalendar = HinemosTime.getCalendarInstance();
    endCalendar.clear();//from  w  w w  .j av  a2  s .co m
    endCalendar.set(year, month - 1, day + 1, 0, 0, 0);
    long endTime = endCalendar.getTimeInMillis();

    if (startTime <= validFrom && endTime <= validFrom) {
        return ret;
    }
    if (validTo <= startTime && validTo <= endTime) {
        return ret;
    }
    if (startTime < validFrom && validFrom < endTime) {
        CalendarDetailInfo detail = new CalendarDetailInfo();
        detail.setTimeFrom(0 - TIMEZONE);
        detail.setTimeTo(validFrom - startTime - TIMEZONE);
        detail.setOperateFlg(false);
        detail.setOrderNo(-2);// ?
        m_log.trace("start<validfrom && validfrom<endttime add");
        ret.add(detail);
    }
    if (startTime < validTo && validTo < endTime) {
        CalendarDetailInfo detail = new CalendarDetailInfo();
        detail.setTimeFrom(validTo - startTime - TIMEZONE);
        detail.setTimeTo(HOUR24 - TIMEZONE);
        detail.setOperateFlg(false);
        detail.setOrderNo(-1);// ?
        m_log.trace("start<validto && validto<endttime add");
        ret.add(detail);
    }

    // client?????CalendarDetailList???
    // ?????????
    startCalendar.clear();
    startCalendar.set(year, month - 1, day, 0, 0, 0);
    ArrayList<Date> checkDateList = new ArrayList<>();
    int onesec = 1 * 1000;
    Long startLong = startCalendar.getTime().getTime();
    ArrayList<CalendarDetailInfo> substituteList = new ArrayList<>();

    for (CalendarDetailInfo detailInfo : info.getCalendarDetailList()) {
        int timezone = HinemosTime.getTimeZoneOffset();
        // start_time
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() - onesec + timezone));// 1second??
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() + onesec + timezone));// 1second?
        // end_time
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() - onesec + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() + onesec + timezone));
        if (detailInfo.isSubstituteFlg()) {
            // ?????????
            substituteList.add(detailInfo);
        }
    }

    // getDetail24???????
    ArrayList<CalendarDetailInfo> detailList = new ArrayList<>();
    for (CalendarDetailInfo detail : info.getCalendarDetailList()) {
        detailList.addAll(CalendarUtil.getDetail24(detail));
    }
    for (CalendarDetailInfo detailInfo : detailList) {
        int timezone = HinemosTime.getTimeZoneOffset();
        // start_time
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() - onesec + timezone));// 1second??
        checkDateList.add(new Date(startLong + detailInfo.getTimeFrom() + onesec + timezone));// 1second?
        // end_time
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() - onesec + timezone));
        checkDateList.add(new Date(startLong + detailInfo.getTimeTo() + onesec + timezone));
    }

    // ?????????????
    ArrayList<Date> checkDateListSub = new ArrayList<>();
    for (Date checkDate : checkDateList) {
        for (CalendarDetailInfo detailInfo : substituteList) {
            Long checkDateLong = checkDate.getTime();
            checkDateListSub
                    .add(new Date(checkDateLong - (CalendarUtil.parseDate(detailInfo.getSubstituteTime())
                            + HinemosTime.getTimeZoneOffset())));
        }
    }
    checkDateList.addAll(checkDateListSub);

    // ?valid_time_from?valid_time_to
    checkDateList.add(new Date(info.getValidTimeFrom()));
    checkDateList.add(new Date(info.getValidTimeTo()));
    // list??????
    checkDateList = new ArrayList<>(new HashSet<>(checkDateList));
    // list?
    Collections.sort(checkDateList);
    m_log.trace("checkDateList.size:" + checkDateList.size());

    ArrayList<CalendarDetailInfo> detailSubsList = new ArrayList<>();
    for (Date targetDate : checkDateList) {
        Calendar targetCal = Calendar.getInstance();
        targetCal.setTime(targetDate);
        // ????????????
        if (startCalendar.get(Calendar.YEAR) != targetCal.get(Calendar.YEAR)
                || startCalendar.get(Calendar.MONTH) != targetCal.get(Calendar.MONTH)
                || startCalendar.get(Calendar.DATE) != targetCal.get(Calendar.DATE)) {
            continue;
        }
        m_log.trace("startCalendar:" + targetDate);
        ArrayList<CalendarDetailInfo> detailList2 = new ArrayList<>();
        Date substituteDate = new Date(targetDate.getTime());

        // detailList2????CalendarDetailInfo?
        Object[] retObjArr = CalendarUtil.getCalendarRunDetailInfo(info, targetDate, detailList2);
        boolean isrun = (Boolean) retObjArr[0];
        // ?2??????
        if (retObjArr.length == 2) {
            substituteDate.setTime(((Date) retObjArr[1]).getTime());
        }
        m_log.trace("id:" + info.getCalendarId() + ", startCalendar:" + targetDate + ", detailList2.size:"
                + detailList2.size() + ", isrun:" + isrun + ", substituteDate:" + substituteDate.toString());

        // ?CalendarDetailInfo????????????getDetail24?????
        for (CalendarDetailInfo detailInfo : detailList2) {
            ArrayList<CalendarDetailInfo> calendarDetailList = CalendarUtil.getDetail24(detailInfo);
            for (CalendarDetailInfo detail24 : calendarDetailList) {
                if (CalendarUtil.isRunByDetailDateTime(detail24, substituteDate)
                        && !detailSubsList.contains(detail24)) {
                    detailSubsList.add(detail24);
                    m_log.trace("add to ret. orderNo:" + detail24.getOrderNo() + ", description:"
                            + detail24.getDescription() + ", isOperation:" + detail24.isOperateFlg() + ", from:"
                            + detail24.getTimeFrom() + ", to:" + detail24.getTimeTo());
                }
            }
        }
    }
    ret.addAll(detailSubsList);
    Collections.sort(ret, new Comparator<CalendarDetailInfo>() {
        public int compare(CalendarDetailInfo obj0, CalendarDetailInfo obj1) {
            int order1 = obj0.getOrderNo();
            int order2 = obj1.getOrderNo();
            int ret = order1 - order2;
            return ret;
        }
    });

    if (m_log.isDebugEnabled()) {
        for (CalendarDetailInfo detail : ret) {
            m_log.debug("detail=" + detail);
        }
    }
    m_log.trace("ret.size:" + ret.size());
    return ret;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testLang1121() throws ParseException {
    final TimeZone kst = TimeZone.getTimeZone("KST");
    final DateParser fdp = getInstance("yyyyMMdd", kst, Locale.KOREA);

    try {/*from  w w w  .  j  ava 2s .  c  om*/
        fdp.parse("2015");
        Assert.fail("expected parse exception");
    } catch (final ParseException pe) {
        // expected parse exception
    }

    // Wed Apr 29 00:00:00 KST 2015
    Date actual = fdp.parse("20150429");
    final Calendar cal = Calendar.getInstance(kst, Locale.KOREA);
    cal.clear();
    cal.set(2015, 3, 29);
    Date expected = cal.getTime();
    Assert.assertEquals(expected, actual);

    final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd", Locale.KOREA);
    df.setTimeZone(kst);
    expected = df.parse("20150429113100");

    // Thu Mar 16 00:00:00 KST 81724
    actual = fdp.parse("20150429113100");
    Assert.assertEquals(expected, actual);
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

/**
 * Code from Axis1 code base Note - We only follow the convention in the latest schema spec
 *
 * @param source//  w w w .ja v  a  2s  . c  o  m
 * @return Returns Calendar.
 */
public static Calendar convertToDateTime(String source) {

    if ((source == null) || source.trim().equals("")) {
        return null;
    }
    source = source.trim();
    // the lexical representation of the date time as follows
    // '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
    Date date = null;
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.setLenient(false);

    if (source.startsWith("-")) {
        source = source.substring(1);
        calendar.set(Calendar.ERA, GregorianCalendar.BC);
    }

    int year = 0;
    int month = 0;
    int day = 0;
    int hour = 0;
    int minite = 0;
    int second = 0;
    long miliSecond = 0;
    int timeZoneOffSet = TimeZone.getDefault().getRawOffset();

    if ((source != null) && (source.length() >= 19)) {
        if ((source.charAt(4) != '-') || (source.charAt(7) != '-') || (source.charAt(10) != 'T')
                || (source.charAt(13) != ':') || (source.charAt(16) != ':')) {
            throw new RuntimeException("invalid date format (" + source + ") with out - s at correct place ");
        }
        year = Integer.parseInt(source.substring(0, 4));
        month = Integer.parseInt(source.substring(5, 7));
        day = Integer.parseInt(source.substring(8, 10));
        hour = Integer.parseInt(source.substring(11, 13));
        minite = Integer.parseInt(source.substring(14, 16));
        second = Integer.parseInt(source.substring(17, 19));

        int milliSecondPartLength = 0;

        if (source.length() > 19) {
            String rest = source.substring(19);
            if (rest.startsWith(".")) {
                // i.e this have the ('.'s+) part
                if (rest.endsWith("Z")) {
                    // this is in gmt time zone
                    timeZoneOffSet = 0;
                    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
                    miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("Z")));
                    milliSecondPartLength = rest.substring(1, rest.lastIndexOf("Z")).trim().length();
                } else if ((rest.lastIndexOf("+") > 0) || (rest.lastIndexOf("-") > 0)) {
                    // this is given in a general time zione
                    String timeOffSet = null;
                    if (rest.lastIndexOf("+") > 0) {
                        timeOffSet = rest.substring(rest.lastIndexOf("+") + 1);
                        miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("+")));
                        milliSecondPartLength = rest.substring(1, rest.lastIndexOf("+")).trim().length();
                        // we keep +1 or -1 to finally calculate the value
                        timeZoneOffSet = 1;

                    } else if (rest.lastIndexOf("-") > 0) {
                        timeOffSet = rest.substring(rest.lastIndexOf("-") + 1);
                        miliSecond = Integer.parseInt(rest.substring(1, rest.lastIndexOf("-")));
                        milliSecondPartLength = rest.substring(1, rest.lastIndexOf("-")).trim().length();
                        // we keep +1 or -1 to finally calculate the value
                        timeZoneOffSet = -1;
                    }
                    if (timeOffSet.charAt(2) != ':') {
                        throw new RuntimeException(
                                "invalid time zone format (" + source + ") without : at correct place");
                    }
                    int hours = Integer.parseInt(timeOffSet.substring(0, 2));
                    int minits = Integer.parseInt(timeOffSet.substring(3, 5));
                    timeZoneOffSet = ((hours * 60) + minits) * 60000 * timeZoneOffSet;

                } else {
                    // i.e it does not have time zone
                    miliSecond = Integer.parseInt(rest.substring(1));
                    milliSecondPartLength = rest.substring(1).trim().length();
                }

            } else {
                if (rest.startsWith("Z")) {
                    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
                    // this is in gmt time zone
                    timeZoneOffSet = 0;
                } else if (rest.startsWith("+") || rest.startsWith("-")) {
                    // this is given in a general time zione
                    if (rest.charAt(3) != ':') {
                        throw new RuntimeException(
                                "invalid time zone format (" + source + ") without : at correct place");
                    }
                    int hours = Integer.parseInt(rest.substring(1, 3));
                    int minits = Integer.parseInt(rest.substring(4, 6));
                    timeZoneOffSet = ((hours * 60) + minits) * 60000;
                    if (rest.startsWith("-")) {
                        timeZoneOffSet = timeZoneOffSet * -1;
                    }
                } else {
                    throw new NumberFormatException("in valid time zone attribute");
                }
            }
        }
        calendar.set(Calendar.YEAR, year);
        // xml month is started from 1 and calendar month is started from 0
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minite);
        calendar.set(Calendar.SECOND, second);
        if (milliSecondPartLength != 3) {
            // milisecond part represenst the fraction of the second so we have to
            // find the fraction and multiply it by 1000. So if milisecond part
            // has three digits nothing required
            miliSecond = miliSecond * 1000;
            for (int i = 0; i < milliSecondPartLength; i++) {
                miliSecond = miliSecond / 10;
            }
        }
        calendar.set(Calendar.MILLISECOND, (int) miliSecond);
        calendar.set(Calendar.ZONE_OFFSET, timeZoneOffSet);
        // set the day light offset only if the time zone is present
        if (source.length() > 19) {
            calendar.set(Calendar.DST_OFFSET, 0);
        }

    } else {
        throw new NumberFormatException("date string can not be less than 19 characters");
    }

    return calendar;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testAmPm() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();

    final DateParser h = getInstance("yyyy-MM-dd hh a mm:ss", NEW_YORK, Locale.US);
    final DateParser K = getInstance("yyyy-MM-dd KK a mm:ss", NEW_YORK, Locale.US);
    final DateParser k = getInstance("yyyy-MM-dd kk:mm:ss", NEW_YORK, Locale.US);
    final DateParser H = getInstance("yyyy-MM-dd HH:mm:ss", NEW_YORK, Locale.US);

    cal.set(2010, Calendar.AUGUST, 1, 0, 33, 20);
    assertEquals(cal.getTime(), h.parse("2010-08-01 12 AM 33:20"));
    assertEquals(cal.getTime(), K.parse("2010-08-01 0 AM 33:20"));
    assertEquals(cal.getTime(), k.parse("2010-08-01 00:33:20"));
    assertEquals(cal.getTime(), H.parse("2010-08-01 00:33:20"));

    cal.set(2010, Calendar.AUGUST, 1, 3, 33, 20);
    assertEquals(cal.getTime(), h.parse("2010-08-01 3 AM 33:20"));
    assertEquals(cal.getTime(), K.parse("2010-08-01 3 AM 33:20"));
    assertEquals(cal.getTime(), k.parse("2010-08-01 03:33:20"));
    assertEquals(cal.getTime(), H.parse("2010-08-01 03:33:20"));

    cal.set(2010, Calendar.AUGUST, 1, 15, 33, 20);
    assertEquals(cal.getTime(), h.parse("2010-08-01 3 PM 33:20"));
    assertEquals(cal.getTime(), K.parse("2010-08-01 3 PM 33:20"));
    assertEquals(cal.getTime(), k.parse("2010-08-01 15:33:20"));
    assertEquals(cal.getTime(), H.parse("2010-08-01 15:33:20"));

    cal.set(2010, Calendar.AUGUST, 1, 12, 33, 20);
    assertEquals(cal.getTime(), h.parse("2010-08-01 12 PM 33:20"));
    assertEquals(cal.getTime(), K.parse("2010-08-01 0 PM 33:20"));
    assertEquals(cal.getTime(), k.parse("2010-08-01 12:33:20"));
    assertEquals(cal.getTime(), H.parse("2010-08-01 12:33:20"));
}

From source file:com.greenline.guahao.web.module.home.controllers.expert.FastOrderProcess.java

/**
 * ?/*  w  ww . j  a va2s  .c om*/
 * 
 * @return List<ValueTextVO>
 */
public List<ValueTextVO> getClinicDateScopeList() {
    List<ValueTextVO> list = new ArrayList<ValueTextVO>();
    // ?
    Calendar now = Calendar.getInstance();
    Calendar time = Calendar.getInstance();
    time.clear();
    time.set(Calendar.YEAR, now.get(Calendar.YEAR));
    time.set(Calendar.MONTH, now.get(Calendar.MONTH));
    time.set(Calendar.DAY_OF_YEAR, now.get(Calendar.DAY_OF_YEAR));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    time.add(Calendar.DAY_OF_YEAR, 1); // 
    StringBuffer scope0 = new StringBuffer();
    StringBuffer scope1 = new StringBuffer();
    StringBuffer scope2 = new StringBuffer();
    StringBuffer value0 = new StringBuffer();
    StringBuffer value1 = new StringBuffer();
    StringBuffer value2 = new StringBuffer();

    scope0.append(sdf.format(time.getTime()));
    value0.append(time.getTime().getTime());
    scope0.append("-");
    value0.append("-");
    time.add(Calendar.DAY_OF_YEAR, 6); // 
    scope0.append(sdf.format(time.getTime()));
    value0.append(time.getTime().getTime());
    ValueTextVO vt0 = new ValueTextVO();
    vt0.setValue(value0.toString());
    vt0.setText(scope0.toString());
    list.add(vt0);

    time.add(Calendar.DAY_OF_YEAR, 1); // 
    scope1.append(sdf.format(time.getTime()));
    value1.append(time.getTime().getTime());
    scope1.append("-");
    value1.append("-");
    time.add(Calendar.DAY_OF_YEAR, 6); // 
    scope1.append(sdf.format(time.getTime()));
    value1.append(time.getTime().getTime());
    // scope1 += "()";
    ValueTextVO vt1 = new ValueTextVO();
    vt1.setValue(value1.toString());
    vt1.setText(scope1.toString());
    list.add(vt1);

    time.add(Calendar.DAY_OF_YEAR, 1); // 
    scope2.append(sdf.format(time.getTime()));
    value2.append(time.getTime().getTime());
    scope2.append("??");
    value2.append("-");
    time.add(Calendar.DAY_OF_YEAR, 365);// 365
    value2.append(time.getTime().getTime());
    ValueTextVO vt2 = new ValueTextVO();
    vt2.setValue(value2.toString());
    vt2.setText(scope2.toString());
    list.add(vt2);

    return list;
}

From source file:org.kuali.kra.budget.summary.BudgetSummaryServiceImpl.java

public boolean isLeapDaysInPeriod(Date sDate, Date eDate) {
    Date leapDate;/* w  w  w.  j a v  a  2  s.com*/
    int sYear = getYear(sDate);
    int eYear = getYear(eDate);
    if (isLeapYear(sDate)) {
        Calendar c1 = Calendar.getInstance();
        c1.clear();
        c1.set(sYear, 1, 29);
        leapDate = new java.sql.Date(c1.getTime().getTime());
        // start date is before 2/29 & enddate >= 2/29
        if (sDate.before(leapDate)) {
            if (eDate.compareTo(leapDate) >= 0) {
                return true;
            }
        } else if (sDate.equals(leapDate)) {
            return true;
        }
    } else if (isLeapYear(eDate)) {
        Calendar c1 = Calendar.getInstance();
        c1.set(eYear, 1, 29);
        leapDate = new java.sql.Date(c1.getTime().getTime());
        if (eDate.compareTo(leapDate) >= 0) {
            return true;
        }
    } else {
        sYear++;
        while (eYear > sYear) {
            if (isLeapYear(sYear)) {
                return true;
            }
            sYear++;
        }
    }
    return false;
}

From source file:KitchenManagement.FoodDemandForecastingAndPlanning.FoodDemandForecastingAndPlanningBean.java

@Override
public Boolean generatePurchaseOrderFromMaterialRequirement(Long storeId) {
    System.out.println("generatePurchaseOrderFromMaterialRequirement is called.");
    try {/*  w  w  w  .  j  av a2 s .  c o  m*/
        StoreEntity store = em.find(StoreEntity.class, storeId);
        Query q = em.createQuery("select s from MonthScheduleEntity s");
        List<MonthScheduleEntity> scheduleList = q.getResultList();
        MonthScheduleEntity schedule = scheduleList.get(scheduleList.size() - 1);
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, schedule.getYear());
        calendar.set(Calendar.MONTH, schedule.getMonth() - 1);

        Query q1 = em.createQuery("select rm from RawIngredientEntity rm");
        List<RawIngredientEntity> rmList = (List<RawIngredientEntity>) q1.getResultList();

        for (RawIngredientEntity rm : rmList) {
            Integer stockLevel = micBean.checkItemQty(store.getWarehouse().getId(), rm.getSKU());

            Query q2 = em.createQuery(
                    "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.schedule.id = ?2 and mr.rawIngredient.SKU = ?3 order by mr.day")
                    .setParameter(1, storeId).setParameter(2, schedule.getId()).setParameter(3, rm.getSKU());
            List<MaterialRequirementEntity> mrList = (List<MaterialRequirementEntity>) q2.getResultList();
            System.out.println("mrList.size()" + mrList.size());

            for (MaterialRequirementEntity mr : mrList) {
                System.out.println("mr.getDay()" + mr.getDay());
                if (stockLevel >= mr.getQuantity()) {
                    stockLevel -= mr.getQuantity();
                } else {
                    Query q3 = em.createQuery(
                            "select si from Supplier_ItemEntity si where si.supplier.regionalOffice.id = ?1 and si.item.SKU = ?2")
                            .setParameter(1, store.getRegionalOffice().getId()).setParameter(2, rm.getSKU());
                    Supplier_ItemEntity supplier_ItemEntity = (Supplier_ItemEntity) q3.getSingleResult();

                    int lotsize = supplier_ItemEntity.getLotSize();
                    int purchaseQuantity = 0;
                    if (((mr.getQuantity() - stockLevel) % lotsize) != 0) {
                        purchaseQuantity = (((mr.getQuantity() - stockLevel) / lotsize) + 1) * lotsize;
                    } else {
                        purchaseQuantity = (((mr.getQuantity() - stockLevel) / lotsize)) * lotsize;
                    }
                    System.out.println("(mr.getQuantity() - stockLevel): " + (mr.getQuantity() - stockLevel)
                            + "; lotsize: " + lotsize);
                    System.out.println("purchaseQuantity: " + purchaseQuantity);
                    calendar.set(Calendar.DAY_OF_MONTH, mr.getDay());

                    PurchaseOrderEntity purchaseOrder = purchaseBean.createPurchaseOrder(
                            supplier_ItemEntity.getSupplier().getId(), store.getWarehouse().getId(),
                            calendar.getTime());
                    purchaseBean.addLineItemToPurchaseOrder(purchaseOrder.getId(), rm.getSKU(),
                            purchaseQuantity);

                    stockLevel = stockLevel + purchaseQuantity - mr.getQuantity();
                }
            }
        }
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return false;
}

From source file:org.richfaces.component.UICalendar.java

public Date convertCurrentDate(String currentDateString) {

    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.DATE, 1);
    int idx = currentDateString.indexOf('/');
    if (idx != -1) {
        calendar.set(Calendar.MONTH, Integer.parseInt(currentDateString.substring(0, idx)) - 1);
        calendar.set(Calendar.YEAR, Integer.parseInt(currentDateString.substring(idx + 1)));

        return calendar.getTime();
    } else {/*from  w  w w  .  jav a  2s.  c om*/
        return null;
    }

}