Example usage for java.util Calendar SUNDAY

List of usage examples for java.util Calendar SUNDAY

Introduction

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

Prototype

int SUNDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Sunday.

Usage

From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java

private Integer obtieneDia(String dia) {
    switch (dia) {
    case "domingo":
        return Calendar.SUNDAY;
    case "lunes":
        return Calendar.MONDAY;
    case "martes":
        return Calendar.TUESDAY;
    case "miercoles":
        return Calendar.WEDNESDAY;
    case "jueves":
        return Calendar.THURSDAY;
    case "viernes":
        return Calendar.FRIDAY;
    default://w  ww .j a v  a  2  s  . c  o m
        return Calendar.SATURDAY;
    }
}

From source file:cs.umass.edu.prepare.view.custom.CalendarAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;/*from  w w  w. j a v a2  s .  co m*/
    TextView dayView;
    if (convertView == null) { // if it's not recycled, initialize some attributes
        v = View.inflate(context, R.layout.calendar_item, null);
    }

    ViewGroup insertPoint = (ViewGroup) v.findViewById(R.id.layout_calendar_item);
    insertPoint.removeAllViews();

    dayView = (TextView) View.inflate(context, R.layout.textview_date, null);
    insertPoint.addView(dayView);

    // disable empty days from the beginning
    if (dateStrings[position].equals("")) {
        dayView.setClickable(false);
        dayView.setFocusable(false);
    } else {
        v.setBackgroundResource(R.drawable.list_item_background);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, month.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, month.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStrings[position]));
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (month.get(Calendar.YEAR) == selectedDate.get(Calendar.YEAR)
                && month.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH)
                && dateStrings[position].equals("" + selectedDate.get(Calendar.DAY_OF_MONTH))) {
            int selectedColor = ContextCompat.getColor(context,
                    R.color.color_calendar_item_background_selected);
            v.setBackgroundColor(selectedColor);
        } else if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
            dayView.setTextColor(Color.GRAY);
        }
    }
    dayView.setText(dateStrings[position]);

    // create date string for comparison
    String dateStr = dateStrings[position];

    if (displayType == DisplayType.BASIC) {
        v.setMinimumHeight(0);
        return v; // do not populate cells
    }
    v.setMinimumHeight(325); // TODO: not device independent

    if (medications == null || adherenceData == null) {
        Log.w(TAG, "Warning : No adherenceData found.");
        return v; // do not populate cells
    }

    if (dateStr.equals(""))
        return v;

    Calendar dateKey = Utils.getDateKey(month.get(Calendar.YEAR), month.get(Calendar.MONTH),
            Integer.parseInt(dateStr));
    if (adherenceData.containsKey(dateKey)) {
        populateCell(dateKey, insertPoint);
    }

    return v;
}

From source file:voldemort.scheduled.DataCleanupJobTest.java

public void testCleanupStartTime() {
    // Make sure the default is always the next day.
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals("Default is not tomorrow", Utils.getDayOfTheWeekFromNow(1),
            (cal.get(Calendar.DAY_OF_WEEK) + 1) % 7);

    // When starting the server any day in the week from SUN to FRI and
    // targeting a saturday, should always start on the next saturday
    GregorianCalendar expectedStart = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 0, 0, 0);
    Random rand = new Random();
    for (int day = Calendar.SUNDAY; day <= Calendar.FRIDAY; day++) {
        GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 22 + day,
                rand.nextInt(24), rand.nextInt(60), rand.nextInt(60));
        GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0);
        assertEquals(/*from  w ww .j av  a2  s  .c  om*/
                "Expected :" + expectedStart.getTimeInMillis() + " Computed: "
                        + computedStart.getTimeInMillis(),
                expectedStart.getTimeInMillis(), computedStart.getTimeInMillis());
    }

    // Targeting saturday, 00:00 and starting on a friday 23:59:59 should
    // start the next saturday
    GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 28, 23, 59, 59);
    GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0);
    assertEquals(
            "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(),
            expectedStart.getTimeInMillis(), computedStart.getTimeInMillis());

    // If we start past the start hour on the target day, it should start
    // the next week
    serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 1, 0, 1);
    computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0);
    assertEquals(Calendar.SATURDAY, computedStart.get(Calendar.DAY_OF_WEEK));
    assertEquals(serverStartTime.get(Calendar.DAY_OF_YEAR) + 7, computedStart.get(Calendar.DAY_OF_YEAR));
}

