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:com.l2jfree.gameserver.model.entity.CCHSiege.java

public boolean checkIfAlreadyRegisteredForSameDay(L2Clan clan) {
    for (Siege siege : SiegeManager.getInstance().getSieges()) {
        if (siege.getSiegeDate().get(Calendar.DAY_OF_WEEK) == getSiegeDate().get(Calendar.DAY_OF_WEEK)) {
            if (siege.checkIsAttacker(clan))
                return true;
            if (siege.checkIsDefender(clan))
                return true;
            if (siege.checkIsDefenderWaiting(clan))
                return true;
        }/*from   w  w  w .  j a v a 2  s .c o m*/
    }
    for (CCHSiege siege : CCHManager.getInstance().getSieges()) {
        if (siege.getSiegeDate().get(Calendar.DAY_OF_WEEK) == getSiegeDate().get(Calendar.DAY_OF_WEEK)) {
            if (siege.checkIsAttacker(clan))
                return true;
            if (siege.checkIsDefender(clan))
                return true;
        }
    }
    return false;
}

From source file:org.activequant.util.charting.IntradayMarketTimeline.java

private boolean isActiveDate(Calendar cal, Calendar cal2) {
    int day = cal.get(Calendar.DAY_OF_WEEK);

    long timeSinceStart = cal.get(Calendar.HOUR_OF_DAY) * 3600000 + cal.get(Calendar.MINUTE) * 60000
            + cal.get(Calendar.SECOND) * 1000;

    boolean firstDate = false;

    if (day == Calendar.SUNDAY) {
        firstDate = (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd);
    } else if (day == Calendar.MONDAY) {
        firstDate = (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd);
    } else if (day == Calendar.TUESDAY) {
        firstDate = (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd);
    } else if (day == Calendar.WEDNESDAY) {
        firstDate = (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd);
    } else if (day == Calendar.THURSDAY) {
        firstDate = (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd);
    } else if (day == Calendar.FRIDAY) {
        firstDate = (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd);
    } else if (day == Calendar.SATURDAY) {
        firstDate = (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd);
    } else {//from  www. java2 s .  c  om
        firstDate = false;
    }

    int day2 = cal2.get(Calendar.DAY_OF_WEEK);

    timeSinceStart = cal2.get(Calendar.HOUR_OF_DAY) * 3600000 + cal2.get(Calendar.MINUTE) * 60000
            + cal2.get(Calendar.SECOND) * 1000;

    boolean secondDate = false;

    if (day2 == Calendar.SUNDAY) {
        secondDate = (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd);
    } else if (day2 == Calendar.MONDAY) {
        secondDate = (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd);
    } else if (day2 == Calendar.TUESDAY) {
        secondDate = (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd);
    } else if (day2 == Calendar.WEDNESDAY) {
        secondDate = (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd);
    } else if (day2 == Calendar.THURSDAY) {
        secondDate = (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd);
    } else if (day2 == Calendar.FRIDAY) {
        secondDate = (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd);
    } else if (day2 == Calendar.SATURDAY) {
        secondDate = (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd);
    } else {
        secondDate = false;
    }

    return (firstDate && secondDate);
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

public static int getWeek() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    int w = cal.get(Calendar.DAY_OF_WEEK);
    return w;//from  w ww  . ja  v a 2  s  . co m
}

From source file:com.espertech.esper.regression.pattern.TestCronParameter.java

private int getLastDayOfWeekInMonth(int day, int year) {
    if (day < 0 || day > 7) {
        throw new IllegalArgumentException("Last xx day of the month has to be a day of week (0-7)");
    }// w  w w .  j  a v  a2s.c  o  m
    int dayOfWeek = getDayOfWeek(day, year);
    setTime(year);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    int dayDiff = calendar.get(Calendar.DAY_OF_WEEK) - dayOfWeek;
    if (dayDiff > 0) {
        calendar.add(Calendar.DAY_OF_WEEK, -dayDiff);
    } else if (dayDiff < 0) {
        calendar.add(Calendar.DAY_OF_WEEK, -7 - dayDiff);
    }
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:com.l2jfree.gameserver.model.sevensigns.SevenSigns.java

public final int getDaysToPeriodChange() {
    int numDays = _calendar.get(Calendar.DAY_OF_WEEK) - PERIOD_START_DAY;

    if (numDays < 0)
        return 0 - numDays;

    return 7 - numDays;
}

From source file:Holidays.java

public static java.util.Calendar PresidentsDayObserved(int nYear) {
    // Third Monday in February
    int nX;/* ww w . j a  va 2 s  .c  o  m*/
    int nMonth = 1; // February

    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(nYear, nMonth, 1);

    nX = cal.get(Calendar.DAY_OF_WEEK);

    switch (nX) {
    case 0: {// Sunday
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 16);
        return cal;
    }
    case 1: {// Monday
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 15);
        return cal;
    }
    case 2: // Tuesday
    {
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 21);
        return cal;
    }
    case 3: // Wednesday
    {
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 20);
        return cal;
    }
    case 4: // Thrusday
    {
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 19);
        return cal;
    }
    case 5: // Friday
    {
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 18);
        return cal;
    }
    default: // Saturday
    {
        cal = java.util.Calendar.getInstance();
        cal.set(nYear, nMonth, 17);
        return cal;
    }
    }
}

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

