Example usage for java.util Calendar DAY_OF_WEEK

List of usage examples for java.util Calendar DAY_OF_WEEK

Introduction

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

Prototype

int DAY_OF_WEEK

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

Click Source Link

Document

Field number for get and set indicating the day of the week.

Usage

From source file:com.karmick.android.citizenalert.alarm.AlarmAddActivity.java

protected ArrayList<String> setAlarmData() {

    ArrayList<String> errs = new ArrayList<String>();

    boolean day_checked = false;
    boolean chkd;
    chkd = alarm_isactive.isChecked();// w  w w  . j  av  a  2  s  . c om
    alarm.setAlarmActive(chkd);

    alarm.setAlarmName(alarm_message.getText().toString());
    // hard code for now [start]
    Alarm.Difficulty d = Alarm.Difficulty.values()[0];
    alarm.setDifficulty(d);
    alarm.setAlarmTonePath("content://settings/system/alarm_alert");
    alarm.setVibrate(false);
    // hard code for now [ends]

    if (alarm_days_mon.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.MONDAY);

    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.MONDAY);
        }
    }
    if (alarm_days_tue.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.TUESDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.TUESDAY);
        }
    }
    if (alarm_days_wed.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.WEDNESDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.WEDNESDAY);
        }
    }
    if (alarm_days_thu.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.THURSDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.THURSDAY);
        }
    }
    if (alarm_days_fri.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.FRIDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.FRIDAY);
        }
    }
    if (alarm_days_sat.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.SATURDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.SATURDAY);
        }
    }
    if (alarm_days_sun.isChecked()) {
        day_checked = true;
        alarm.addDay(Alarm.Day.SUNDAY);
    } else {

        if (alarm.getDays().length > 1) {
            alarm.removeDay(Alarm.Day.SUNDAY);
        }
    }

    if (contact_ids != null) {
        if (!contact_ids.isEmpty()) {
            alarm.setContact_ids(contact_ids);
        } else {
            errs.add("Please select atleast one contact.");
        }
    }

    if (!day_checked) {
        errs.add("Please select atleast one day.");
    }

    if (alarm_time.getText().toString().isEmpty()) {
        errs.add("Please enter alarm time");
    }

    int interval = 0;

    if (alarm_interval.getText().toString().isEmpty()) {

        errs.add("Please enter interval.");
    } else {
        interval = Integer.parseInt(alarm_interval.getText().toString());
        if (interval <= 0) {
            errs.add("Please enter interval greater than zero.");
        }
    }
    int counter = 0;

    if (alarm_counter.getText().toString().isEmpty()) {
        errs.add("Please enter counter.");
    } else {
        counter = Integer.parseInt(alarm_counter.getText().toString());
        if (counter <= 0) {
            errs.add("Please enter counter greater than zero.");
        }
    }

    // Checking if the calculated time is entring into next day or not
    int mu = interval * counter;
    Calendar _clndr0 = newAlarmTime;
    Calendar _clndr1 = newAlarmTime3;
    _clndr1.add(Calendar.MINUTE, mu);

    int day1 = _clndr1.get(Calendar.DAY_OF_WEEK);
    int day2 = _clndr0.get(Calendar.DAY_OF_WEEK);
    if (day1 != day2) {
        errs.add("Calulated time is entering into nex day.");
    }

    alarm.setAlarmTime(newAlarmTime);

    ArrayList<String> furtherAlarmTimes = new ArrayList<String>();
    Calendar clndr = newAlarmTime2;
    if (counter >= 1) {
        for (int c = 0; c < counter; c++) {
            furtherAlarmTimes.add(getAlarmTimeAsString(clndr));
            clndr.add(Calendar.SECOND, (interval * 60));
        }
    } else {
        furtherAlarmTimes.add(getAlarmTimeAsString(clndr));
    }

    alarm.setFurther_AlarmTimes(furtherAlarmTimes);
    alarm.setCounter(counter);
    alarm.setInterval(interval);

    return errs;
}

From source file:edu.dlnu.liuwenpeng.EachMintueTransactionSupport.SegmentedTimeline.java

/**    
* Returns the milliseconds for midnight of the first Monday after    
* 1-Jan-1900, ignoring daylight savings.    
*    //  w  w  w .  j  av  a  2s  . c  o m
* @return The milliseconds.    
*    
* @since 1.0.7    
*/
public static long firstMondayAfter1900() {
    int offset = TimeZone.getDefault().getRawOffset();
    TimeZone z = new SimpleTimeZone(offset, "UTC-" + offset);

    // calculate midnight of first monday after 1/1/1900 relative to    
    // current locale    
    Calendar cal = new GregorianCalendar(z);
    cal.set(1900, 0, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DATE, 1);
    }
    //return cal.getTimeInMillis();    
    // preceding code won't work with JDK 1.3    
    return cal.getTime().getTime();
}

