Example usage for java.util Calendar MONDAY

List of usage examples for java.util Calendar MONDAY

Introduction

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

Prototype

int MONDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Monday.

Usage

From source file:de.kirchnerei.bicycle.battery.BatteryEditFragment.java

private void doPickBatteryDate() {

    final Calendar now = Calendar.getInstance();
    now.setTime(item.getDate());//from   ww w . j a  v a  2 s.c o m

    DatePickerDialog dlg = new DatePickerDialog(getActivity(),
            // TODO Define a Theme for the DatePickerDialog
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    synchronized (now) {
                        now.set(Calendar.YEAR, year);
                        now.set(Calendar.MONTH, monthOfYear);
                        now.set(Calendar.DATE, dayOfMonth);
                        updateDate(now.getTime());
                    }
                }
            }, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE));
    dlg.getDatePicker().setMaxDate(System.currentTimeMillis());
    dlg.getDatePicker().setFirstDayOfWeek(Calendar.MONDAY);
    dlg.show();
}

From source file:DateUtils.java

public static final String getDayString(int day) {
    switch (day) {
    case Calendar.SUNDAY:
        return "SUNDAY";
    case Calendar.MONDAY:
        return "MONDAY";
    case Calendar.TUESDAY:
        return "TUESDAY";
    case Calendar.WEDNESDAY:
        return "WEDNESDAY";
    case Calendar.THURSDAY:
        return "THURSDAY";
    case Calendar.FRIDAY:
        return "FRIDAY";
    case Calendar.SATURDAY:
        return "SATURDAY";
    }//from w  w w .j av  a2s .  co  m
    return "";
}

From source file:in.suraj.timetableswipe.BTechFragment.java

private void init() {
    rgroup = (RadioGroup) rootView.findViewById(R.id.rbgrp);
    rbMon = (RadioButton) rootView.findViewById(R.id.rbMon);
    rbTue = (RadioButton) rootView.findViewById(R.id.rbTue);
    rbWed = (RadioButton) rootView.findViewById(R.id.rbWed);
    rbThur = (RadioButton) rootView.findViewById(R.id.rbThur);
    rbFri = (RadioButton) rootView.findViewById(R.id.rbFri);

    tvLect1Name = (TextView) rootView.findViewById(R.id.tvLect1Name);
    tvLect1Prof = (TextView) rootView.findViewById(R.id.tvLect1Prof);

    tvLect2Name = (TextView) rootView.findViewById(R.id.tvLect2Name);
    tvLect2Prof = (TextView) rootView.findViewById(R.id.tvLect2Prof);

    tvLect3Name = (TextView) rootView.findViewById(R.id.tvLect3Name);
    tvLect3Prof = (TextView) rootView.findViewById(R.id.tvLect3Prof);

    tvLect4Name = (TextView) rootView.findViewById(R.id.tvLect4Name);
    tvLect4Prof = (TextView) rootView.findViewById(R.id.tvLect4Prof);

    tvLect5Name = (TextView) rootView.findViewById(R.id.tvLect5Name);
    tvLect5Prof = (TextView) rootView.findViewById(R.id.tvLect5Prof);

    Calendar c = Calendar.getInstance();
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

    if (Calendar.MONDAY == dayOfWeek) {
        setUpMonday();//from w  ww .j  ava2 s  . co m
    } else if (Calendar.TUESDAY == dayOfWeek) {
        setUpTuesday();
    } else if (Calendar.WEDNESDAY == dayOfWeek) {
        setUpWednesday();
    } else if (Calendar.THURSDAY == dayOfWeek) {
        setUpThursday();
    } else if (Calendar.FRIDAY == dayOfWeek) {
        setUpFriday();
    } else if (Calendar.SATURDAY == dayOfWeek) {
        tvLect1Name.setText("Saturday :)");
        tvLect1Name.setTextColor(Color.RED);
    } else if (Calendar.SUNDAY == dayOfWeek) {
        tvLect1Name.setText("Sunday :)");
        tvLect1Name.setTextColor(Color.RED);
    }
}

From source file:org.eevolution.form.CRP.java

/**
 * Create Category Dataset based on date start and resource
 * @param start//from w  ww  .j  a  v a 2  s. com
 * @param resource
 * @return CategoryDataset
 */
