Example usage for java.util Calendar WEEK_OF_MONTH

List of usage examples for java.util Calendar WEEK_OF_MONTH

Introduction

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

Prototype

int WEEK_OF_MONTH

To view the source code for java.util Calendar WEEK_OF_MONTH.

Click Source Link

Document

Field number for get and set indicating the week number within the current month.

Usage

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * return a timestamp Object which correspond to the timestamp
 * in parameter add with a  number of times unit (day,week,month)specify in strTimesUnit .
 * @param timestamp date/*from   w ww .  ja va2  s . co m*/
 * @param strTimesUnit (day,week,month)
 * @param nDecal the number of timesUnit
 * @return a timestamp Object which correspond with the string specified in parameter
 * add with a  number of times unit (day,week,month)specify in strTimesUnit.
 */
public static Timestamp addStatisticInterval(Timestamp timestamp, String strTimesUnit, int nDecal) {
    int nTimesUnit = Calendar.DAY_OF_MONTH;

    if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_WEEK)) {
        nTimesUnit = Calendar.WEEK_OF_MONTH;
    } else if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_MONTH)) {
        nTimesUnit = Calendar.MONTH;
    }

    Calendar caldate = new GregorianCalendar();
    caldate.setTime(timestamp);
    caldate.set(Calendar.MILLISECOND, 0);
    caldate.set(Calendar.SECOND, 0);
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE));
    caldate.add(nTimesUnit, nDecal);

    Timestamp timeStamp1 = new Timestamp(caldate.getTimeInMillis());

    return timeStamp1;
}

From source file:egovframework.oe1.cms.cmm.web.EgovOe1SchdulManageController.java

/**
 *  ? //from  w  w  w .j a va  2 s.c  o m
 * @param searchVO
 * @param commandMap
 * @param deptSchdulManageVO
 * @param model
 * @return "/cms/cmm/EgovSchdulManageWeekList"
 * @throws Exception
 */
