Example usage for java.util Calendar SATURDAY

List of usage examples for java.util Calendar SATURDAY

Introduction

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

Prototype

int SATURDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Saturday.

Usage

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * @param beginDate date de dbut de la priode en Date
 * @param endDate date de fin de la priode en Date
 * @param weekend true pour que les jours fris tombant un week end soient comtabilis, false sinon.
 * @return retourne le nombre de jours fris dans la priode.
 *//*w  w  w  .j a  v a  2 s. co  m*/
public static int getNbPublicHolliday(final Date beginDate, final Date endDate, final boolean weekend) {
    if ((beginDate == null) || (endDate == null)) {
        return 0;
    }
    final GregorianCalendar gc = new GregorianCalendar();
    // recupere l'anne de debut
    int by = getYearOfDate(gc, beginDate);

    // Recupere l'anne de fin
    int ey = getYearOfDate(gc, endDate);

    // Recupere les jours de vacance des 2 annes
    ArrayList ph = getPublicHolliday(by, ey);

    int nbph = 0;

    for (final Iterator iter = ph.iterator(); iter.hasNext();) {
        final Date d = (Date) iter.next();
        gc.setTime(d);

        // Si les WEEK-END sont compatbili , les ajouter au compteur
        if (weekend) {
            if (isBetween(d, beginDate, endDate)) {
                nbph++;
            }
        } else {
            // Verifie que ce n'est pas un Samedi ou un dimance pour ompatibilit
            if ((gc.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY)
                    && (gc.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)) {
                if (isBetween(d, beginDate, endDate)) {
                    nbph++;
                }
            }
        }
    }

    return nbph;
}

From source file:org.kuali.kra.committee.web.CommitteeScheduleAddSeleniumTest.java

/**
 * Determines whether the given {@code date} is on a weekday.
 * /* w  w w .  j a v a2  s.c  o  m*/
 * @param date the date to check
 * @return true if {@code date} is on a weekday, false if it is on a weekend
 */
private boolean isWeekday(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    boolean isSaturday = calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
    boolean isSunday = calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;

    return !isSaturday && !isSunday;
}

From source file:com.borax12.materialdaterangepicker.single.date.MonthView.java

/**
 * Return a 1 or 2 letter String for use as a weekday label
 * @param day The day for which to generate a label
 * @return The weekday label/*from   www  .ja v a 2 s. c o  m*/
 */
private String getWeekDayLabel(Calendar day) {
    Locale locale = Locale.getDefault();

    // Localised short version of the string is not available on API < 18
    if (Build.VERSION.SDK_INT < 18) {
        String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
        String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

        // Chinese labels should be fetched right to left
        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = dayName.length();
            dayLabel = dayName.substring(len - 1, len);
        }

        // Most hebrew labels should select the second to last character
        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                dayLabel = dayName.toUpperCase(locale).substring(0, 1);
            }
        }

        // Catalan labels should be two digits in lowercase
        if (locale.getLanguage().equals("ca"))
            dayLabel = dayName.toLowerCase().substring(0, 2);

        // Correct single character label in Spanish is X
        if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
            dayLabel = "X";

        return dayLabel;
    }
    // Getting the short label is a one liner on API >= 18
    return new SimpleDateFormat("EEEEE", locale).format(day.getTime());
}

From source file:com.jarklee.materialdatetimepicker.date.MonthView.java

/**
 * Return a 1 or 2 letter String for use as a weekday label
 *
 * @param day The day for which to generate a label
 * @return The weekday label/* w  ww  .  j a  va 2 s.c  o m*/
 */
private String getWeekDayLabel(Calendar day) {
    Locale locale = getLocale();
    // Localised short version of the string is not available on API < 18
    if (Build.VERSION.SDK_INT < 18) {
        String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
        String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

        // Chinese labels should be fetched right to left
        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = dayName.length();
            dayLabel = dayName.substring(len - 1, len);
        }

        // Most hebrew labels should select the second to last character
        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                dayLabel = dayName.toUpperCase(locale).substring(0, 1);
            }
        }

        // Catalan labels should be two digits in lowercase
        if (locale.getLanguage().equals("ca"))
            dayLabel = dayName.toLowerCase().substring(0, 2);

        // Correct single character label in Spanish is X
        if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
            dayLabel = "X";

        return dayLabel;
    }
    // Getting the short label is a one liner on API >= 18
    return new SimpleDateFormat("EEEEE", locale).format(day.getTime());
}