protected CategoryDataset createDataset(Timestamp start, MResource resource) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID());
    int days = 1;
    long hours = t.getTimeSlotHours();

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    //      Long Hours = new Long(hours);                            
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ",
            resource.getS_Resource_ID());
    MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID);
    if (!uom.isHour()) {
        return dataset;
    }
    long summary = 0;

    while (days < 32) {
        String day = new String(new Integer(date.getDate()).toString());
        long HoursLoad = getLoad(resource, date).longValue();
        Long Hours = new Long(hours);

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            days++;
            if (t.isOnSunday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.MONDAY:
            days++;
            if (t.isOnMonday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.TUESDAY:
            days++;
            if (t.isOnTuesday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.WEDNESDAY:
            days++;
            if (t.isOnWednesday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.THURSDAY:
            days++;
            if (t.isOnThursday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.FRIDAY:
            days++;
            if (t.isOnFriday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.SATURDAY:
            days++;
            if (t.isOnSaturday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        }

    }
    return dataset;
}

From source file:Time.java

/**
 * Initialize the internal calendar instance.
 * /*from  ww  w .j  a  v  a 2s  . c  o  m*/
 * @param year
 *          Year of new day.
 * @param month
 *          Month of new day.
 * @param dayOfMonth
 *          Day of month of new day.
 */
private void initialize(int year, int month, int dayOfMonth) {
    calendar_ = Calendar.getInstance();
    calendar_.setLenient(true);
    calendar_.setFirstDayOfWeek(Calendar.MONDAY);
    calendar_.setTimeZone(TimeZone.getTimeZone("GMT"));
    set(year, month, dayOfMonth);
}

From source file:org.callistasoftware.netcare.core.job.SystemAlarmJob.java

@Scheduled(fixedRate = 3600000)
public void alarmJob() {
    log.info("======== ALARM JOB STARTED =========");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -(HealthPlanServiceImpl.SCHEMA_HISTORY_DAYS));
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    cal.add(Calendar.DATE, -1);//  w ww  .ja v  a 2 s .  c o m
    ApiUtil.dayEnd(cal);

    /*
     * Create alarm for health plans that is about to expire
     */
    plans(cal.getTime());

    /*
     * Create alarm for activities that is about to expire
     */
    activities(cal.getTime());

    log.info("======== ALARM JOB COMPLETED =========");
}

From source file:nl.strohalm.cyclos.utils.TimePeriod.java

/**
 * Returns the previous full period that does not include the given date. Example: date = 2007-02-15, field = month, number = 2 returns a period
 * of 2 months from 2006-12-01 to 2007-01-31
 *//*  w  w  w. j  a  va  2  s.c  o  m*/
public Period previousPeriod(final Calendar date) {
    Calendar end;
    if (field == Field.WEEKS) {
        // Weeks are not supported on DateUtils.truncate, so, go back to the last monday, and get weeks before
        end = DateHelper.truncate(date);
        while (end.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
            end.add(Calendar.DATE, -1);
        }
    } else {
        end = DateUtils.truncate(date, field.getCalendarValue());
    }
    return periodEndingAt(end);
}

From source file:com.idega.block.cal.renderer.AbstractCompactScheduleRenderer.java

/**
 * <p>//from   www .  j av  a2s  . c o  m
 * Draw one day in the schedule
 * </p>
 * 
 * @param context
 *            the FacesContext
 * @param writer
 *            the ResponseWriter
 * @param schedule
 *            the schedule
 * @param day
 *            the day that should be drawn
 * @param cellWidth
 *            the width of the cell
 * @param dayOfWeek
 *            the day of the week
 * @param dayOfMonth
 *            the day of the month
 * @param isWeekend
 *            is it a weekend day?
 * @param isCurrentMonth
 *            is the day in the currently selected month?
 * @param rowspan
 *            the rowspan for the table cell
 * 
 * @throws IOException
 *             when the cell could not be drawn
 */
protected void writeDayCell(FacesContext context, ResponseWriter writer, HtmlSchedule schedule, ScheduleDay day,
        float cellWidth, int dayOfWeek, int dayOfMonth, boolean isWeekend, boolean isCurrentMonth, int rowspan)
        throws IOException {

    final String clientId = schedule.getClientId(context);
    final Map<String, Object> attributes = schedule.getAttributes();
    final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context);
    final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName();

    TimeZone tz = TimeZone.getDefault();
    final String dayHeaderId = clientId + "_header_" + ScheduleUtil.getDateId(day.getDate(), tz);
    final String dayBodyId = clientId + "_body_" + ScheduleUtil.getDateId(day.getDate(), tz);

    boolean isMonthMode = false;
    boolean isWeekMode = false;

    boolean isFirstInARow = false;

    if (cellWidth == 100f / 6) {
        isMonthMode = true;
    } else if (cellWidth == 50f) {
        isWeekMode = true;
    }

    if ((dayOfWeek != Calendar.SUNDAY) && isMonthMode) {
        writer.startElement(HTML.DIV_ELEM, schedule);
    }
    if (isWeekMode && (dayOfWeek != Calendar.SUNDAY)) {
        writer.startElement(HTML.DIV_ELEM, schedule);
    }
    String dayClass = null;
    if (isWeekMode) {
        dayClass = "";
    } else {
        dayClass = getStyleClass(schedule, isCurrentMonth ? "day" : "inactive-day") + " "
                + getStyleClass(schedule, isWeekend ? "weekend" : "workday");
    }

    // add class for sunday

    if ((dayOfWeek == Calendar.MONDAY) || (dayOfWeek == Calendar.WEDNESDAY) || (dayOfWeek == Calendar.FRIDAY)// ||
    ) {
        isFirstInARow = true;
    }

    if (dayOfWeek == Calendar.SUNDAY) {
        dayClass += " sunday";
    }

    if (dayOfWeek == Calendar.SATURDAY) {
        dayClass += " saturday";
    }

    if ((dayOfWeek != Calendar.SUNDAY) && isMonthMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, "workdaytest", null);

    }
    if ((dayOfWeek != Calendar.SUNDAY) && isWeekMode) {
        if (isFirstInARow) {
            writer.writeAttribute(HTML.CLASS_ATTR, "weekTest firstInAWeekRow", null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, "weekTest secondInAWeekRow", null);
        }
    }

    // determine the height of the day in pixels
    StringBuffer styleBuffer = new StringBuffer();

    int rowHeight = getRowHeight(attributes);
    String myRowHeight = "height: ";
    String myContentHeight = "height: ";

    if (rowHeight > 0) {
        if (isWeekend) {
            myRowHeight += (rowHeight / 2) + "px;";
            myContentHeight += ((rowHeight / 2) - 19) + "px;";
        } else {
            myRowHeight += (rowHeight + 1) + "px;"; //need to add 1 to get the weekends right
            myContentHeight += ((rowHeight + 1) - 18) + "px;"; //18 instead of 19, to get the weekends right
        }
    } else {
        myRowHeight += "100%;";
        myContentHeight += "100%;";
    }

    styleBuffer.append(myRowHeight);

    writer.startElement(HTML.DIV_ELEM, schedule);

    if (cellWidth == 50f) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "day weekMode"), null);
    } else {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "day monthMode"), null);
    }

    // day header
    writer.startElement(HTML.DIV_ELEM, schedule);

    if (isMonthMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "headerForMonthDay"), null);
    } else if (isWeekMode) {
        writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "headerForWeekDay"), null);
    }

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "header"), null);
    writer.writeAttribute(HTML.STYLE_ATTR, "height: 18px; width: 100%; overflow: hidden", null);
    writer.writeAttribute(HTML.ID_ATTR, dayHeaderId, null);
    //register an onclick event listener to a day header which will capture
    //the date
    if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
        writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                "fireScheduleDateClicked(this, event, '" + formId + "', '" + clientId + "');", null);
    }

    writer.writeText(getDateString(context, schedule, day.getDate()), null);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);

    // day content
    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "contentForMonthDay"), null);
    writer.startElement(HTML.DIV_ELEM, schedule);
    if (isMonthMode) {

        if ((dayOfWeek == Calendar.SUNDAY) || (dayOfWeek == Calendar.SATURDAY)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "weekendContent content"), null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "workdayContent content"), null);
        }

    } else {
        if ((dayOfWeek == Calendar.SUNDAY) || (dayOfWeek == Calendar.SATURDAY)) {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "weekendContentWeekMode content"),
                    null);
        } else {
            writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "workdayContentWeekMode content"),
                    null);
        }
    }

    // determine the height of the day content in pixels
    StringBuffer contentStyleBuffer = new StringBuffer();
    contentStyleBuffer.append(myContentHeight);
    //        contentStyleBuffer.append(" width: 100%;");
    writer.writeAttribute(HTML.STYLE_ATTR, contentStyleBuffer.toString(), null);

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "contentview"), null);

    //this extra div is required, because when a scrollbar is visible and
    //it is clicked, the fireScheduleTimeClicked() method is fired.
    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.STYLE_ATTR, "height: 100%; vertical-align: top;", null);

    writer.writeAttribute(HTML.ID_ATTR, dayBodyId, null);

    //register an onclick event listener to a day cell which will capture
    //the date
    if (!schedule.isReadonly() && schedule.isSubmitOnClick()) {
        writer.writeAttribute(HTML.ONMOUSEUP_ATTR,
                "fireScheduleTimeClicked(this, event, '" + formId + "', '" + clientId + "');", null);
    }

    writer.startElement(HTML.DIV_ELEM, schedule);
    writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%;", null);

    writeEntries(context, schedule, day, writer);

    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);
    writer.endElement(HTML.DIV_ELEM);

    if ((dayOfWeek != Calendar.SATURDAY) && isMonthMode) {
        writer.endElement(HTML.DIV_ELEM);
    }
    if (cellWidth == 50f && dayOfWeek != Calendar.SATURDAY) {
        writer.endElement(HTML.DIV_ELEM);
    }
}

