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.jasig.schedassist.model.AvailableBlockBuilder.java

/**
 * Returns a {@link List} of {@link Date} objects that fall between startDate and endDate and
 * exist on the days specified by daysOfWeekPhrase.
 * /* ww w . j a va  2 s  .  com*/
 * For instance, passing "MWF", a start Date of June 30 2008, and an end Date of July 04 2008, this 
 * method will return a list of 3 Date objects (one for Monday June 30, one for Wednesday July 2, and
 * one for Friday July 4).
 * 
 * The time values for returned {@link Date}s will always be 00:00:00 (in the JVM's default timezone).
 * 
 * @param daysOfWeekPhrase
 * @param startDate
 * @param endDate
 * @return a {@link List} of {@link Date} objects that fall between startDate and endDate and
 * exist on the days specified by daysOfWeekPhrase.
 */
protected static List<Date> matchingDays(final String daysOfWeekPhrase, final Date startDate,
        final Date endDate) {
    List<Date> matchingDays = new ArrayList<Date>();

    Set<Integer> daysOfWeek = new HashSet<Integer>();
    for (char character : daysOfWeekPhrase.toUpperCase().toCharArray()) {
        switch (character) {
        case 'N':
            daysOfWeek.add(Calendar.SUNDAY);
            break;
        case 'M':
            daysOfWeek.add(Calendar.MONDAY);
            break;
        case 'T':
            daysOfWeek.add(Calendar.TUESDAY);
            break;
        case 'W':
            daysOfWeek.add(Calendar.WEDNESDAY);
            break;
        case 'R':
            daysOfWeek.add(Calendar.THURSDAY);
            break;
        case 'F':
            daysOfWeek.add(Calendar.FRIDAY);
            break;
        case 'S':
            daysOfWeek.add(Calendar.SATURDAY);
            break;
        }
    }

    Calendar current = Calendar.getInstance();
    current.setTime(startDate);
    // set the time to 00:00:00 to insure the time doesn't affect our comparison)
    // (because there may be a valid time window on endDate)
    current = CommonDateOperations.zeroOutTimeFields(current);

    while (current.getTime().compareTo(endDate) < 0) {
        if (daysOfWeek.contains(current.get(Calendar.DAY_OF_WEEK))) {
            matchingDays.add(current.getTime());
        }
        // increment currentDate +1 day 
        current.add(Calendar.DATE, 1);
    }
    return matchingDays;
}

From source file:nu.mine.kino.projects.utils.ProjectUtils.java

/**
 * y?j`FbN//from   w w w  .  j  a v a2s. co m
 * 
 * @param holidays
 * @param targetDate
 * @return
 */
public static boolean isHoliday(Holiday[] holidays, Date targetDate) {
    if (holidays != null) {//
        for (Holiday holiday : holidays) {
            if (holiday.getDate().getTime() == targetDate.getTime()) {
                return true;
            }
        }
    }

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(targetDate);
    switch (calendar.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.SATURDAY:
    case Calendar.SUNDAY:
        return true;
    default:
        return false;
    }
}

From source file:edu.ucsb.nceas.MCTestCase.java

/**
 * Create a unique docid for testing insert and update. Does not
 * include the 'revision' part of the id.
 * /*from w w  w .j  av a 2 s .c  o m*/
 * @return a String docid based on the current date and time
 */
protected String generateDocumentId() {
    try {
        Thread.sleep(1010);
    } catch (InterruptedException ie) {
        debug("Could not sleep: " + ie.getMessage());
    }

    StringBuffer docid = new StringBuffer(prefix);
    docid.append(".");

    // Create a calendar to get the date formatted properly
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);
    docid.append(calendar.get(Calendar.YEAR));
    docid.append(calendar.get(Calendar.DAY_OF_YEAR));
    docid.append(calendar.get(Calendar.HOUR_OF_DAY));
    docid.append(calendar.get(Calendar.MINUTE));
    docid.append(calendar.get(Calendar.SECOND));

    return docid.toString();
}

From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object isWorkingDay(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 1) {
        try {/*from w ww .  ja v  a  2  s  .  c  om*/
            if (isNull(ArgList[0]))
                return null;
            else if (isUndefined(ArgList[0]))
                return Context.getUndefinedValue();
            else {
                java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
                Calendar startDate = Calendar.getInstance();
                startDate.setTime(dIn);
                if (startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                        && startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY)
                    return Boolean.TRUE;
                return Boolean.FALSE;
            }
        } catch (Exception e) {
            return null;
        }
    } else {
        throw Context.reportRuntimeError("The function call isWorkingDay requires 1 argument.");
    }
}