From source file:com.kunze.androidlocaltodo.TaskListActivity.java

private void ShowDueDateDialog(Calendar dueDate, OnClickListener okListener) {
    LayoutInflater inflater = this.getLayoutInflater();
    View dlgView = inflater.inflate(R.layout.dialog_due_date, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(dlgView);//from w  w  w.  j a v a 2 s  .c  om
    builder.setTitle("Due Date");
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("OK", okListener);

    final TextView dateText = (TextView) dlgView.findViewById(R.id.due_date_text);
    SetFriendlyDueDateText(dateText, dueDate);

    final DatePicker datePicker = (DatePicker) dlgView.findViewById(R.id.due_date_calendar);
    //datePicker.setMinDate(Math.min(now.getTimeInMillis(), dueDate.getTimeInMillis()));
    datePicker.init(dueDate.get(Calendar.YEAR), dueDate.get(Calendar.MONTH), dueDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0);
                    SetFriendlyDueDateText(dateText, calendar);

                }
            });
    datePicker.setCalendarViewShown(false);

    Button todayButton = (Button) dlgView.findViewById(R.id.today_button);
    todayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar now = Calendar.getInstance();
            datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                    now.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, now);
        }
    });
    Button plusDayButton = (Button) dlgView.findViewById(R.id.plus_day_button);
    plusDayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            calendar.add(Calendar.DATE, 1);
            datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, calendar);
        }
    });
    Button thisWeekendButton = (Button) dlgView.findViewById(R.id.this_weekend_button);
    thisWeekendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar weekend = Calendar.getInstance();
            while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                weekend.add(Calendar.DATE, 1);
            }
            datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH),
                    weekend.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, weekend);
        }
    });
    Button plusWeekButton = (Button) dlgView.findViewById(R.id.plus_week_button);
    plusWeekButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            calendar.add(Calendar.DATE, 7);
            datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            SetFriendlyDueDateText(dateText, calendar);
        }
    });

    builder.show();
}

From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java

public static Object dateDiff(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 3) {
        try {//  w  w w  . j a v  a 2s.co m
            if (isNull(ArgList, new int[] { 0, 1, 2 })) {
                return new Double(Double.NaN);
            } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) {
                return undefinedValue;
            } else {
                java.util.Date dIn1 = (java.util.Date) ArgList[0];
                java.util.Date dIn2 = (java.util.Date) ArgList[1];
                String strType = ((String) ArgList[2]).toLowerCase();
                int iRC = 0;

                Calendar startDate = Calendar.getInstance();
                Calendar endDate = Calendar.getInstance();
                startDate.setTime(dIn1);
                endDate.setTime(dIn2);

                /*
                 * Changed by: Ingo Klose, SHS VIVEON AG, Date: 27.04.2007
                 *
                 * Calculating time differences using getTimeInMillis() leads to false results when crossing Daylight
                 * Savingstime borders. In order to get correct results the time zone offsets have to be added.
                 *
                 * Fix: 1. calculate correct milli seconds for start and end date 2. replace endDate.getTimeInMillis() with
                 * endL and startDate.getTimeInMillis() with startL
                 */
                long endL = endDate.getTimeInMillis()
                        + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                long startL = startDate.getTimeInMillis()
                        + startDate.getTimeZone().getOffset(startDate.getTimeInMillis());

                if (strType.equals("y")) {
                    return new Double(endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR));
                } else if (strType.equals("m")) {
                    int iMonthsToAdd = (endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR)) * 12;
                    return new Double(
                            (endDate.get(Calendar.MONTH) - startDate.get(Calendar.MONTH)) + iMonthsToAdd);
                } else if (strType.equals("d")) {
                    return new Double(((endL - startL) / 86400000));
                } else if (strType.equals("wd")) {
                    int iOffset = -1;
                    if (endDate.before(startDate)) {
                        iOffset = 1;
                    }
                    while ((iOffset == 1 && endL < startL) || (iOffset == -1 && endL > startL)) {
                        int day = endDate.get(Calendar.DAY_OF_WEEK);
                        if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY)) {
                            iRC++;
                        }
                        endDate.add(Calendar.DATE, iOffset);
                        endL = endDate.getTimeInMillis()
                                + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                    }
                    return new Double(iRC);
                } else if (strType.equals("w")) {
                    int iDays = (int) ((endL - startL) / 86400000);
                    return new Double(iDays / 7);
                } else if (strType.equals("ss")) {
                    return new Double(((endL - startL) / 1000));
                } else if (strType.equals("mi")) {
                    return new Double(((endL - startL) / 60000));
                } else if (strType.equals("hh")) {
                    return new Double(((endL - startL) / 3600000));
                } else {
                    return new Double(((endL - startL) / 86400000));
                }
                /*
                 * End Bugfix
                 */
            }
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call dateDiff requires 3 arguments.");
    }
}