From source file:com.virtusa.akura.attendance.controller.DailyAttendanceController.java

/**
 * Method is to return date list.//from w  w w .jav a  2 s.  c  o m
 * 
 * @return current date - String
 * @throws AkuraAppException - throw SMSExeption.
 */
@ModelAttribute(MODEL_ATT_CURRENT_DATE)
public List<String> populateDateList() throws AkuraAppException {

    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    List<Holiday> holidayList = getHolidayList(String.valueOf(year));
    List<String> dateList = new ArrayList<String>();

    while (true) {
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == Calendar.SATURDAY) {
            calendar.add(Calendar.DATE, -1);

        } else if (dayOfWeek == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, CONSTANT_MINUS_TWO);

        } else {

            Date date = calendar.getTime();
            if (!DateUtil.isHoliday(holidayList, DateUtil.getParseDate(DateUtil.getFormatDate(date)))) {
                dateList.add(DateUtil.getFormatDate(date));
                calendar.add(Calendar.DATE, -1);
            } else {
                calendar.add(Calendar.DATE, -1);
            }

        }

        if (dateList.size() == CONSTANT_FIVE) {
            break;
        }

    }

    return dateList;
}

From source file:GenAppStoreSales.java

/**
 * Starting point for the demonstration application.
 * @throws IOException // w  w w  .ja va  2  s  . c o m
 * 
 */