From source file:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for checking whether the target date is weekend
 * // w  ww. jav  a2s . c om
 * @param tgtDate
 * @return
 */
public static boolean isWeekEnd(Date tgtDate) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(tgtDate);

    return (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? true : false);
}

From source file:de.ribeiro.android.gso.dataclasses.Pager.java

/**
 * Erstellt eine Stundeplan Seite des ViewPagers, inkl Header und Footer
 * <p/>/*  w ww.  j  av  a  2s  . c o  m*/
 * Hier wird die Wochenansicht generiert
 *
 * @param weekData
 * @param ctxt
 * @return
 * @author Tobias Janssen
 */
private View createWeekPage(WeekData weekData) {
    // in die Page kommen alle Elemente dieser Ansicht
    View page = inflater.inflate(R.layout.weeklayout, null);

    TableLayout tl = (TableLayout) page.findViewById(R.id.weekTimetable);
    LinearLayoutBordered ll = new LinearLayoutBordered(context);

    // Tagesberschrift erstellen:
    TableRow tr = new TableRow(context);

    for (int x = Calendar.SUNDAY; x < Calendar.SATURDAY; x++) {
        // einen neuen Rahmen fr das Tabellenfeld vorbereiten
        ll = new LinearLayoutBordered(context);
        ll.setBorderRight(true);
        ll.setBorderBottom(true);
        ll.setBorderTop(true);
        ll.setBorderSize(1);
        ll.setBackgroundColor(Color.WHITE);

        View textview = inflater.inflate(R.layout.textview, null);
        TextView tv = (TextView) textview.findViewById(R.id.textview);
        // berschriftentextgre einstellen

        tv.setTextSize(textSize);
        if (x == Calendar.SUNDAY) {
            tv.setText(timeslots[0]);
            tv.setTextColor(Color.parseColor("#3A599A"));

        } else {
            tv.setText(ResolveWeekDay(x));
        }
        ll.addView(tv);
        tr.addView(ll);
    }
    tl.addView(tr);

    // den Stundenplan zusammensetzten
    // fr jeden tag
    List<Lesson> stunden = GetSchulstunden();
    for (int y = 0; y < stunden.size(); y++) {
        tr = new TableRow(context);
        for (int x = Calendar.SUNDAY; x <= Calendar.FRIDAY; x++) {
            if (x == Calendar.SUNDAY) {
                addColumn(timeslots[y + 1], "#3A599A", tr);
            } else {
                // alle events dieses Tages durchgehen ob die zu dieser
                // schulstunde passen
                boolean lessonAdded = false;
                TextView lastTextView = null;
                for (ICalEvent ev : weekData.events) {
                    // ist event an diesem tag?
                    if (ev.DTSTART.get(Calendar.DAY_OF_WEEK) == x) {
                        // ja
                        // ist event zu dieser schulstunde?

                        Time st = new Time();
                        st.set(ev.DTSTART.getTimeInMillis());
                        int start = GetSchulstundeOfDateTime(st);
                        Time et = new Time();
                        et.set(ev.DTEND.getTimeInMillis() - 60000);
                        int end = GetSchulstundeOfDateTime(et);
                        // ende der schulstunde herausfinden
                        if (((start != end) && y >= start && y <= end) || start == y || end == y) {
                            // ja event ist in dieser stunde
                            // ist eine Doopelbelegung fr diese Stunde?
                            if (lessonAdded && lastTextView != null) {
                                // ja, doppelbelegung
                                String newText = "";
                                if (weekData.typeId.equalsIgnoreCase("4")) {
                                    newText = lastTextView.getText() + "\r\n" + ev.DESCRIPTION + " "
                                            + ev.SUMMARY;
                                } else {
                                    newText = lastTextView.getText() + "\r\n"
                                            + ev.DESCRIPTION.replace(weekData.elementId, "") + " " + ev.SUMMARY
                                            + " " + ev.LOCATION;
                                }
                                lastTextView.setText(newText);
                            } else {
                                // prfen, ob dieses event eine gelschte
                                // stunde ist
                                if (ev.UID.equalsIgnoreCase("deleted")) {
                                    // gelschtes event
                                    lastTextView = addColumn(" --- " + " " + " --- " + " " + " --- ", "#FF0000",
                                            tr);
                                } else {
                                    String color = "#3A599A";
                                    if (ev.UID.equalsIgnoreCase("diff"))
                                        color = "#FF0000";
                                    if (weekData.typeId.equalsIgnoreCase("4")) {
                                        lastTextView = addColumn(ev.DESCRIPTION + " " + ev.SUMMARY, color, tr);
                                    } else {
                                        lastTextView = addColumn(ev.DESCRIPTION.replace(weekData.elementId, "")
                                                + " " + ev.SUMMARY + " " + ev.LOCATION, color, tr);
                                    }
                                }
                            }

                            lessonAdded = true;
                        }
                    }
                }
                if (!lessonAdded) {
                    // ja event ist in dieser stunde
                    addColumn("", "#3A599A", tr);
                }
            }
        }
        tl.addView(tr);
    }
    TextView syncTime = (TextView) page.findViewById(R.id.syncTime);
    Calendar sync = new GregorianCalendar();
    sync.setTimeInMillis(weekData.syncTime);

    String minute = String.valueOf(sync.get(Calendar.MINUTE));
    if (minute.length() == 1)
        minute = "0" + minute;

    syncTime.setText(weekData.elementId + " | Stand vom " + sync.get(Calendar.DAY_OF_MONTH) + "."
            + (sync.get(Calendar.MONTH) + 1) + "." + sync.get(Calendar.YEAR) + " "
            + sync.get(Calendar.HOUR_OF_DAY) + ":" + minute + " Uhr");

    return page;
}

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