public static Object getDayNumber(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 2) {
        try {//  ww w.ja v  a2  s  .  com
            if (isNull(ArgList[0]))
                return new Double(Double.NaN);
            else if (isUndefined(ArgList[0]))
                return undefinedValue;
            else {
                java.util.Date dIn = (java.util.Date) ArgList[0];
                String strType = (String) ArgList[1];
                Calendar startDate = Calendar.getInstance();
                startDate.setTime(dIn);
                if (strType.toLowerCase().equals("y"))
                    return new Double(startDate.get(Calendar.DAY_OF_YEAR));
                else if (strType.toLowerCase().equals("m"))
                    return new Double(startDate.get(Calendar.DAY_OF_MONTH));
                else if (strType.toLowerCase().equals("w"))
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK));
                else if (strType.toLowerCase().equals("wm"))
                    return new Double(startDate.get(Calendar.DAY_OF_WEEK_IN_MONTH));
                return new Double(startDate.get(Calendar.DAY_OF_YEAR));
            }
        } catch (Exception e) {
            return null;
            //throw new RuntimeException(e.toString());      
        }
    } else {
        throw new RuntimeException("The function call getDayNumber requires 2 arguments.");
    }
}

From source file:com.application.utils.FastDateParser.java

/**
 * Obtain a Strategy given a field from a SimpleDateFormat pattern
 *
 * @param formatField      A sub-sequence of the SimpleDateFormat pattern
 * @param definingCalendar The calendar to obtain the short and long values
 * @return The Strategy that will handle parsing for the field
 *//*from   w  w w  .  j a v  a  2  s  .  c  o  m*/
private Strategy getStrategy(final String formatField, final Calendar definingCalendar) {
    switch (formatField.charAt(0)) {
    case '\'':
        if (formatField.length() > 2) {
            return new CopyQuotedStrategy(formatField.substring(1, formatField.length() - 1));
        }
        //$FALL-THROUGH$
    default:
        return new CopyQuotedStrategy(formatField);
    case 'D':
        return DAY_OF_YEAR_STRATEGY;
    case 'E':
        return getLocaleSpecificStrategy(Calendar.DAY_OF_WEEK, definingCalendar);
    case 'F':
        return DAY_OF_WEEK_IN_MONTH_STRATEGY;
    case 'G':
        return getLocaleSpecificStrategy(Calendar.ERA, definingCalendar);
    case 'H':
        return MODULO_HOUR_OF_DAY_STRATEGY;
    case 'K':
        return HOUR_STRATEGY;
    case 'M':
        return formatField.length() >= 3 ? getLocaleSpecificStrategy(Calendar.MONTH, definingCalendar)
                : NUMBER_MONTH_STRATEGY;
    case 'S':
        return MILLISECOND_STRATEGY;
    case 'W':
        return WEEK_OF_MONTH_STRATEGY;
    case 'a':
        return getLocaleSpecificStrategy(Calendar.AM_PM, definingCalendar);
    case 'd':
        return DAY_OF_MONTH_STRATEGY;
    case 'h':
        return MODULO_HOUR_STRATEGY;
    case 'k':
        return HOUR_OF_DAY_STRATEGY;
    case 'm':
        return MINUTE_STRATEGY;
    case 's':
        return SECOND_STRATEGY;
    case 'w':
        return WEEK_OF_YEAR_STRATEGY;
    case 'y':
        return formatField.length() > 2 ? LITERAL_YEAR_STRATEGY : ABBREVIATED_YEAR_STRATEGY;
    case 'Z':
    case 'z':
        return getLocaleSpecificStrategy(Calendar.ZONE_OFFSET, definingCalendar);
    }
}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Given an alarm in hours and minutes, return a time suitable for
 * setting in AlarmManager./* w w w.  j a  v  a 2 s .c  o m*/
 */
static Calendar calculateAlarm(int hour, int minute, Alarm.DaysOfWeek daysOfWeek) {

    // start with now
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());

    int nowHour = c.get(Calendar.HOUR_OF_DAY);
    int nowMinute = c.get(Calendar.MINUTE);

    // if alarm is behind current time, advance one day
    if (hour < nowHour || hour == nowHour && minute <= nowMinute) {
        c.add(Calendar.DAY_OF_YEAR, 1);
    }
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    int addDays = daysOfWeek.getNextAlarm(c);
    if (addDays > 0)
        c.add(Calendar.DAY_OF_WEEK, addDays);
    return c;
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.SubjectService.java

/**
 * Finds all the dates which represent the particular day of the week (Monday, Tuesday, etc.)
 * in the specified month.//from ww w.jav  a2s.  c o m
 */
// package level for testing
List<Date> findDaysOfWeekInMonth(int year, int month, int dayOfTheWeek) {
    List<Date> matches = new ArrayList<Date>();
    Calendar search = Calendar.getInstance();
    search.set(year, month, 1);
    while (search.get(Calendar.MONTH) == month
            && search.get(Calendar.DAY_OF_MONTH) <= search.getActualMaximum(Calendar.DAY_OF_MONTH)) {
        System.out.println(search.getTime());
        if (search.get(Calendar.DAY_OF_WEEK) == dayOfTheWeek) {
            matches.add(search.getTime());
        }
        search.add(Calendar.DAY_OF_MONTH, 1);
    }
    return matches;
}