From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java

/**
 * Checks whether the current day is a holiday.
 *
 * @param now The current day./*w  w  w. java  2  s .c  om*/
 * @return True if the current date is a holiday, false otherwise.
 * @throws BatchProcessingException If major error occurred.
 */
protected boolean isNowHoliday(Date now) throws BatchProcessingException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(now);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
        return true; // Sunday for 0 and Saturday for 6 are holidays
    }

    try {
        startTransaction();

        StoredProcedureQuery sp = entityManager.createNamedStoredProcedureQuery("IsThisHoliday");
        sp.setParameter("pDate2Test", now, TemporalType.DATE);

        Boolean result = (Boolean) sp.getSingleResult();

        commitTransaction();

        return result;
    } catch (PersistenceException pe) {
        throw new BatchProcessingException("Database error checking holiday.", pe);
    }
}

From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static Object dateDiff(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 3) {
        try {/*from   w ww  . j  a v  a 2s . c  o m*/
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return new Double(Double.NaN);
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return undefinedValue;
            else {
                java.util.Date dIn1 = (java.util.Date) ArgList[0];
                java.util.Date dIn2 = (java.util.Date) ArgList[1];
                String strType = (String) ArgList[2];
                int iRC = 0;

                Calendar startDate = Calendar.getInstance();
                Calendar endDate = Calendar.getInstance();
                startDate.setTime(dIn1);
                endDate.setTime(dIn2);

                /* Changed by:    Ingo Klose, SHS VIVEON AG,
                 * Date:      27.04.2007
                 *
                 * Calculating time differences using getTimeInMillis() leads to false results
                 * when crossing Daylight Savingstime borders. In order to get correct results
                 * the time zone offsets have to be added.
                 *
                 * Fix:       1.    calculate correct milli seconds for start and end date
                 *             2.    replace endDate.getTimeInMillis() with endL
                 *                and startDate.getTimeInMillis() with startL
                 */
                long endL = endDate.getTimeInMillis()
                        + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                long startL = startDate.getTimeInMillis()
                        + startDate.getTimeZone().getOffset(startDate.getTimeInMillis());

                if (strType.toLowerCase().equals("y")) {
                    return new Double(endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR));
                } else if (strType.toLowerCase().equals("m")) {
                    int iMonthsToAdd = (int) (endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR)) * 12;
                    return new Double(
                            (endDate.get(Calendar.MONTH) - startDate.get(Calendar.MONTH)) + iMonthsToAdd);
                } else if (strType.toLowerCase().equals("d")) {
                    return new Double(((endL - startL) / 86400000));
                } else if (strType.toLowerCase().equals("wd")) {
                    int iOffset = -1;
                    if (endDate.before(startDate))
                        iOffset = 1;
                    while ((iOffset == 1 && endL < startL) || (iOffset == -1 && endL > startL)) {
                        int day = endDate.get(Calendar.DAY_OF_WEEK);
                        if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY))
                            iRC++;
                        endDate.add(Calendar.DATE, iOffset);
                        endL = endDate.getTimeInMillis()
                                + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                    }
                    return new Double(iRC);
                } else if (strType.toLowerCase().equals("w")) {
                    int iDays = (int) ((endL - startL) / 86400000);
                    return new Double(iDays / 7);
                } else if (strType.toLowerCase().equals("ss")) {
                    return new Double(((endL - startL) / 1000));
                } else if (strType.toLowerCase().equals("mi")) {
                    return new Double(((endL - startL) / 60000));
                } else if (strType.toLowerCase().equals("hh")) {
                    return new Double(((endL - startL) / 3600000));
                } else {
                    return new Double(((endL - startL) / 86400000));
                }
                /*
                   * End Bugfix
                 */
            }
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call dateDiff requires 3 arguments.");
    }
}

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

