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:com.eryansky.common.utils.SysUtils.java

public static String getNowDateStr() {
     String result = dateFormat(getNowDate(), CHS_DATEFORMAT);
     Calendar c = Calendar.getInstance();
     for (int i = 0; i < 8; i++) {
         c.add(Calendar.DAY_OF_MONTH, 1);
         @SuppressWarnings("unused")
         int e = c.get(Calendar.DAY_OF_WEEK);
     }/*from  ww w . j a va2s  .  c o m*/
     result += "  ";
     switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
     case Calendar.SUNDAY:
         return result + "";
     case Calendar.MONDAY:
         return result + "";
     case Calendar.TUESDAY:
         return result + "";
     case Calendar.WEDNESDAY:
         return result + "";
     case Calendar.THURSDAY:
         return result + "";
     case Calendar.FRIDAY:
         return result + "";
     case Calendar.SATURDAY:
         return result + "";
     default:
         return result;
     }
 }

From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java

public Integer WEEKDAY(Object dateObject, Boolean isSundayFirstDay) {
    Integer dayOfWeek = getCalendarFieldFromDate(dateObject, Calendar.DAY_OF_WEEK);
    if (dayOfWeek == null) {
        if (log.isDebugEnabled()) {
            log.debug("Unable to get the correct day of the week.");
        }/* w  ww  . j  ava 2 s. co  m*/
        return null;
    }
    if (isSundayFirstDay) {
        // By default Sunday is considered first day in Java 
        // Calendar.SUNDAY should be a constant with value 1.
        // See the Calendar.DAY_OF_WEEK javadoc      
        return dayOfWeek;
    } else {
        // shift the days
        if (dayOfWeek == Calendar.SUNDAY) {
            return 7;
        } else {
            return dayOfWeek - 1;
        }
    }
}

From source file:br.com.transport.report.ManagerReportBean.java

/**
 * Retorna o primeiro dia da semana/*from  w  w w.  j  a v  a  2s.  co  m*/
 * @return
 */
private Calendar getInitCalendar() {

    Calendar init = GregorianCalendar.getInstance();
    init.setFirstDayOfWeek(Calendar.SUNDAY);
    init.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    init.set(Calendar.HOUR_OF_DAY, 0);
    init.set(Calendar.MINUTE, 0);
    init.set(Calendar.SECOND, 0);
    init.setTime(init.getTime());

    return init;
}

From source file:org.silverpeas.core.web.calendar.CalendarTimeWindowViewContext.java

private void setReferenceDay(final Date date, int offset) {

    // Reference date
    Calendar cal = DateUtil.convert(date, locale);
    final Date referenceDate;
    if (!withWeekend && (viewType.equals(WEEKLY) || viewType.equals(DAILY))) {
        switch (cal.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SATURDAY:
            if (Calendar.SATURDAY == DateUtil.getFirstDayOfWeek(locale)) {
                referenceDate = DateUtils.addDays(date, offset >= 0 ? 2 : -1);
            } else {
                referenceDate = DateUtils.addDays(date, offset > 0 ? 2 : -1);
            }/*from   ww  w .  j  av  a  2  s.com*/
            break;
        case Calendar.SUNDAY:
            if (Calendar.SUNDAY == DateUtil.getFirstDayOfWeek(locale)) {
                referenceDate = DateUtils.addDays(date, offset >= 0 ? 1 : -2);
            } else {
                referenceDate = DateUtils.addDays(date, offset > 0 ? 1 : -2);
            }
            break;
        default:
            referenceDate = date;
        }
    } else {
        referenceDate = date;
    }
    this.referenceDay = new CalendarDay(referenceDate, locale);

    // Period
    referencePeriod = CalendarPeriod.from(Period.from(referenceDate, viewType.getPeriodeType(), locale),
            locale);
}

From source file:JobScheduler.java

public void configureBackup(Runnable job) {
    Calendar now = Calendar.getInstance();

    executeAtNextDOW(job, now.getTime(), Calendar.SUNDAY);
}

From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java