@RequestMapping(value = "/cms/cmm/EgovOe1SchdulManageWeekList.do")
public String EgovDeptSchdulManageWeekList(@ModelAttribute("searchVO") EgovOe1ComDefaultVO searchVO,
        Map commandMap, EgovOe1SchdulManageVO deptSchdulManageVO, ModelMap model) throws Exception {
    //Spring Security
    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    //?  
    model.addAttribute("searchKeyword",
            commandMap.get("searchKeyword") == null ? "" : (String) commandMap.get("searchKeyword"));
    model.addAttribute("searchCondition",
            commandMap.get("searchCondition") == null ? "" : (String) commandMap.get("searchCondition"));

    // ?
    EgovOe1ComDefaultCodeVO vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1028");
    List schdulSeCode_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("schdulSeCode_result", schdulSeCode_result);

    // ?
    vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1008");
    List year_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("year_result", year_result);

    // 
    vo = new EgovOe1ComDefaultCodeVO();
    vo.setCodeId("OE1013");
    List month_result = cmmUseService.selectCmmCodeDetail(vo);
    model.addAttribute("month_result", month_result);

    /* *****************************************************************
     // ?  ?
    ****************************************************************** */
    Calendar calNow = Calendar.getInstance();
    Calendar calBefore = Calendar.getInstance();
    Calendar calNext = Calendar.getInstance();

    String strYear = deptSchdulManageVO.getSearchYear();
    String strMonth = deptSchdulManageVO.getSearchMonth();
    String strWeek = deptSchdulManageVO.getSearchWeek();
    String strSchdulSeCode = deptSchdulManageVO.getSearchSchdulSeCode();

    int iNowYear = 0;
    int iNowMonth = 0;
    int iNowDate = 0;
    int iNowWeek = 0;

    if ((strYear != null && !"".equals(strYear)) && (strMonth != null && !"".equals(strMonth))
            && (strWeek != null && !"".equals(strWeek))) {
        iNowYear = Integer.parseInt(strYear);
        iNowMonth = Integer.parseInt(strMonth);
        iNowWeek = Integer.parseInt(strWeek);
    } else {
        iNowYear = calNow.get(Calendar.YEAR);
        iNowMonth = (calNow.get(Calendar.MONTH) + 1);
        iNowDate = calNow.get(Calendar.DATE);
    }

    //System.out.println("strYear=====>"   + strYear);
    //System.out.println("strMonth=====>"   + strMonth);
    //System.out.println("strWeek=====>"   + strWeek);
    //System.out.println("iNowYear=====>"   + iNowYear);
    //System.out.println("iNowMonth=====>"+ iNowMonth);
    //System.out.println("iNowDate=====>"   + iNowDate);
    //System.out.println("Calendar.WEEK_OF_MONTH==>"+Calendar.WEEK_OF_MONTH);

    //?/ 
    calNow.set(iNowYear, iNowMonth - 1, 1);
    calBefore.set(iNowYear, iNowMonth - 1, 1);
    calNext.set(iNowYear, iNowMonth - 1, 1);

    calBefore.add(Calendar.MONTH, -1);
    calNext.add(Calendar.MONTH, +1);

    int startDay = calNow.getMinimum(Calendar.DATE);
    int endDay = calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
    int startWeek = calNow.get(Calendar.DAY_OF_WEEK);

    //System.out.println(" ?===>"+startWeek);

    ArrayList listWeekGrop = new ArrayList();
    ArrayList listWeekDate = new ArrayList();

    String sUseDate = "";

    calBefore.add(Calendar.DATE, calBefore.getActualMaximum(Calendar.DAY_OF_MONTH) - (startWeek - 1));
    for (int i = 1; i < startWeek; i++) {
        sUseDate = Integer.toString(calBefore.get(Calendar.YEAR));
        sUseDate += DateTypeIntForString(calBefore.get(Calendar.MONTH) + 1);
        sUseDate += DateTypeIntForString(calBefore.get(Calendar.DATE));
        listWeekDate.add(sUseDate);
        calBefore.add(Calendar.DATE, +1);
    }

    int iBetweenCount = startWeek;

    //  ?. BETWEEN 
    for (int i = 1; i <= endDay; i++) {
        sUseDate = Integer.toString(iNowYear);
        sUseDate += Integer.toString(iNowMonth).length() == 1 ? "0" + Integer.toString(iNowMonth)
                : Integer.toString(iNowMonth);
        sUseDate += Integer.toString(i).length() == 1 ? "0" + Integer.toString(i) : Integer.toString(i);

        listWeekDate.add(sUseDate);

        if (iBetweenCount % 7 == 0) {
            listWeekGrop.add(listWeekDate);
            listWeekDate = new ArrayList();

            if ((strYear == null || "".equals(strYear)) && i < iNowDate) {
                iNowWeek++;
            }
        }

        // 7? ??
        if (i == endDay) {

            for (int j = listWeekDate.size(); j < 7; j++) {
                String sUseNextDate = Integer.toString(calNext.get(Calendar.YEAR));
                sUseNextDate += DateTypeIntForString(calNext.get(Calendar.MONTH) + 1);
                sUseNextDate += DateTypeIntForString(calNext.get(Calendar.DATE));
                listWeekDate.add(sUseNextDate);
                calNext.add(Calendar.DATE, +1);
            }

            listWeekGrop.add(listWeekDate);
        }

        iBetweenCount++;
    }

    model.addAttribute("year", iNowYear + "");
    model.addAttribute("month", ((iNowMonth) + "").length() == 1 ? "0" + (iNowMonth) : (iNowMonth));
    model.addAttribute("week", iNowWeek + "");
    model.addAttribute("dayOfMonth", (Calendar.WEEK_OF_MONTH) + "");

    model.addAttribute("listWeekGrop", listWeekGrop);

    List listWeek = (List) listWeekGrop.get(iNowWeek);
    commandMap.put("searchMode", "WEEK");
    commandMap.put("schdulBgnde", (String) listWeek.get(0));
    commandMap.put("schdulEndde", (String) listWeek.get(listWeek.size() - 1));
    commandMap.put("searchSchdulSeCode", strSchdulSeCode);

    String sNowMonth = "";
    if (((iNowMonth) + "").length() == 1) {
        sNowMonth = "0" + (iNowMonth);
    } else {
        sNowMonth = (iNowMonth) + "";
    }
    deptSchdulManageVO.setSearchYear(iNowYear + "");
    deptSchdulManageVO.setSearchMonth(sNowMonth);
    deptSchdulManageVO.setSearchWeek(iNowWeek + "");

    //?   ?   ??.
    model.addAttribute("searchMode", deptSchdulManageVO);

    List resultList = egovDeptSchdulManageService.selectDeptSchdulManageRetrieve(commandMap);
    model.addAttribute("resultList", resultList);

    return "/cms/cmm/EgovSchdulManageWeekList";
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java

private static Date getKernelDate(Date d, TimeResolution resolution) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);/*from  w w  w.j  av  a2 s . c  o m*/

    switch (resolution) {
    case HOURLY:
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case DAILY:
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case WEEKLY:
        c.set(Calendar.DAY_OF_WEEK, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case MONTHLY:
        c.set(Calendar.WEEK_OF_MONTH, 1);
        c.set(Calendar.DAY_OF_WEEK, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case QUARTERLY:
        int numMonthsInQuarter = 3;
        // sets to either January 1st, April 1st, July 1st or October 1st
        c.set(Calendar.MONTH, c.get(Calendar.MONTH) / numMonthsInQuarter * numMonthsInQuarter);
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    case YEARLY:
        c.set(Calendar.MONTH, Calendar.JANUARY);
        c.set(Calendar.WEEK_OF_MONTH, 1);
        c.set(Calendar.DAY_OF_WEEK, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        break;
    }

    return c.getTime();
}

From source file:KitchenManagement.FoodDemandForecastingAndPlanning.FoodDemandForecastingAndPlanningBean.java

@Override
public Boolean generateMaterialRequirementPlan(Long storeId) {
    System.out.println("generateMaterialRequirementPlan is called.");
    try {//  w  w w  .  j a  v a  2  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 mps from MasterProductionScheduleEntity mps where mps.store.id = ?1 and mps.schedule.id = ?2")
                .setParameter(1, storeId).setParameter(2, schedule.getId());
        List<MasterProductionScheduleEntity> mpsList = (List<MasterProductionScheduleEntity>) q1
                .getResultList();

        for (MasterProductionScheduleEntity mps : mpsList) {
            if (mps.getMenuItem().getRecipe() != null) {
                for (LineItemEntity lineItem : mps.getMenuItem().getRecipe().getListOfLineItems()) {
                    Query q2 = em.createQuery(
                            "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id = ?3 and mr.mps.id = ?4")
                            .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                            .setParameter(3, schedule.getId()).setParameter(4, mps.getId());
                    List<MaterialRequirementEntity> mrList = (List<MaterialRequirementEntity>) q2
                            .getResultList();
                    System.out.println("mrList.getSize(): " + mrList.size());
                    for (MaterialRequirementEntity mr : mrList) {
                        em.remove(mr);
                    }
                    em.flush();
                }
            }
        }

        for (MasterProductionScheduleEntity mps : mpsList) {
            if (mps.getMenuItem().getRecipe() != null && mps.getAmount_month() != 0) {
                for (LineItemEntity lineItem : mps.getMenuItem().getRecipe().getListOfLineItems()) {

                    Query query1 = em.createQuery(
                            "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id =?3 and mr.day = ?4 ")
                            .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                            .setParameter(3, schedule.getId()).setParameter(4, 1);
                    if (mps.getAmount_week1() != 0) {
                        if (query1.getResultList().isEmpty()) {
                            MaterialRequirementEntity MR1 = new MaterialRequirementEntity();
                            MR1.setStore(store);
                            MR1.setMps(mps);
                            MR1.setRawIngredient((RawIngredientEntity) lineItem.getItem());
                            MR1.setQuantity(mps.getAmount_week1() * lineItem.getQuantity()
                                    / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                            MR1.setSchedule(schedule);
                            MR1.setDay(1);
                            em.persist(MR1);
                        } else {
                            MaterialRequirementEntity MR1 = (MaterialRequirementEntity) query1.getResultList()
                                    .get(0);
                            MR1.setQuantity(MR1.getQuantity() + mps.getAmount_week1() * lineItem.getQuantity()
                                    / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                            em.merge(MR1);
                        }
                    }

                    calendar.set(Calendar.WEEK_OF_MONTH, 2);
                    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                    System.out.println("calendar.get(Calendar.DAY_OF_MONTH) week2 :"
                            + calendar.get(Calendar.DAY_OF_MONTH));
                    Query query2 = em.createQuery(
                            "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id =?3 and mr.day = ?4 ")
                            .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                            .setParameter(3, schedule.getId())
                            .setParameter(4, calendar.get(Calendar.DAY_OF_MONTH));

                    if (query2.getResultList().isEmpty()) {
                        MaterialRequirementEntity MR2 = new MaterialRequirementEntity();
                        MR2.setStore(store);
                        MR2.setMps(mps);
                        MR2.setRawIngredient((RawIngredientEntity) lineItem.getItem());
                        System.out.println("persis-mps.getAmount_week2(): " + mps.getAmount_week2());
                        System.out.println("lineItem.getQuantity(): " + lineItem.getQuantity());
                        System.out.println("mps.getMenuItem().getRecipe().getBroadLotSize()"
                                + mps.getMenuItem().getRecipe().getBroadLotSize());
                        MR2.setQuantity(mps.getAmount_week2() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        MR2.setSchedule(schedule);
                        MR2.setDay(calendar.get(Calendar.DAY_OF_MONTH));
                        em.persist(MR2);
                        System.out.println("persis-MR2.getQuantity(): " + MR2.getQuantity());
                    } else {
                        MaterialRequirementEntity MR2 = (MaterialRequirementEntity) query2.getResultList()
                                .get(0);
                        System.out.println("persis-mps.getAmount_week2(): " + mps.getAmount_week2());
                        System.out.println("lineItem.getQuantity(): " + lineItem.getQuantity());
                        System.out.println("mps.getMenuItem().getRecipe().getBroadLotSize()"
                                + mps.getMenuItem().getRecipe().getBroadLotSize());

                        MR2.setQuantity(MR2.getQuantity() + mps.getAmount_week2() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        em.merge(MR2);
                        System.out.println("merge-MR2.getQuantity(): " + MR2.getQuantity());
                    }

                    calendar.set(Calendar.WEEK_OF_MONTH, 3);
                    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                    System.out.println("calendar.get(Calendar.DAY_OF_MONTH) week3 :"
                            + calendar.get(Calendar.DAY_OF_MONTH));
                    Query query3 = em.createQuery(
                            "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id =?3 and mr.day = ?4 ")
                            .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                            .setParameter(3, schedule.getId())
                            .setParameter(4, calendar.get(Calendar.DAY_OF_MONTH));
                    if (query3.getResultList().isEmpty()) {
                        MaterialRequirementEntity MR3 = new MaterialRequirementEntity();
                        MR3.setStore(store);
                        MR3.setMps(mps);
                        MR3.setRawIngredient((RawIngredientEntity) lineItem.getItem());
                        MR3.setQuantity(mps.getAmount_week3() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        MR3.setSchedule(schedule);
                        MR3.setDay(calendar.get(Calendar.DAY_OF_MONTH));
                        em.persist(MR3);
                    } else {
                        MaterialRequirementEntity MR3 = (MaterialRequirementEntity) query3.getResultList()
                                .get(0);
                        MR3.setQuantity(MR3.getQuantity() + mps.getAmount_week3() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        em.merge(MR3);
                    }

                    calendar.set(Calendar.WEEK_OF_MONTH, 4);
                    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                    System.out.println("calendar.get(Calendar.DAY_OF_MONTH) week4 :"
                            + calendar.get(Calendar.DAY_OF_MONTH));
                    Query query4 = em.createQuery(
                            "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id =?3 and mr.day = ?4 ")
                            .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                            .setParameter(3, schedule.getId())
                            .setParameter(4, calendar.get(Calendar.DAY_OF_MONTH));
                    if (query4.getResultList().isEmpty()) {
                        MaterialRequirementEntity MR4 = new MaterialRequirementEntity();
                        MR4.setStore(store);
                        MR4.setMps(mps);
                        MR4.setRawIngredient((RawIngredientEntity) lineItem.getItem());
                        MR4.setQuantity(mps.getAmount_week4() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        MR4.setSchedule(schedule);
                        MR4.setDay(calendar.get(Calendar.DAY_OF_MONTH));
                        em.persist(MR4);
                    } else {
                        MaterialRequirementEntity MR4 = (MaterialRequirementEntity) query4.getResultList()
                                .get(0);
                        MR4.setQuantity(MR4.getQuantity() + mps.getAmount_week4() * lineItem.getQuantity()
                                / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                        em.merge(MR4);
                    }

                    if (mps.getAmount_week5() != 0) {
                        calendar.set(Calendar.WEEK_OF_MONTH, 5);
                        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
                        System.out.println("calendar.get(Calendar.DAY_OF_MONTH) week5 :"
                                + calendar.get(Calendar.DAY_OF_MONTH));
                        Query query5 = em.createQuery(
                                "select mr from MaterialRequirementEntity mr where mr.store.id = ?1 and mr.rawIngredient.SKU = ?2 and mr.schedule.id =?3 and mr.day = ?4 ")
                                .setParameter(1, storeId).setParameter(2, lineItem.getItem().getSKU())
                                .setParameter(3, schedule.getId())
                                .setParameter(4, calendar.get(Calendar.DAY_OF_MONTH));
                        if (query5.getResultList().isEmpty()) {
                            MaterialRequirementEntity MR5 = new MaterialRequirementEntity();
                            MR5.setStore(store);
                            MR5.setMps(mps);
                            MR5.setRawIngredient((RawIngredientEntity) lineItem.getItem());
                            MR5.setQuantity(mps.getAmount_week5() * lineItem.getQuantity()
                                    / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                            MR5.setSchedule(schedule);
                            MR5.setDay(calendar.get(Calendar.DAY_OF_MONTH));
                            em.persist(MR5);
                        } else {
                            MaterialRequirementEntity MR5 = (MaterialRequirementEntity) query5.getResultList()
                                    .get(0);
                            MR5.setQuantity(MR5.getQuantity() + mps.getAmount_week5() * lineItem.getQuantity()
                                    / mps.getMenuItem().getRecipe().getBroadLotSize() + 1);
                            em.merge(MR5);
                        }
                    }
                }
            }
        }
        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return false;
}

From source file:org.openmrs.module.formentry.FormEntryUtil.java

/**
 * Replaces %Y in the string with the four digit year. Replaces %M with the two digit month
 * Replaces %D with the two digit day Replaces %w with week of the year Replaces %W with week of
 * the month/*  w ww.j  ava 2  s .  c o  m*/
 * 
 * @param str String filename containing variables to replace with date strings
 * @return String with variables replaced
 */
public static String replaceVariables(String str, Date d) {

    Calendar calendar = Calendar.getInstance();
    if (d != null)
        calendar.setTime(d);

    int year = calendar.get(Calendar.YEAR);
    str = str.replace("%Y", Integer.toString(year));

    int month = calendar.get(Calendar.MONTH) + 1;
    String monthString = Integer.toString(month);
    if (month < 10)
        monthString = "0" + monthString;
    str = str.replace("%M", monthString);

    int day = calendar.get(Calendar.DATE);
    String dayString = Integer.toString(day);
    if (day < 10)
        dayString = "0" + dayString;
    str = str.replace("%D", dayString);

    int week = calendar.get(Calendar.WEEK_OF_YEAR);
    String weekString = Integer.toString(week);
    if (week < 10)
        weekString = "0" + week;
    str = str.replace("%w", weekString);

    int weekmonth = calendar.get(Calendar.WEEK_OF_MONTH);
    String weekmonthString = Integer.toString(weekmonth);
    if (weekmonth < 10)
        weekmonthString = "0" + weekmonthString;
    str = str.replace("%W", weekmonthString);

    return str;
}

From source file:info.raack.appliancelabeler.web.MainController.java

private void createOneWeekSpan(EnergyMonitor energyMonitor, Date start, Date end) {
    int period = Calendar.WEEK_OF_MONTH;

    createDateSpan(energyMonitor, start, end, period);
}

From source file:com.xxl.report.service.ReportService.java

private Calendar getNextRunningDate(int type) {
    Calendar cal = Calendar.getInstance();
    switch (type) {
    case SemAppConstants.REPORT_SCHEDULE_ONCE: {
        break;//w ww  . j a  v a  2 s .c o  m
    }
    case SemAppConstants.REPORT_SCHEDULE_HOUR: {
        cal.add(Calendar.HOUR, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_WEEK: {
        cal.add(Calendar.WEEK_OF_MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_DAY: {
        cal.add(Calendar.DAY_OF_MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_MONTH: {
        cal.add(Calendar.MONTH, 1);
        break;
    }
    case SemAppConstants.REPORT_SCHEDULE_YEAR: {
        cal.add(Calendar.YEAR, 1);
        break;
    }
    }
    return cal;
}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static Timestamp getWeekStart(Timestamp stamp, int daysLater, int weeksLater, TimeZone timeZone,
        Locale locale) {/*from w w w. jav  a  2  s. c  o  m*/
    Calendar tempCal = toCalendar(stamp, timeZone, locale);
    tempCal.set(tempCal.get(Calendar.YEAR), tempCal.get(Calendar.MONTH), tempCal.get(Calendar.DAY_OF_MONTH), 0,
            0, 0);
    tempCal.add(Calendar.DAY_OF_MONTH, daysLater);
    tempCal.set(Calendar.DAY_OF_WEEK, tempCal.getFirstDayOfWeek());
    tempCal.add(Calendar.WEEK_OF_MONTH, weeksLater);
    Timestamp retStamp = new Timestamp(tempCal.getTimeInMillis());
    retStamp.setNanos(0);
    return retStamp;
}

From source file:DateFormatUtils.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 * //from   w  w  w  .j a  v  a  2 s .com
 * @return a <code>List</code> of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 */
protected List parsePattern() {
    DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    List rules = new ArrayList();

    String[] ERAs = symbols.getEras();
    String[] months = symbols.getMonths();
    String[] shortMonths = symbols.getShortMonths();
    String[] weekdays = symbols.getWeekdays();
    String[] shortWeekdays = symbols.getShortWeekdays();
    String[] AmPmStrings = symbols.getAmPmStrings();

    int length = mPattern.length();
    int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen >= 4) {
                rule = selectNumberRule(Calendar.YEAR, tokenLen);
            } else {
                rule = TwoDigitYearField.INSTANCE;
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:es.sm2.openppm.front.servlets.ProjectControlServlet.java

/**
  * Generate Histogram Chart//from  ww w .j a v a  2s .  co  m
  * 
  * @param req
  * @param resp
  * @throws IOException
  */
private void histogramChartJX(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    int idProject = ParamUtil.getInteger(req, Project.IDPROJECT);
    Date since = ParamUtil.getDate(req, "since", getDateFormat(req));
    Date until = ParamUtil.getDate(req, "until", getDateFormat(req));

    JSONArray dataSeries = new JSONArray();
    JSONArray categories = new JSONArray();
    JSONArray legend = new JSONArray();

    PrintWriter out = resp.getWriter();

    try {

        TimesheetLogic timesheetLogic = new TimesheetLogic();
        TeamMemberLogic memberLogic = new TeamMemberLogic();
        JobcategoryLogic jobLogic = new JobcategoryLogic();

        Calendar sinceCal = DateUtil.getCalendar();
        sinceCal.setTime(DateUtil.getFirstWeekDay(since));

        Calendar untilCal = DateUtil.getCalendar();
        untilCal.setTime(DateUtil.getLastWeekDay(until));

        while (!sinceCal.after(untilCal)) {

            int sinceDay = sinceCal.get(Calendar.DAY_OF_MONTH);
            Calendar calWeek = DateUtil.getLastWeekDay(sinceCal);
            int untilDay = calWeek.get(Calendar.DAY_OF_MONTH);

            categories.add(sinceDay + "-" + untilDay + " "
                    + getResourceBundle(req).getString("month.min_" + (calWeek.get(Calendar.MONTH) + 1)) + " "
                    + dfYear.format(calWeek.getTime()));

            sinceCal.add(Calendar.WEEK_OF_MONTH, 1);
        }

        List<Teammember> members = memberLogic.consStaffinActualsFtes(new Project(idProject), since, until);

        List<Jobcategory> jobs = jobLogic.findByRelation(Jobcategory.COMPANY, getCompany(req), Jobcategory.NAME,
                Constants.ASCENDENT);

        int i = 0;
        for (Jobcategory job : jobs) {

            sinceCal.setTime(DateUtil.getFirstWeekDay(since));

            JSONArray series = new JSONArray();

            while (!sinceCal.after(untilCal)) {

                double resources = 0;

                for (Teammember member : members) {

                    if (member.getJobcategory() != null
                            && job.getIdJobCategory().equals(member.getJobcategory().getIdJobCategory())
                            && DateUtil.betweenWeek(member.getDateIn(), member.getDateOut(),
                                    sinceCal.getTime())) {

                        Double fte = timesheetLogic.getFte(new Project(idProject), member,
                                DateUtil.getFirstWeekDay(sinceCal.getTime()),
                                DateUtil.getLastWeekDay(sinceCal.getTime()));

                        resources += fte;
                    }
                }
                series.add((resources > 0 ? resources / 100 : 0));

                sinceCal.add(Calendar.WEEK_OF_MONTH, 1);
            }

            // Paint if values exist
            Boolean existValues = false;
            int index = 0;

            while (index < series.size() && !existValues) {

                if (series.getDouble(index) != 0.0) {
                    existValues = true;
                }

                index += 1;
            }

            if (existValues) {

                legend.add(ChartUtil.getLegend(job.getName(), ++i));

                dataSeries.add(series);
            }
        }

        legend.add(ChartUtil.getLegend(getResourceBundle(req).getString("not_defined"), 0));

        sinceCal.setTime(DateUtil.getFirstWeekDay(since));

        JSONArray series = new JSONArray();

        while (!sinceCal.after(untilCal)) {

            double resources = 0;

            for (Teammember member : members) {

                if (member.getJobcategory() == null
                        && DateUtil.betweenWeek(member.getDateIn(), member.getDateOut(), sinceCal.getTime())) {

                    Double fte = timesheetLogic.getFte(new Project(idProject), member,
                            DateUtil.getFirstWeekDay(sinceCal.getTime()),
                            DateUtil.getLastWeekDay(sinceCal.getTime()));

                    resources += fte;
                }

            }
            series.add((resources > 0 ? resources / 100 : 0));

            sinceCal.add(Calendar.WEEK_OF_MONTH, 1);
        }

        dataSeries.add(series);

        JSONObject chartJSON = new JSONObject();

        chartJSON.put("categories", categories);
        chartJSON.put("dataSeries", dataSeries);
        chartJSON.put("legend", legend);

        out.print(chartJSON);
    } catch (Exception e) {
        ExceptionUtil.evalueExceptionJX(out, req, getResourceBundle(req), LOGGER, e);
    } finally {
        out.close();
    }
}