public static void main(String[] args) throws IOException {
    System.out.print("\nRefreshing Apple Store Reports...");

    // Init Calendars
    rollCalendar = Calendar.getInstance();
    updateRollCalendar();
    currentYear = rollCalendar.get(Calendar.YEAR);
    currentMonth = rollCalendar.get(Calendar.MONTH) + 1;
    currentDay = rollCalendar.get(Calendar.DATE);
    Calendar launchCalendar = Calendar.getInstance();
    int launchYear = 2013, launchMonth = 2, launchDay = 28; //Month from 0..11
    launchCalendar.set(launchYear, launchMonth, launchDay);
    /* Report Folders
     */
    currentPath = new File("").getAbsolutePath();
    String sourceName = "/sources";
    File sourceDir = new File(currentPath, sourceName);
    if (!sourceDir.isDirectory()) {
        if (!(new File(currentPath + sourceName)).mkdirs()) {
            System.out.println("[Error] Couldn't create 'source' folder.");
        }
    }
    sourcePath = sourceDir.getAbsolutePath();

    String chartName = "/charts";
    File chartDir = new File(currentPath, chartName);
    if (!chartDir.isDirectory()) {
        if (!(new File(currentPath + chartName)).mkdirs()) {
            System.out.println("[Error] Couldn't create 'chart' folder.");
        }
    }
    chartPath = chartDir.getAbsolutePath();

    String dateCode, reportName;

    // DAILY REPORT
    System.out.println("\n-> Daily reports");
    for (int d = 0; d < 14; d++) {
        rollCalendar.add(Calendar.DATE, -1);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        reportName = "S_D_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Daily", dateCode);
    }
    printDatePeriod("DAILY", "report");

    // WEEKLY REPORT
    System.out.println("\n-> Weekly reports");
    rollCalendar = Calendar.getInstance();
    rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    pursuedDay = currentDay;
    pursuedMonth = currentMonth;
    pursuedYear = currentYear;
    for (int w = 0; w < 13; w++) {
        rollCalendar.add(Calendar.DATE, -7);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        reportName = "S_W_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Weekly", dateCode);
    }
    printDatePeriod("WEEKLY", "report");

    // MONTHLY REPORTS
    System.out.println("\n-> Monthly reports");
    rollCalendar = Calendar.getInstance();
    pursuedDay = currentDay;
    pursuedMonth = currentMonth - 1;
    pursuedYear = currentYear;
    for (int m = 0; m < 12; m++) {
        rollCalendar.add(Calendar.MONTH, -1);
        rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d%02d", pursuedYear, pursuedMonth);
        reportName = "S_M_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Monthly", dateCode);
    }
    printDatePeriod("MONTHLY", "report");

    // YEARLY REPORTS
    System.out.println("\n-> Yearly reports");
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.DATE, -1);
    pursuedDay = currentDay - 1;
    pursuedMonth = currentMonth;
    pursuedYear = currentYear;
    for (int y = 0; y < 100; y++) {
        rollCalendar.add(Calendar.YEAR, -1);
        if (rollCalendar.compareTo(launchCalendar) <= 0)
            break;
        updateRollCalendar();
        dateCode = String.format("%d", pursuedYear);
        reportName = "S_Y_" + appID + "_" + dateCode + ".txt";
        autoingestionDownload(reportName, "Yearly", dateCode);
    }
    printDatePeriod("YEARLY", "report");

    /**
     * Reading Sales.txt & Generating Charts
     */
    // WEEK CHARTS
    String plotName, pursuedPeriodDate;
    System.out.print("\nRestoring charts...\n");
    System.out.println("-> Week charts");
    rollCalendar = Calendar.getInstance();
    rollCalendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    rollCalendar.add(Calendar.DATE, -7);
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_W_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("week", true, true);
            if (countryLabels.size() > 0) {
                genPlot("WEEK", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("WEEK IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels,
                        countryInAppUnits);
            }
        } else
            readSales("week", false, true);// Week already plotted
    }
    printDatePeriod("WEEK", "charts");

    // Incomplete current Week (let the current day be computed)
    rollCalendar = Calendar.getInstance();
    updateRollCalendar();
    readSales("week", false, true);
    // MONTH CHARTS
    System.out.println("\n-> Month charts");
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.MONTH, -1);
    rollCalendar.set(Calendar.DATE, rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_M_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("month", true, false);
            if (countryLabels.size() > 0) {
                genPlot("MONTH", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("MONTH", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits);
            }
        } else {
            readSales("month", false, false);
        }

    }
    printDatePeriod("MONTH", "charts");

    // YEAR CHARTS
    System.out.println("\n-> Year charts");
    rollCalendar = (Calendar) launchCalendar.clone();
    rollCalendar.set(Calendar.DATE, -1);
    rollCalendar.add(Calendar.YEAR, -1);
    updateRollCalendar();
    while (rollCalendar.compareTo(launchCalendar) > 0) {
        pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
        dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
        plotName = "S_Y_" + appID + "_" + dateCode;
        File plotFile = new File(chartPath + "/" + plotName + ".png");
        if (!plotFile.isFile()) {
            readSales("year", true, false);
            if (countryLabels.size() > 0) {
                genPlot("YEAR", plotName, pursuedPeriodDate, countryLabels, countryUnits);
            }
            if (countryInAppLabels.size() > 0) {
                genPlot("YEAR", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels, countryInAppUnits);
            }
        } else
            readSales("year", false, false);
    }
    printDatePeriod("YEAR", "charts");

    // CUSTOM CHART PERIOD
    System.out.println("\n-> Custom charts");
    customCalendar = (Calendar) launchCalendar.clone(); // begin day
    rollCalendar = Calendar.getInstance(); // end day
    rollCalendar.add(Calendar.DATE, -1);
    updateRollCalendar();
    pursuedPeriodDate = String.format("%d.%d.%d", pursuedDay, pursuedMonth, pursuedYear);
    dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay);
    plotName = "S_C_" + appID + "__whole";// + dateCode;
    File plotFile = new File(chartPath + "/" + plotName + ".png");
    if (!plotFile.isFile()) {
        readSales("custom", true, false);
        if (countryLabels.size() > 0) {
            genPlot("CUSTOM", plotName, pursuedPeriodDate, countryLabels, countryUnits);
        }
        if (countryInAppLabels.size() > 0) {
            genPlot("CUSTOM IN-APP", plotName + "_InApp", pursuedPeriodDate, countryInAppLabels,
                    countryInAppUnits);
        }
    }
    printDatePeriod("CUSTOM Period", "charts");

    // Day Sales units
    rollCalendar = Calendar.getInstance();
    rollCalendar.add(Calendar.DATE, -1);
    updateRollCalendar();
    readSales("day", false, false);

    System.out.println("\nTotal units: " + totalUnits + "/" + totalUpdateUnits + "-Up (+" + dayUnits + ")");
    System.out.println("Total IN-APP units: " + totalInAppUnits + " (+" + dayINAPPUnits + ")\n");
    System.exit(0);
}