From source file:org.activequant.util.charting.IntradayMarketTimeline.java

private boolean isActiveDate(Calendar cal) {
    int day = cal.get(Calendar.DAY_OF_WEEK);

    long timeSinceStart = cal.get(Calendar.HOUR_OF_DAY) * 3600000 + cal.get(Calendar.MINUTE) * 60000
            + cal.get(Calendar.SECOND) * 1000;

    if (day == Calendar.SUNDAY) {
        return (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd);
    } else if (day == Calendar.MONDAY) {
        return (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd);
    } else if (day == Calendar.TUESDAY) {
        return (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd);
    } else if (day == Calendar.WEDNESDAY) {
        return (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd);
    } else if (day == Calendar.THURSDAY) {
        return (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd);
    } else if (day == Calendar.FRIDAY) {
        return (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd);
    } else if (day == Calendar.SATURDAY) {
        return (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd);
    } else {//from ww w.  j  av a2  s .  c  om
        return false;
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.SubjectService.java

private void avoidBlackoutDates(ScheduledActivity event, Site site) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Calendar dateCalendar = Calendar.getInstance();
    Date date = event.getActualDate();
    dateCalendar.setTime(date);//from   www.j a  va  2  s  .co m

    int year = dateCalendar.get(Calendar.YEAR);
    Calendar holidayCalendar = Calendar.getInstance();
    List<BlackoutDate> holidayList = site.getBlackoutDates();

    for (BlackoutDate blackoutDate : holidayList) {
        // TODO: instanceof indicates abstraction failure -- this logic should be in each BlackoutDate class
        if (blackoutDate instanceof SpecificDateBlackout) {
            //month needs to be decremented, because we are using 00 for January in the Calendar
            SpecificDateBlackout h = (SpecificDateBlackout) blackoutDate;
            if (h.getYear() == null) {
                holidayCalendar.set(year, h.getMonth(), h.getDay());
            } else {
                holidayCalendar.set(h.getYear(), h.getMonth(), h.getDay());
            }
            String originalDateFormatted = df.format(date.getTime());
            String holidayDateFormatted = df.format(holidayCalendar.getTime());
            if (originalDateFormatted.equals(holidayDateFormatted)) {
                shiftToAvoidBlackoutDate(event, site, blackoutDate.getDescription());
            }
        } else if (blackoutDate instanceof WeekdayBlackout) {
            WeekdayBlackout dayOfTheWeek = (WeekdayBlackout) blackoutDate;
            int intValueOfTheDay = dayOfTheWeek.getDayOfTheWeekInteger();
            if (dateCalendar.get(Calendar.DAY_OF_WEEK) == intValueOfTheDay) {
                shiftToAvoidBlackoutDate(event, site, blackoutDate.getDescription());
            }
        } else if (blackoutDate instanceof RelativeRecurringBlackout) {
            RelativeRecurringBlackout relativeRecurringHoliday = (RelativeRecurringBlackout) blackoutDate;
            Integer numberOfTheWeek = relativeRecurringHoliday.getWeekNumber();
            Integer month = relativeRecurringHoliday.getMonth();
            int dayOfTheWeekInt = relativeRecurringHoliday.getDayOfTheWeekInteger();
            List<Date> dates = findDaysOfWeekInMonth(year, month, dayOfTheWeekInt);
            //-1, since we start from position 0 in the list
            Date specificDay = dates.get(numberOfTheWeek - 1);

            String originalDateFormatted = df.format(date.getTime());
            String holidayDateFormatted = df.format(specificDay);
            if (originalDateFormatted.equals(holidayDateFormatted)) {
                shiftToAvoidBlackoutDate(event, site, blackoutDate.getDescription());
            }
        }
    }
}

From source file:com.frey.repo.DateUtil.java

/*****************************************
 * @return interger/*w  w  w  . j  ava  2s.com*/
 * @ ???
 ****************************************/
public static String getYearWeekEndDay(int yearNum, int weekNum) throws ParseException {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, yearNum);
    cal.set(Calendar.WEEK_OF_YEAR, weekNum + 1);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    // ????
    String tempYear = Integer.toString(yearNum);
    String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1);
    String tempDay = Integer.toString(cal.get(Calendar.DATE));
    String tempDate = tempYear + "-" + tempMonth + "-" + tempDay;
    return setDateFormat(tempDate, "yyyy-MM-dd");
}