/*****************************************
 * @ ???//from   w  ww .j a  v  a  2 s . c o m
 ****************************************/
public static String getYearWeekEndDay(Date curDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(curDate);
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR));
    } else {
        cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) + 1);
    }
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    // cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY+1);
    // ????
    String tempYear = Integer.toString(cal.get(Calendar.YEAR));
    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:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object isWorkingDay(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 1) {
        try {// w  w  w  .  j a v a  2s.  co  m
            if (isNull(ArgList[0])) {
                return null;
            } else if (isUndefined(ArgList[0])) {
                return Context.getUndefinedValue();
            } else {
                java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
                Calendar startDate = Calendar.getInstance();
                startDate.setTime(dIn);
                if (startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                        && startDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                    return Boolean.TRUE;
                }
                return Boolean.FALSE;
            }
        } catch (Exception e) {
            return null;
        }
    } else {
        throw Context.reportRuntimeError("The function call isWorkingDay requires 1 argument.");
    }
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private int getIdFromUri(Uri uri) {
    int postId = -1;

    List<String> pathSegments = uri.getPathSegments();

    if ((pathSegments.size() == 5) && (pathSegments.get(0).equals(Const.INTENT_EXTRA_URL_PATH_POST_ID))) {

        try {/*from  w  w  w  .j  av a  2 s  .c  o  m*/
            postId = Integer.parseInt(pathSegments.get(1));
            final int day = Integer.valueOf(pathSegments.get(2));
            final double time = Double.valueOf(pathSegments.get(3));
            final int duration = Integer.valueOf(pathSegments.get(4));

            final int hourOfDay = (int) time;
            final int minute = (int) ((time - hourOfDay) * 60);

            GregorianCalendar calendar = new GregorianCalendar();

            calendar.set(Calendar.DAY_OF_WEEK, day == 7 ? Calendar.SUNDAY : day + 1);
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);

            parkingApp.setParkingCalendar(calendar);
            // parkingApp.setParkingTime(hourOfDay, minute);
            parkingApp.setParkingDuration(duration);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    return postId;
}

From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java

@Override
public List<Date> getDates(final String selectedUser, final Date from, final Date to, final boolean workingHour,
        final boolean checkNonWorking) throws GenericEntityException {
    List<Date> datesWhereNoWorklog = new ArrayList<Date>();
    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);/*from   w  ww .  j  a  v a2 s.c o  m*/
    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);
    while (!fromDate.after(toDate)) {
        String currentDateString = DateTimeConverterUtil.dateToString(fromDate.getTime());
        if (excludeDatesSet.contains(currentDateString)) {
            fromDate.add(Calendar.DATE, 1);
            continue;
        }
        // check includes - not check weekend
        // check weekend - pass
        if (!includeDatesSet.contains(currentDateString)
                && ((fromDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
                        || (fromDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) {
            fromDate.add(Calendar.DATE, 1);
            continue;
        }
        // check worklog. if no worklog set result else ++ scanedDate
        boolean isDateContainsWorklog;
        if (workingHour) {
            isDateContainsWorklog = isContainsEnoughWorklog(fromDate.getTime(), checkNonWorking);
        } else {
            isDateContainsWorklog = isContainsWorklog(fromDate.getTime());
        }
        if (!isDateContainsWorklog) {
            datesWhereNoWorklog.add((Date) fromDate.getTime().clone());
        }
        fromDate.add(Calendar.DATE, 1);

    }
    Collections.reverse(datesWhereNoWorklog);
    return datesWhereNoWorklog;
}