From source file:com.xumpy.timesheets.services.implementations.JobsSrvImpl.java

public static boolean jobInWeekend(Jobs jobs) {
    Date date = jobs.getJobDate();

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from w  w w .jav  a 2  s .c  o  m

    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY
            || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        return true;
    }

    return false;
}

From source file:com.netflix.simianarmy.basic.BasicCalendar.java

private boolean isWeekend(Calendar calendar) {
    int dow = calendar.get(Calendar.DAY_OF_WEEK);
    return dow == Calendar.SATURDAY || dow == Calendar.SUNDAY;
}

From source file:org.openmrs.web.servlet.QuickReportServlet.java

private void doAttendedClinic(VelocityContext velocityContext, PrintWriter report, HttpServletRequest request)
        throws ServletException {
    EncounterService es = Context.getEncounterService();
    LocationService ls = Context.getLocationService();

    DateFormat dateFormat = Context.getDateFormat();
    velocityContext.put("date", dateFormat);

    Calendar cal = Calendar.getInstance();

    Date start;/*  ww w.j  a  v a 2s .c  om*/
    Date end;

    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");
    String location = request.getParameter("location");

    if (startDate != null && startDate.length() != 0) {
        try {
            cal.setTime(dateFormat.parse(startDate));
        } catch (ParseException e) {
            throw new ServletException("Error parsing 'Start Date'", e);
        }
    } else {
        cal.setTime(new Date());
    }

    // if they don't input an end date, assume they meant "this week"
    if (endDate == null || "".equals(endDate)) {
        while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        start = cal.getTime();
        cal.add(Calendar.DAY_OF_MONTH, 7);
        end = cal.getTime();
    } else {
        // they put in an end date, assume literal start and end
        start = cal.getTime();
        try {
            cal.setTime(dateFormat.parse(endDate));
        } catch (ParseException e) {
            throw new ServletException("Error parsing 'End Date'", e);
        }
        end = cal.getTime();
    }

    Collection<Encounter> encounters = null;

    if (location == null || "".equals(location)) {
        EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder()
                .setIncludeVoided(true).setFromDate(start).setToDate(end).createEncounterSearchCriteria();
        encounters = es.getEncounters(encounterSearchCriteria);
    } else {
        Location locationObj = ls.getLocation(Integer.valueOf(location));
        EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder()
                .setIncludeVoided(true).setLocation(locationObj).setFromDate(start).setToDate(end)
                .createEncounterSearchCriteria();
        encounters = es.getEncounters(encounterSearchCriteria);
    }

    if (encounters != null) {
        velocityContext.put("encounters", encounters);
    } else {
        report.append("No Encounters found");
    }
}

From source file:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java