From source file:com.bt.heliniumstudentapp.ScheduleFragment.java

@SuppressWarnings("ConstantConditions")
@Override/*from  w w  w. j a  v a 2 s . c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    mainContext = (AppCompatActivity) getActivity();
    scheduleLayout = inflater.inflate(R.layout.fragment_schedule, viewGroup, false);

    MainActivity.setToolbarTitle(mainContext, getResources().getString(R.string.schedule), null);

    weekDaysLV = (ListView) scheduleLayout.findViewById(R.id.lv_weekDays_fs);

    final boolean restart = PreferenceManager.getDefaultSharedPreferences(mainContext)
            .getBoolean("forced_restart", false);

    if (restart)
        PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putBoolean("forced_restart", false)
                .apply();

    if (restart) { //TODO Database check?
        MainActivity.setStatusBar(mainContext);

        scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR);

        scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null);

        if (MainActivity.isOnline())
            parseData(HeliniumStudentApp.ACTION_ONLINE);
        else
            parseData(HeliniumStudentApp.ACTION_OFFLINE);
    } else if (scheduleJson == null) {
        final boolean online = MainActivity.isOnline();

        scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR);

        if (online && PreferenceManager.getDefaultSharedPreferences(mainContext)
                .getBoolean("pref_updates_auto_update", true)) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
                new UpdateClass(mainContext, false).execute();
            else
                new UpdateClass(mainContext, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }

        if (online && (PreferenceManager.getDefaultSharedPreferences(mainContext)
                .getBoolean("pref_schedule_init", true)
                || PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0",
                        null) == null)) {
            getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN);
        } else if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) {
            MainActivity.setStatusBar(mainContext);

            scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0",
                    null);

            if (online)
                parseData(HeliniumStudentApp.ACTION_ONLINE);
            else
                parseData(HeliniumStudentApp.ACTION_OFFLINE);
        }
    }

    ((SwipeRefreshLayout) scheduleLayout).setColorSchemeResources(MainActivity.accentSecondaryColor,
            MainActivity.accentPrimaryColor, MainActivity.primaryColor);
    ((SwipeRefreshLayout) scheduleLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refresh();
        }
    });

    MainActivity.prevIV.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) {
                if (MainActivity.isOnline()) {
                    scheduleFocus--;

                    getSchedule(HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN);
                } else {
                    final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE)
                            .get(Calendar.WEEK_OF_YEAR);

                    if (scheduleFocus > currentWeek + 1) {
                        scheduleFocus = currentWeek + 1;
                        scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("schedule_1", null);
                    } else {
                        scheduleFocus = currentWeek;
                        scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("schedule_0", null);
                    }

                    parseData(HeliniumStudentApp.ACTION_OFFLINE);
                }
            }
        }
    });

    MainActivity.historyIV.setOnClickListener(new OnClickListener() { //FIXME Huge mess
        private int year;
        private int monthOfYear;
        private int dayOfMonth;

        @Override
        public void onClick(View v) {
            if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) {
                if (MainActivity.isOnline()) {
                    MainActivity.setUI(HeliniumStudentApp.VIEW_SCHEDULE, HeliniumStudentApp.ACTION_ONLINE);

                    final AlertDialog.Builder weekpickerDialogBuilder = new AlertDialog.Builder(
                            new ContextThemeWrapper(mainContext, MainActivity.themeDialog));

                    final View view = View.inflate(mainContext, R.layout.dialog_schedule, null);
                    weekpickerDialogBuilder.setView(view);

                    final DatePicker datePicker = (DatePicker) view.findViewById(R.id.np_weekpicker_dw);

                    year = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR);
                    monthOfYear = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.MONTH);
                    dayOfMonth = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.DAY_OF_MONTH);

                    weekpickerDialogBuilder.setTitle(getString(R.string.go_to));

                    weekpickerDialogBuilder.setPositiveButton(getString(android.R.string.ok),
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    final GregorianCalendar date = new GregorianCalendar(
                                            HeliniumStudentApp.LOCALE);
                                    final GregorianCalendar today = new GregorianCalendar(
                                            HeliniumStudentApp.LOCALE);

                                    date.set(Calendar.YEAR, year);
                                    date.set(Calendar.MONTH, monthOfYear);
                                    date.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                                    date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                                    today.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

                                    scheduleFocus = (today.get(Calendar.WEEK_OF_YEAR))
                                            - ((int) ((today.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7))
                                                    - (date.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7))));

                                    getSchedule(HeliniumStudentApp.DIREC_OTHER,
                                            HeliniumStudentApp.ACTION_REFRESH_IN);
                                }
                            });

                    weekpickerDialogBuilder.setNegativeButton(getString(android.R.string.cancel), null);

                    final AlertDialog weekPickerDialog = weekpickerDialogBuilder.create();

                    final GregorianCalendar minDate = new GregorianCalendar(HeliniumStudentApp.LOCALE);
                    minDate.set(Calendar.YEAR, 2000);
                    minDate.set(Calendar.WEEK_OF_YEAR, 1);

                    final GregorianCalendar maxDate = new GregorianCalendar(HeliniumStudentApp.LOCALE);
                    maxDate.set(Calendar.YEAR, 2038);
                    maxDate.set(Calendar.WEEK_OF_YEAR, 1);

                    datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() {
                        final GregorianCalendar newDate = new GregorianCalendar(HeliniumStudentApp.LOCALE);

                        @Override
                        public void onDateChanged(DatePicker view, int dialogYear, int dialogMonthOfYear,
                                int dialogDayOfMonth) {
                            newDate.set(year, monthOfYear, dayOfMonth);

                            year = dialogYear;
                            monthOfYear = dialogMonthOfYear;
                            dayOfMonth = dialogDayOfMonth;

                            if (minDate != null && minDate.after(newDate))
                                view.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH),
                                        minDate.get(Calendar.DAY_OF_MONTH), this);
                            else if (maxDate != null && maxDate.before(newDate))
                                view.init(maxDate.get(Calendar.YEAR), maxDate.get(Calendar.MONTH),
                                        maxDate.get(Calendar.DAY_OF_MONTH), this);
                            else
                                view.init(year, monthOfYear, dayOfMonth, this);
                        }
                    });

                    weekPickerDialog.setCanceledOnTouchOutside(true);
                    weekPickerDialog.show();

                    weekPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                            .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor));
                    weekPickerDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                            .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor));
                } else {
                    scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR);
                    scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                            .getString("schedule_0", null);

                    parseData(HeliniumStudentApp.ACTION_OFFLINE);
                }
            }
        }
    });

    MainActivity.nextIV.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) {
                if (MainActivity.isOnline()) {
                    scheduleFocus++;

                    getSchedule(HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN);
                } else {
                    final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE)
                            .get(Calendar.WEEK_OF_YEAR);

                    if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1",
                            null) != null && scheduleFocus >= currentWeek) {
                        scheduleFocus = currentWeek + 1;
                        scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("schedule_1", null);
                    } else {
                        scheduleFocus = currentWeek;
                        scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext)
                                .getString("schedule_0", null);
                    }

                    parseData(HeliniumStudentApp.ACTION_OFFLINE);
                }
            }
        }
    });

    return scheduleLayout;
}

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

private static Date getKernelDate(Date d, TimeResolution resolution) {
    Calendar c = Calendar.getInstance();
    c.setTime(d);//  www . ja  v  a 2  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:com.jdo.CloudContactUtils.java

public static String getDay() {

    int d = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
    String day = "sun";
    switch (d) {//from w  w w.  j  a v a 2 s  .co m

    case Calendar.SUNDAY:
        day = "sun";
        break;

    case Calendar.MONDAY:
        day = "mon";
        break;

    case Calendar.TUESDAY:
        day = "tue";
        break;

    case Calendar.WEDNESDAY:
        day = "wed";
        break;

    case Calendar.THURSDAY:
        day = "thu";
        break;

    case Calendar.FRIDAY:
        day = "fri";
        break;

    case Calendar.SATURDAY:
        day = "sat";
        break;
    }

    return day;
}

From source file:egovframework.oe1.cms.com.web.EgovOe1CalRestdeManageController.java

/**
 * ? //from  w w  w.  j  a v a 2  s.  c o  m
 * @param restde
 * @param model
 * @return "/cmm/sym/cal/EgovNormalYearCalendar"
 * @throws Exception
 */