From source file:Main.java

/**
 * This constructs an <code>Iterator</code> over each day in a date
 * range defined by a focus date and range style.
 *
 * For instance, passing Thursday, July 4, 2002 and a
 * <code>RANGE_MONTH_SUNDAY</code> will return an <code>Iterator</code>
 * that starts with Sunday, June 30, 2002 and ends with Saturday, August 3,
 * 2002, returning a Calendar instance for each intermediate day.
 *
 * This method provides an iterator that returns Calendar objects.
 * The days are progressed using {@link Calendar#add(int, int)}.
 *
 * @param focus  the date to work with/*from   w  ww .  j  a  va  2 s.c  o m*/
 * @param rangeStyle  the style constant to use. Must be one of
 * {@link DateUtils#RANGE_MONTH_SUNDAY}, 
 * {@link DateUtils#RANGE_MONTH_MONDAY},
 * {@link DateUtils#RANGE_WEEK_SUNDAY},
 * {@link DateUtils#RANGE_WEEK_MONDAY},
 * {@link DateUtils#RANGE_WEEK_RELATIVE},
 * {@link DateUtils#RANGE_WEEK_CENTER}
 * @return the date iterator
 * @throws IllegalArgumentException if the date is <code>null</code>
 * @throws IllegalArgumentException if the rangeStyle is invalid
 */
public static Iterator iterator(Calendar focus, int rangeStyle) {
    if (focus == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    Calendar start = null;
    Calendar end = null;
    int startCutoff = Calendar.SUNDAY;
    int endCutoff = Calendar.SATURDAY;
    switch (rangeStyle) {
    case RANGE_MONTH_SUNDAY:
    case RANGE_MONTH_MONDAY:
        //Set start to the first of the month
        start = truncate(focus, Calendar.MONTH);
        //Set end to the last of the month
        end = (Calendar) start.clone();
        end.add(Calendar.MONTH, 1);
        end.add(Calendar.DATE, -1);
        //Loop start back to the previous sunday or monday
        if (rangeStyle == RANGE_MONTH_MONDAY) {
            startCutoff = Calendar.MONDAY;
            endCutoff = Calendar.SUNDAY;
        }
        break;
    case RANGE_WEEK_SUNDAY:
    case RANGE_WEEK_MONDAY:
    case RANGE_WEEK_RELATIVE:
    case RANGE_WEEK_CENTER:
        //Set start and end to the current date
        start = truncate(focus, Calendar.DATE);
        end = truncate(focus, Calendar.DATE);
        switch (rangeStyle) {
        case RANGE_WEEK_SUNDAY:
            //already set by default
            break;
        case RANGE_WEEK_MONDAY:
            startCutoff = Calendar.MONDAY;
            endCutoff = Calendar.SUNDAY;
            break;
        case RANGE_WEEK_RELATIVE:
            startCutoff = focus.get(Calendar.DAY_OF_WEEK);
            endCutoff = startCutoff - 1;
            break;
        case RANGE_WEEK_CENTER:
            startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3;
            endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3;
            break;
        }
        break;
    default:
        throw new IllegalArgumentException("The range style " + rangeStyle + " is not valid.");
    }
    if (startCutoff < Calendar.SUNDAY) {
        startCutoff += 7;
    }
    if (startCutoff > Calendar.SATURDAY) {
        startCutoff -= 7;
    }
    if (endCutoff < Calendar.SUNDAY) {
        endCutoff += 7;
    }
    if (endCutoff > Calendar.SATURDAY) {
        endCutoff -= 7;
    }
    while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) {
        start.add(Calendar.DATE, -1);
    }
    while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) {
        end.add(Calendar.DATE, 1);
    }
    return new DateIterator(start, end);
}

From source file:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns the Week as a formatted string corresponding to the date code
 * @return The week label//from   w ww.  java2s .  c o  m
 * @param locale The locale used for display settings
 * @param strDate The date code
 */
public static String getWeekLabel(String strDate, Locale locale) {
    Calendar calendar = new GregorianCalendar();
    Calendar calendarFirstDay = new GregorianCalendar();
    Calendar calendarLastDay = new GregorianCalendar();
    calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate));

    int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    if (nDayOfWeek == 1) {
        nDayOfWeek = 8;
    }

    calendarFirstDay = calendar;
    calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek);
    calendarLastDay = (GregorianCalendar) calendarFirstDay.clone();
    calendarLastDay.add(Calendar.DATE, 6);

    String strFormat = AppPropertiesService.getProperty(Constants.PROPERTY_LABEL_FORMAT_DATE_OF_DAY);
    DateFormat formatDate = new SimpleDateFormat(strFormat, locale);
    String strLabelFirstDay = formatDate.format(calendarFirstDay.getTime());
    String strLabelLastDay = formatDate.format(calendarLastDay.getTime());
    calendarFirstDay.clear();
    calendarLastDay.clear();

    return strLabelFirstDay + "-" + strLabelLastDay;
}