public UserHolidaysState calcUserHolidaysState(User usuario, Date chargeYear) {
    UserHolidaysState uhs = new UserHolidaysState();
    uhs.setUser(usuario);// w ww  . ja  va 2s . co  m
    // WorkingAgreement attribute is an HB proxy not initialized, we need to get it from DB
    WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault();
    WorkingAgreement agreement = workingAgreementDao.getById(usuario.getAgreement().getId());
    // and refresh the user instance agreement attribute
    usuario.setAgreement(agreement);

    uhs.setTotalYear(agreement.getHolidays());

    int acceptedHolidays = 0;

    if (chargeYear != null) {

        HolidayManager fiestasManager = HolidayManager.getDefault();

        // We must take in account previous year holidays and next year holidays

        Calendar calMin = Calendar.getInstance();
        calMin.setTime(chargeYear);
        calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH));
        calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH));
        calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY));
        calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE));
        calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND));
        calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND));

        Calendar calMax = Calendar.getInstance();
        calMax.setTime(chargeYear);
        calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH));
        calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH));
        calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY));
        calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE));
        calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND));
        calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND));

        calMin.add(Calendar.YEAR, -1);
        calMax.add(Calendar.YEAR, 1);

        HolidaySearch fiestaSearch = new HolidaySearch();
        fiestaSearch.setStartDate(calMin.getTime());
        fiestaSearch.setEndDate(calMax.getTime());

        List<Holiday> listFiestas = fiestasManager.getAllEntities(fiestaSearch, null);

        calMin.setTime(chargeYear);
        calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH));
        calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH));
        calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY));
        calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE));
        calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND));
        calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND));

        calMax.setTime(chargeYear);
        calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH));
        calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH));
        calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY));
        calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE));
        calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND));
        calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND));

        RequestHolidayManager holyManager = RequestHolidayManager.getDefault();
        RequestHolidaySearch holSearch = new RequestHolidaySearch();
        holSearch.setUserRequest(uhs.getUser());
        holSearch.setState(HolidayState.ACCEPT);
        holSearch.setStartChargeYear(calMin.getTime());
        holSearch.setEndChargeYear(calMax.getTime());

        List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null);

        for (RequestHoliday rH : listH) {
            Calendar cActual = Calendar.getInstance();
            cActual.setTime(rH.getBeginDate());
            while (!cActual.getTime().after(rH.getFinalDate())) {
                if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                        && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    boolean isFiesta = false;

                    for (Holiday fiest : listFiestas) {
                        Calendar cFiesta = Calendar.getInstance();
                        cFiesta.setTime(fiest.getDate());
                        if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR)
                                && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH)
                                && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) {
                            isFiesta = true;
                        }
                    }

                    if (!isFiesta) {
                        acceptedHolidays++;
                    }
                }

                cActual.add(Calendar.DAY_OF_MONTH, 1);
            }

        }
        uhs.setTotalAccepted(acceptedHolidays);

        Calendar calAuxCont = Calendar.getInstance();
        calAuxCont.setTime(uhs.getUser().getStartDate());

        Calendar calAux = Calendar.getInstance();
        calAux.setTime(chargeYear);
        int yearCharge = calAux.get(Calendar.YEAR);
        int yearContract = calAuxCont.get(Calendar.YEAR);

        if (yearCharge == yearContract) {
            // Dividimos los das de cada usuario entre los meses del ao.
            double ratio = uhs.getUser().getAgreement().getHolidays() / 12.0;
            int monthContract = calAuxCont.get(Calendar.MONTH);
            int meses = (Calendar.DECEMBER - monthContract);
            double diasVacaciones = meses * ratio;
            double aux = Math.ceil(diasVacaciones);
            uhs.setTotalYear((int) aux);
        }
    }

    return uhs;
}

From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java

private static String[] mapShortWeekdays(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}