@RequestMapping(value = "/com/EgovNormalYearCalendar.do")
public String selectNormalYearCalendar(EgovOe1Restde restde, ModelMap model) throws Exception {

    Calendar cal = Calendar.getInstance();

    if (restde.getYear() == null || restde.getYear().equals("")) {
        restde.setYear(Integer.toString(cal.get(Calendar.YEAR)));
    }
    if (restde.getMonth() == null || restde.getMonth().equals("")) {
        restde.setMonth(Integer.toString(cal.get(Calendar.MONTH) + 1));
    }
    int iYear = Integer.parseInt(restde.getYear());
    int iMonth = Integer.parseInt(restde.getMonth());

    if (iMonth < 1) {
        iYear--;
        iMonth = 12;
    }
    if (iMonth > 12) {
        iYear++;
        iMonth = 1;
    }
    if (iYear < 1) {
        iYear = 1;
        iMonth = 1;
    }
    if (iYear > 9999) {
        iYear = 9999;
        iMonth = 12;
    }
    restde.setYear(Integer.toString(iYear));

    /* ? */

    /* 1 */
    iMonth = 1;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_1 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_1 = restdeManageService.selectNormalMonthRestde(restde);

    /* 2 */
    iMonth = 2;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_2 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_2 = restdeManageService.selectNormalMonthRestde(restde);

    /* 3 */
    iMonth = 3;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_3 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_3 = restdeManageService.selectNormalMonthRestde(restde);

    /* 4 */
    iMonth = 4;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_4 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_4 = restdeManageService.selectNormalMonthRestde(restde);

    /* 5 */
    iMonth = 5;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_5 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_5 = restdeManageService.selectNormalMonthRestde(restde);

    /* 6 */
    iMonth = 6;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_6 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_6 = restdeManageService.selectNormalMonthRestde(restde);

    /* 7 */
    iMonth = 7;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_7 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_7 = restdeManageService.selectNormalMonthRestde(restde);

    /* 8 */
    iMonth = 8;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_8 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_8 = restdeManageService.selectNormalMonthRestde(restde);

    /* 9 */
    iMonth = 9;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_9 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_9 = restdeManageService.selectNormalMonthRestde(restde);

    /* 10 */
    iMonth = 10;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_10 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_10 = restdeManageService.selectNormalMonthRestde(restde);

    /* 11 */
    iMonth = 11;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_11 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_11 = restdeManageService.selectNormalMonthRestde(restde);

    /* 12 */
    iMonth = 12;
    restde.setMonth(Integer.toString(iMonth));
    cal.set(iYear, iMonth - 1, 1);
    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));
    List CalInfoList_12 = restdeManageService.selectNormalRestdePopup(restde);
    List NormalMonthRestdeList_12 = restdeManageService.selectNormalMonthRestde(restde);

    model.addAttribute("resultList_1", CalInfoList_1);
    model.addAttribute("resultList_2", CalInfoList_2);
    model.addAttribute("resultList_3", CalInfoList_3);
    model.addAttribute("resultList_4", CalInfoList_4);
    model.addAttribute("resultList_5", CalInfoList_5);
    model.addAttribute("resultList_6", CalInfoList_6);
    model.addAttribute("resultList_7", CalInfoList_7);
    model.addAttribute("resultList_8", CalInfoList_8);
    model.addAttribute("resultList_9", CalInfoList_9);
    model.addAttribute("resultList_10", CalInfoList_10);
    model.addAttribute("resultList_11", CalInfoList_11);
    model.addAttribute("resultList_12", CalInfoList_12);
    model.addAttribute("RestdeList_1", NormalMonthRestdeList_1);
    model.addAttribute("RestdeList_2", NormalMonthRestdeList_2);
    model.addAttribute("RestdeList_3", NormalMonthRestdeList_3);
    model.addAttribute("RestdeList_4", NormalMonthRestdeList_4);
    model.addAttribute("RestdeList_5", NormalMonthRestdeList_5);
    model.addAttribute("RestdeList_6", NormalMonthRestdeList_6);
    model.addAttribute("RestdeList_7", NormalMonthRestdeList_7);
    model.addAttribute("RestdeList_8", NormalMonthRestdeList_8);
    model.addAttribute("RestdeList_9", NormalMonthRestdeList_9);
    model.addAttribute("RestdeList_10", NormalMonthRestdeList_10);
    model.addAttribute("RestdeList_11", NormalMonthRestdeList_11);
    model.addAttribute("RestdeList_12", NormalMonthRestdeList_12);

    return "/cms/com/EgovNormalYearCalendar";
}

From source file:Holidays.java

public static java.util.Calendar NewYearsDayObserved(int nYear) {
    int nX;// www .j  av  a  2 s .  co  m
    int nMonth = 0; // January
    int nMonthDecember = 11; // December

    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(nYear, nMonth, 1);

    nX = cal.get(Calendar.DAY_OF_WEEK);

    if (nYear > 1900)
        nYear -= 1900;

    switch (nX) {
    case 0: // Sunday
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 2);
        return cal;
    case 1: // Monday
    case 2: // Tuesday
    case 3: // Wednesday
    case 4: // Thrusday
    case 5: // Friday
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 1);
        return cal;
    default:
        // Saturday, then observe on friday of previous year
        cal = java.util.Calendar.getInstance();
        cal.set(--nYear, nMonthDecember, 31);
        return cal;
    }
}