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.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object dateDiff(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 3) {
        try {//  ww  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 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]).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 Context.reportRuntimeError(e.toString());
        }
    } else {
        throw Context.reportRuntimeError("The function call dateDiff requires 3 arguments.");
    }
}

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

public static Object getNextWorkingDay(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    // (Date dIn){
    if (ArgList.length == 1) {
        try {//  ww  w  . j  a va  2  s.  c om
            if (isNull(ArgList[0])) {
                return null;
            } else if (isUndefined(ArgList[0])) {
                return undefinedValue;
            }
            java.util.Date dIn = (java.util.Date) ArgList[0];
            Calendar startDate = Calendar.getInstance();
            startDate.setTime(dIn);
            startDate.add(Calendar.DATE, 1);
            while (startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                startDate.add(Calendar.DATE, 1);
            }
            return startDate.getTime();
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call getNextWorkingDay requires 1 argument.");
    }
}

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

public static Object getNextWorkingDay(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    //(Date dIn){
    if (ArgList.length == 1) {
        try {//ww w .j a v  a  2s .c o  m
            if (isNull(ArgList[0]))
                return null;
            else if (isUndefined(ArgList[0]))
                return undefinedValue;
            java.util.Date dIn = (java.util.Date) ArgList[0];
            Calendar startDate = Calendar.getInstance();
            startDate.setTime(dIn);
            startDate.add(Calendar.DATE, 1);
            while (startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                startDate.add(Calendar.DATE, 1);
            }
            return startDate.getTime();
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call getNextWorkingDay requires 1 argument.");
    }
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testDayNumberOfWeek() throws ParseException {
    final DateParser parser = getInstance("u");
    final Calendar calendar = Calendar.getInstance();

    calendar.setTime(parser.parse("1"));
    Assert.assertEquals(Calendar.MONDAY, calendar.get(Calendar.DAY_OF_WEEK));

    calendar.setTime(parser.parse("6"));
    Assert.assertEquals(Calendar.SATURDAY, calendar.get(Calendar.DAY_OF_WEEK));

    calendar.setTime(parser.parse("7"));
    Assert.assertEquals(Calendar.SUNDAY, calendar.get(Calendar.DAY_OF_WEEK));
}

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

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

From source file:com.virtusa.akura.reporting.controller.GenarateTeacherWisePresentAndAbsentDaysReportController.java

/**
 * Check the given date is a holiday or not.
 *
 * @param holidayList - list consits of Holidays for the given time period.
 * @param currentDate - currentDate// w  w  w  .  j av a  2 s  .co m
 * @param start - Calender object
 * @return boolean
 */
public boolean isHoliday(List<Holiday> holidayList, Date currentDate, Calendar start) {

    boolean flag = false;
    int dayOfWeek = start.get(Calendar.DAY_OF_WEEK);

    for (Holiday tempHoliday : holidayList) {
        if ((currentDate.after(tempHoliday.getStartDate()) && currentDate.before(tempHoliday.getEndDate()))
                || currentDate.equals(tempHoliday.getStartDate())
                || currentDate.equals(tempHoliday.getEndDate()) || Calendar.SATURDAY == dayOfWeek
                || Calendar.SUNDAY == dayOfWeek) {

            flag = true;
            break;
        }
    }
    return flag;
}

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

/**
 * fgt der Liste der Pages und Headlines den bergebenen TimeTable hinzu
 *
 * @param weekData/*from  w ww  .j  a va  2 s .  c  o m*/
 * @param ctxt
 * @author Tobias Janssen
 */
public void appendTimeTableToPager(WeekData weekData, MyContext ctxt) {
    // eine Kopie des Stundenplan-Datums erstellen
    Calendar currentDay = new GregorianCalendar();
    currentDay = (Calendar) weekData.date.clone();

    // den aktuellen Wochentag abrufen
    int currentDayOfWeek = currentDay.get(Calendar.DAY_OF_WEEK);

    if (currentDayOfWeek == Calendar.SUNDAY) {
        // 1000*60*60*24 = 1 Tag!
        currentDay.setTimeInMillis(currentDay.getTimeInMillis() + (1000 * 60 * 60 * 24));
    }
    // den currentDay auf Montag setzten
    if (currentDayOfWeek > Calendar.MONDAY) {
        // 1000*60*60*24 = 1 Tag!
        currentDay
                .setTimeInMillis(currentDay.getTimeInMillis() - (1000 * 60 * 60 * 24 * (currentDayOfWeek - 2)));
    }
    if (context.getResources()
            .getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
        View page = createWeekPage(weekData);
        insertWeekPage(currentDay, page, createWeekHeader(weekData, currentDay), 0,
                ctxt.pager.pageIndex.size());

        // currentDay.roll(Calendar.WEEK_OF_YEAR,true);
        currentDay.setTimeInMillis(currentDay.getTimeInMillis() + 86400000);

    } else {
        // alle Tage der Woche hinzufgen
        for (int x = Calendar.MONDAY; x < Calendar.SATURDAY; x++) {
            // eine Tagesansicht erstellen
            List<TimetableViewObject> list = createTimetableDayViewObject(weekData, currentDay);

            View page = createPage(weekData, list);
            insertDayPage(currentDay, page, createDayHeader(weekData, currentDay), 0,
                    ctxt.pager.pageIndex.size());

            // currentDay.roll(Calendar.DAY_OF_YEAR,1);
            // einen tag weiter vor
            currentDay.setTimeInMillis(currentDay.getTimeInMillis() + 86400000);
        }
    }

}

From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object getNextWorkingDay(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    // (Date dIn){
    if (ArgList.length == 1) {
        try {//ww  w  . j  a va 2s  .com
            if (isNull(ArgList[0])) {
                return null;
            } else if (isUndefined(ArgList[0])) {
                return Context.getUndefinedValue();
            }
            java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            Calendar startDate = Calendar.getInstance();
            startDate.setTime(dIn);
            startDate.add(Calendar.DATE, 1);
            while (startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                    || startDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                startDate.add(Calendar.DATE, 1);
            }
            return startDate.getTime();
        } catch (Exception e) {
            throw Context.reportRuntimeError(e.toString());
        }
    } else {
        throw Context.reportRuntimeError("The function call getNextWorkingDay requires 1 argument.");
    }
}

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

public static Object dateAdd(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 3) {
        try {// w w w  . j  a v a2s.c o m
            if (isNull(ArgList, new int[] { 0, 1, 2 })) {
                return null;
            } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) {
                return undefinedValue;
            }
            java.util.Date dIn = (java.util.Date) ArgList[0];
            String strType = ((String) ArgList[1]).toLowerCase();
            int iValue = (Integer) ArgList[2];
            Calendar cal = Calendar.getInstance();
            cal.setTime(dIn);
            if (strType.equals("y")) {
                cal.add(Calendar.YEAR, iValue);
            } else if (strType.equals("m")) {
                cal.add(Calendar.MONTH, iValue);
            } else if (strType.equals("d")) {
                cal.add(Calendar.DATE, iValue);
            } else if (strType.equals("w")) {
                cal.add(Calendar.WEEK_OF_YEAR, iValue);
            } else if (strType.equals("wd")) {
                int iOffset = 0;
                while (iOffset < iValue) {
                    int day = cal.get(Calendar.DAY_OF_WEEK);
                    cal.add(Calendar.DATE, 1);
                    if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY)) {
                        iOffset++;
                    }
                }
            } else if (strType.equals("hh")) {
                cal.add(Calendar.HOUR, iValue);
            } else if (strType.equals("mi")) {
                cal.add(Calendar.MINUTE, iValue);
            } else if (strType.equals("ss")) {
                cal.add(Calendar.SECOND, iValue);
            }
            return cal.getTime();
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call dateAdd requires 3 arguments.");
    }
}

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