public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklySummaryStatsAbs(Date startDate, Date endDate,
        Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) {
    Calendar cal = new GregorianCalendar();
    TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap<>();

    //SET TO BEGINNING OF WK FOR ABSOLUTE CALC
    cal.setTime(startDate);/*w ww. j a  v a2s . co m*/
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    startDate = cal.getTime();

    List<Object[]> events = getDailyCounts(startDate, endDate, hospitalser, filter, false, ptflag,
            scheduledFlag);

    DateFormat df = new SimpleDateFormat("MM/dd/yy");
    cal.setTime(startDate);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    int wk = cal.get(Calendar.WEEK_OF_YEAR);
    int mo = cal.get(Calendar.MONTH);
    int yr = cal.get(Calendar.YEAR);
    if (mo == Calendar.DECEMBER && wk == 1) {
        yr = yr + 1;
    } else if (mo == Calendar.JANUARY && wk == 52) {
        yr = yr - 1;
    }
    String currYrWk = yr + "-" + String.format("%02d", wk);
    //String prevYrWk = "";
    String prevYrWk = currYrWk;
    SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics();
    int i = 0;
    while (cal.getTime().before(endDate) && i < events.size()) {

        Object[] event = events.get(i);
        Date d = (Date) event[0];
        Long count = (Long) event[1];

        cal.setTime(d);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        wk = cal.get(Calendar.WEEK_OF_YEAR);
        mo = cal.get(Calendar.MONTH);
        yr = cal.get(Calendar.YEAR);
        if (mo == Calendar.DECEMBER && wk == 1) {
            yr = yr + 1;
        } else if (mo == Calendar.JANUARY && wk == 52) {
            yr = yr - 1;
        }
        currYrWk = yr + "-" + String.format("%02d", wk);

        if (!(prevYrWk.equals(currYrWk))) {
            GregorianCalendar lastMon = new GregorianCalendar();
            lastMon.setTime(cal.getTime());
            lastMon.add(Calendar.DATE, -7);
            retval.put(lastMon.getTime(), currStats);
            currStats = new SynchronizedDescriptiveStatistics();
        }

        prevYrWk = currYrWk;

        currStats.addValue(count);
        i++;
    }
    retval.put(cal.getTime(), currStats);

    return retval;
}

From source file:org.kuali.student.enrollment.class2.acal.dto.ExamPeriodWrapper.java

public List<Date> getExamPeriodDates() {
    List<Date> dates = new ArrayList<Date>();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(this.examPeriodInfo.getStartDate());

    while (calendar.getTime().before(this.examPeriodInfo.getEndDate())) {
        Date resultado = calendar.getTime();
        Calendar cal = Calendar.getInstance();
        cal.setTime(resultado);/*from   w ww.  java  2s . c  o  m*/
        int weekday = cal.get(Calendar.DAY_OF_WEEK);
        if ((weekday == Calendar.SATURDAY && !this.excludeSaturday)
                || (weekday == Calendar.SUNDAY && !this.excludeSunday)) {
            dates.add(resultado);
        } else if ((weekday != Calendar.SATURDAY) && (weekday != Calendar.SUNDAY)) {
            dates.add(resultado);
        }

        calendar.add(Calendar.DATE, 1);
    }
    calendar.setTime(this.examPeriodInfo.getEndDate());
    Date finalDate = calendar.getTime();
    dates.add(finalDate);
    return dates;
}

From source file:org.orange.querysystem.CoursesInThisWeekActivity.java

public void showCoursesInfo(List<Course> courses, CourseToSimpleCourse converter) {
    mTabsAdapter.clear();//ww  w  .j a v a 2s .  c o  m

    Bundle[] args = new Bundle[8];
    List<SimpleCourse>[][] lesson = AllCoursesActivity.getTimeTable(courses, converter,
            SettingsActivity.getCurrentWeekNumber(this));

    //?ListCoursesFragment?
    for (int dayOfWeek = 0; dayOfWeek <= 7; dayOfWeek++) {
        ArrayList<SimpleCourse> coursesInADay = new ArrayList<SimpleCourse>();
        for (int period = 1; period < lesson[dayOfWeek].length; period++) {
            for (SimpleCourse course : lesson[dayOfWeek][period]) {
                coursesInADay.add(course);
            }
        }
        Bundle argForFragment = new Bundle();
        argForFragment.putParcelableArrayList(ListCoursesFragment.COURSES_KEY, coursesInADay);
        args[dayOfWeek] = argForFragment;
    }
    //?args[0]args[7]?
    Bundle temp = args[0];
    args[0] = args[7];
    args[7] = temp;

    String[] daysOfWeek = getResources().getStringArray(R.array.days_of_week);

    for (int day = 0; day <= 7; day++) {
        TabSpec tabSpec = mTabHost.newTabSpec(daysOfWeek[day]);
        mTabsAdapter.addTab(tabSpec.setIndicator(daysOfWeek[day]), ListCoursesFragment.class, args[day]);
    }

    int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
    mTabHost.setCurrentTab(dayOfWeek != Calendar.SUNDAY ? dayOfWeek - Calendar.SUNDAY : 7);
}

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

/**
 * <p>//from w  w w.ja  v 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:com.pressurelabs.flowopensource.TheHubActivity.java

private void generateDrawerGreeting(NavigationView view) {
    View header = view.getHeaderView(0);
    TextView greeting = (TextView) header.findViewById(R.id.ndrawer_date_greeting);
    String[] array = this.getResources().getStringArray(R.array.drawer_greeting);

    switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        greeting.setText(array[0]);/* w w w.  ja v a2s.  co  m*/
        break;

    case Calendar.TUESDAY:
        greeting.setText(array[1]);
        break;

    case Calendar.WEDNESDAY:
        greeting.setText(array[2]);
        break;
    case Calendar.THURSDAY:
        greeting.setText(array[3]);
        break;
    case Calendar.FRIDAY:
        greeting.setText(array[4]);
        break;
    case Calendar.SATURDAY:
        greeting.setText(array[5]);
        break;

    case Calendar.SUNDAY:
        greeting.setText(array[6]);
        break;

    default:
        greeting.setText(array[7]);
        break;

    }

}