public static Object dateDiff(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 3) {
        try {// w w  w  .j a  v  a 2  s.  c  o m
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return new Double(Double.NaN);
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return Context.getUndefinedValue();
            else {
                java.util.Date dIn1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
                java.util.Date dIn2 = (java.util.Date) Context.jsToJava(ArgList[1], java.util.Date.class);
                String strType = Context.toString(ArgList[2]);
                int iRC = 0;

                Calendar startDate = Calendar.getInstance();
                Calendar endDate = Calendar.getInstance();
                startDate.setTime(dIn1);
                endDate.setTime(dIn2);

                /* Changed by:    Ingo Klose, SHS VIVEON AG,
                 * Date:      27.04.2007
                 *
                 * Calculating time differences using getTimeInMillis() leads to false results
                 * when crossing Daylight Savingstime borders. In order to get correct results
                 * the time zone offsets have to be added.
                 *
                 * Fix:       1.    calculate correct milli seconds for start and end date
                 *             2.    replace endDate.getTimeInMillis() with endL
                 *                and startDate.getTimeInMillis() with startL
                 */
                long endL = endDate.getTimeInMillis()
                        + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                long startL = startDate.getTimeInMillis()
                        + startDate.getTimeZone().getOffset(startDate.getTimeInMillis());

                if (strType.toLowerCase().equals("y")) {
                    return new Double(endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR));
                } else if (strType.toLowerCase().equals("m")) {
                    int iMonthsToAdd = (int) (endDate.get(Calendar.YEAR) - startDate.get(Calendar.YEAR)) * 12;
                    return new Double(
                            (endDate.get(Calendar.MONTH) - startDate.get(Calendar.MONTH)) + iMonthsToAdd);
                } else if (strType.toLowerCase().equals("d")) {
                    return new Double(((endL - startL) / 86400000));
                } else if (strType.toLowerCase().equals("wd")) {
                    int iOffset = -1;
                    if (endDate.before(startDate))
                        iOffset = 1;
                    while (endL < startL || endL > startL) {
                        int day = endDate.get(Calendar.DAY_OF_WEEK);
                        if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY))
                            iRC++;
                        endDate.add(Calendar.DATE, iOffset);
                        endL = endDate.getTimeInMillis()
                                + endDate.getTimeZone().getOffset(endDate.getTimeInMillis());
                    }
                    return new Double(iRC);
                } else if (strType.toLowerCase().equals("w")) {
                    int iDays = (int) ((endL - startL) / 86400000);
                    return new Double(iDays / 7);
                } else if (strType.toLowerCase().equals("ss")) {
                    return new Double(((endL - startL) / 1000));
                } else if (strType.toLowerCase().equals("mi")) {
                    return new Double(((endL - startL) / 60000));
                } else if (strType.toLowerCase().equals("hh")) {
                    return new Double(((endL - startL) / 3600000));
                } else {
                    return new Double(((endL - startL) / 86400000));
                }
                /*
                   * End Bugfix
                 */
            }
        } catch (Exception e) {
            throw Context.reportRuntimeError(e.toString());
        }
    } else {
        throw Context.reportRuntimeError("The function call dateDiff requires 3 arguments.");
    }
}

From source file:com.commander4j.util.JUtility.java

/**
 * Method getDayOfWeekString1.// ww w.  jav a  2  s.  co  m
 * 
 * @param currentDate
 *            Calendar
 * @return int
 */
public static String getDayOfWeekString1(Calendar currentDate) {
    int temp = getDayOfWeek(currentDate);
    String result = "";

    switch (temp) {
    case Calendar.MONDAY:
        result = "A";
        break;
    case Calendar.TUESDAY:
        result = "B";
        break;
    case Calendar.WEDNESDAY:
        result = "C";
        break;
    case Calendar.THURSDAY:
        result = "D";
        break;
    case Calendar.FRIDAY:
        result = "E";
        break;
    case Calendar.SATURDAY:
        result = "F";
        break;
    case Calendar.SUNDAY:
        result = "G";
        break;
    }

    return result;
}