public static Object dateAdd(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 3) {
        try {/*from w  w w  .  java2s  . c o m*/
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return undefinedValue;
            java.util.Date dIn = (java.util.Date) ArgList[0];
            String strType = (String) ArgList[1];
            int iValue = (int) (Integer) ArgList[2];
            Calendar cal = Calendar.getInstance();
            cal.setTime(dIn);
            if (strType.toLowerCase().equals("y"))
                cal.add(Calendar.YEAR, iValue);
            else if (strType.toLowerCase().equals("m"))
                cal.add(Calendar.MONTH, iValue);
            else if (strType.toLowerCase().equals("d"))
                cal.add(Calendar.DATE, iValue);
            else if (strType.toLowerCase().equals("w"))
                cal.add(Calendar.WEEK_OF_YEAR, iValue);
            else if (strType.toLowerCase().equals("wd")) {
                int iOffset = 0;
                while (iOffset < iValue) {
                    int day = cal.get(Calendar.DAY_OF_WEEK);
                    cal.add(Calendar.DATE, 1);
                    if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY))
                        iOffset++;
                }
            } else if (strType.toLowerCase().equals("hh"))
                cal.add(Calendar.HOUR, iValue);
            else if (strType.toLowerCase().equals("mi"))
                cal.add(Calendar.MINUTE, iValue);
            else if (strType.toLowerCase().equals("ss"))
                cal.add(Calendar.SECOND, iValue);
            return cal.getTime();
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call dateAdd requires 3 arguments.");
    }
}