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:fr.paris.lutece.plugins.calendar.service.Utils.java

/**
 * Returns a date code corresponding to a calendar roll of one month
 * @param dateStart The date start/*from w w  w.  ja v a 2s .c om*/
 * @param dateEnd The date end
 * @param arrayExcludedDays list of excluded days
 * @return A date code incremented with strDateRef parameter
 */
public static int getOccurrenceWithinTwoDates(Date dateStart, Date dateEnd, String[] arrayExcludedDays) {
    int cptDate = 0;
    Calendar calendar1 = new GregorianCalendar();
    Calendar calendar2 = new GregorianCalendar();
    calendar1.setTime(dateStart);
    calendar2.setTime(dateEnd);

    if (calendar1.equals(calendar2)) {
        String strDate = getDate(dateStart);
        if (isDayExcluded(getDayOfWeek(strDate), arrayExcludedDays)) {
            return cptDate;
        }
        return ++cptDate;
    }

    while (!calendar1.after(calendar2)) {
        if (!isDayExcluded(calendar1.get(Calendar.DAY_OF_WEEK), arrayExcludedDays)) {
            ++cptDate;
        }
        calendar1.add(Calendar.DATE, 1);
    }

    return cptDate;
}

From source file:com.aurel.track.linkType.MsProjectLinkTypeBL.java

/**
 * Returns number of saturdays from interval. Start date included always, endDate only if includeLastDay == true!
 * @param startDateParam//from ww w.  ja va 2s . co  m
 * @param endDateParam
 * @param includeLastDay
 * @return
 */
public static Integer getNumberOfSaturdaysFromInterval(Date startDateParam, Date endDateParam,
        boolean includeLastDay) {
    Date realEndDate = endDateParam;
    if (includeLastDay) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(realEndDate);
        cal.add(Calendar.DAY_OF_YEAR, 1);
        realEndDate = cal.getTime();
    }
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(startDateParam);
    int numOfSaturdays = 0;
    while (!calendar.getTime().after(realEndDate)) {
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
            numOfSaturdays++;
        }
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
    return numOfSaturdays;
}

From source file:com.clavain.alerts.Methods.java

private static String getScheduleFieldToCheck() {
    GregorianCalendar gc = new GregorianCalendar();
    String retval = "";

    switch (gc.get(Calendar.DAY_OF_WEEK)) {
    case 1:/*from w  ww .  j a v a 2  s  . c  o m*/
        retval = "s_mon";
        break;
    case 2:
        retval = "s_tue";
        break;
    case 3:
        retval = "s_wed";
        break;
    case 4:
        retval = "s_thu";
        break;
    case 5:
        retval = "s_fri";
        break;
    case 6:
        retval = "s_sat";
        break;
    case 7:
        retval = "s_sun";
        break;
    }
    return retval;
}

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 {/*w  ww .j a v  a  2 s.  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:com.mb.framework.util.DateTimeUtil.java

/**
 * This method is used for checking whether the target date is weekend
 * // w ww.j  a  v  a 2 s  . c  o m
 * @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:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return the first day of week function of the date .
 * @param date the date/* ww w  .j  av a  2  s.co m*/
 * @return the first day of week function of the date.
 */
public static Timestamp getFirstDayOfWeek(Timestamp date) {
    Calendar caldate = new GregorianCalendar();
    caldate.setTime(date);
    caldate.set(Calendar.MILLISECOND, caldate.getActualMinimum(Calendar.MILLISECOND));
    caldate.set(Calendar.SECOND, caldate.getActualMinimum(Calendar.SECOND));
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMinimum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMinimum(Calendar.MINUTE));
    caldate.set(Calendar.DAY_OF_WEEK, caldate.getFirstDayOfWeek());

    Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

    return timeStamp;
}

From source file:com.projity.pm.calendar.CalendarDefinition.java

public static final int getDayOfWeek(long date) {
    Calendar scratchDate = DateTime.calendarInstance();
    scratchDate.setTimeInMillis(date);/*from   w  ww. j  ava  2 s.  co  m*/
    return scratchDate.get(Calendar.DAY_OF_WEEK) - 1;
}

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

/*****************************************
 * @ ???//from w w w  .  java2  s .com
 ****************************************/
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:com.espertech.esper.schedule.ScheduleComputeHelper.java

private static boolean isWeekday(Calendar cal) {
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    return !(dayOfWeek < Calendar.MONDAY || dayOfWeek > Calendar.FRIDAY);
}

From source file:abelymiguel.miralaprima.GetPrima.java

private Boolean isWeekend() {

    Boolean isWeekend;//from w ww.j a  v  a 2 s. c o m
    try {
        Timestamp dateToday = this.getTimestamp();

        Calendar calToday = Calendar.getInstance();
        calToday.setTime(dateToday);

        int day = calToday.get(java.util.Calendar.DAY_OF_WEEK);

        if (day == 7 || day == 1) {
            isWeekend = true;
        } else {
            isWeekend = false;
        }
        //            System.out.println("isWeekend " + isWeekend + " day " + day);
    } catch (Exception e) {
        Logger.getLogger(GetPrima.class.getName()).log(Level.WARNING, null, e);
        isWeekend = false;
    }

    return isWeekend;
}