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:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java

/**
 * @return Indica si un da es festivo//from   w w w.  j a  v a 2 s . com
 */
private boolean isHoliday(List<Holiday> fiestas, Date date) {
    //  Es fin de semana ?
    Calendar cActual = Calendar.getInstance();
    cActual.setTime(date);
    if ((cActual.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
            || (cActual.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {
        return true;
    }

    Iterator<Holiday> ite = fiestas.iterator();
    Holiday current;

    while (ite.hasNext()) {
        current = ite.next();
        if (DateUtils.isSameDay(current.getDate(), date)) {
            return true;
        }
    }

    return false;
}

From source file:stepReport.model.PeriodoModel.java

/**
 * Retorna a data da semana no periodo de 1 ano
 * @param Ano//from  w ww . j a  v  a2  s  .  co  m
 * @return 
 */
public String[] calcPeriodoAno(String Ano) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, Integer.parseInt(Ano));
    c.set(Calendar.DAY_OF_YEAR, 1);
    int day = c.get(Calendar.DAY_OF_WEEK);
    while (day != Calendar.SUNDAY) {
        c.add(Calendar.DAY_OF_WEEK, 1);
        day = c.get(Calendar.DAY_OF_WEEK);
    }

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String dataIni = fmt.format(c.getTime());

    c.set(Calendar.YEAR, Integer.parseInt(Ano));
    c.set(Integer.parseInt(Ano), Calendar.DECEMBER, 31);
    day = c.get(Calendar.DAY_OF_WEEK);
    while (day != Calendar.SUNDAY) {
        c.add(Calendar.DAY_OF_WEEK, 1);
        day = c.get(Calendar.DAY_OF_WEEK);
    }

    String dataFim = fmt.format(c.getTime());

    String v[] = { dataIni, dataFim };
    return v;
}

From source file:org.kuali.student.r2.core.scheduling.util.SchedulingServiceUtil.java

/**
 * Converts a list of Calendar constants (i.e. Calendar.MONDAY, Calendar.FRIDAY) into a string of characters representing those days
 * Used in DTO/Entity translations for TimeSlot
 *
 * @param weekdaysList/*from  w w w.  j a va  2s.  c o m*/
 * @return
 */
public static String weekdaysList2WeekdaysString(List<Integer> weekdaysList) {
    StringBuilder result = new StringBuilder();

    for (Integer day : weekdaysList) {
        switch (day) {
        case Calendar.MONDAY: {
            result.append(SchedulingServiceConstants.MONDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.TUESDAY: {
            result.append(SchedulingServiceConstants.TUESDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.WEDNESDAY: {
            result.append(SchedulingServiceConstants.WEDNESDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.THURSDAY: {
            result.append(SchedulingServiceConstants.THURSDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.FRIDAY: {
            result.append(SchedulingServiceConstants.FRIDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.SATURDAY: {
            result.append(SchedulingServiceConstants.SATURDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.SUNDAY: {
            result.append(SchedulingServiceConstants.SUNDAY_TIMESLOT_DAY_CODE);
            break;
        }
        }
    }

    return result.toString();
}

From source file:verdandi.model.WeekSelectorModel.java

private String getDateValue() {
    StringBuffer buf = new StringBuffer();
    Calendar cal = (Calendar) parent.getCurrentWeek().clone();
    buf.append(WEEK_OF_YEAR_PREFIX);//w  ww  . j  a va 2  s .c  o  m
    if (cal.get(Calendar.WEEK_OF_YEAR) < 10) {
        buf.append("0");
    }
    buf.append(cal.get(Calendar.WEEK_OF_YEAR));
    buf.append(": ");
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    buf.append(dfmt.format(cal.getTime()));
    buf.append(" - ");
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    buf.append(dfmt.format(cal.getTime()));
    return buf.toString();
}

From source file:com.netflix.simianarmy.basic.BasicCalendar.java

/** {@inheritDoc} */
@Override//from   ww  w.  j a  v  a  2 s  . c  om
public boolean isMonkeyTime(Monkey monkey) {
    if (cfg != null && cfg.getStrOrElse("simianarmy.calendar.isMonkeyTime", null) != null) {
        return cfg.getBool("simianarmy.calendar.isMonkeyTime");
    }

    Calendar now = now();
    int dow = now.get(Calendar.DAY_OF_WEEK);
    if (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) {
        return false;
    }

    int hour = now.get(Calendar.HOUR_OF_DAY);
    if (hour < openHour || hour > closeHour) {
        return false;
    }

    if (isHoliday(now)) {
        return false;
    }

    return true;
}

From source file:jp.co.nemuzuka.utils.DateTimeUtils.java

/**
 * ??.//  www . ja v  a 2  s .co  m
 * ??????Date????
 * ?????????????????
 * ???????????
 * @param targetYyyyMM ?
 * @return index 0:??Date index 1:?Date
 */
public static List<Date> getStartEndDate4SunDay(String targetYyyyMM) {
    List<Date> list = getStartEndDate(targetYyyyMM);
    Date startDate = list.get(0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(getTimeZone());

    //??
    while (true) {
        calendar.setTime(startDate);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            //?????
            break;
        }
        //1??
        startDate = addDays(startDate, -1);
    }

    Date endDate = list.get(1);
    //?
    while (true) {
        calendar.setTime(endDate);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
            //?????
            break;
        }
        //1?
        endDate = addDays(endDate, 1);
    }

    List<Date> retList = new ArrayList<Date>();
    retList.add(startDate);
    retList.add(endDate);
    return retList;
}

From source file:com.shalzz.attendance.adapter.TimeTablePagerAdapter.java

public int getPositionForDate(Date date) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean show = sharedPref.getBoolean(mContext.getString(R.string.pref_key_show_weekends), true);
    if (!show) {//from   w  ww  .jav  a2  s.c om
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
            calendar.add(Calendar.DATE, 1);
        }
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            calendar.add(Calendar.DATE, 1);
        }
        date = calendar.getTime();
    }

    return positions.get(date);
}

From source file:com.hurence.logisland.utils.DateUtils.java

/**
 * Check if the date parameter occurs during a weekend.
 *
 * @return Current time in ISO-8601 format, e.g. : "2012-07-03T07:59:09.206 UTC"
 *//*from w  ww.j a v a  2  s  .  com*/
public static boolean isWeekend(Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
        return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
    } else {
        return false;
    }

}

From source file:org.sipfoundry.sipxconfig.device.DeviceTimeZone.java

private void setDstParameters(String dstRule) {
    if (m_useDaylight) {
        // DST: Daylight Savings Time
        // LST: Local Standard Time - local time when DST is not in effect
        // LDT: Local Daylight Time - local time when DST is in effect
        if (dstRule.equals(DST_US)) {
            // http://en.wikipedia.org/wiki/Daylight_saving_time_around_the_world#North_America
            //   into DST    -  02:00 LST --> 03:00 LDT
            //   out of DST  -  02:00 LDT --> 01:00 LST

            m_startMonth = Calendar.MARCH;
            m_startWeek = 2;/*from w ww  .ja  v a  2s  .  c o  m*/
            m_startDayOfWeek = Calendar.SUNDAY;
            m_startTime = 2/*am*/ * MINUTES_PER_HOUR; // 02:00 LST

            m_stopMonth = Calendar.NOVEMBER;
            m_stopWeek = 1;
            m_stopDayOfWeek = Calendar.SUNDAY;
            m_stopTime = 2/*am*/ * MINUTES_PER_HOUR; // 02:00 LDT

        } else if (dstRule.equals(DST_EU)) {
            // http://en.wikipedia.org/wiki/European_Summer_Time
            //   into DST    -  01:00 GMT --> 02:00 GMT
            //   out of DST  -  01:00 GMT --> 00:00 GMT

            m_startMonth = Calendar.MARCH;
            m_startWeek = DST_LASTWEEK;
            m_startDayOfWeek = Calendar.SUNDAY;

            // LST = 01:00 GMT + Time Zone Offset
            m_startTime = (1/*am*/ * MINUTES_PER_HOUR) + getOffset();

            m_stopMonth = Calendar.OCTOBER;
            m_stopWeek = DST_LASTWEEK;
            m_stopDayOfWeek = Calendar.SUNDAY;

            // LDT = 01:00 GMT + Time Zone Offset + Daylight Savings
            m_stopTime = (1/*am*/ * MINUTES_PER_HOUR) + getOffset() + getDstSavings();

        }
    } else {
        // if we don't use DST, set the parameters to 0 to not confuse the phones
        m_startMonth = 0;
        m_startWeek = 0;
        m_startDayOfWeek = 0;
        m_startTime = 0;

        m_stopMonth = 0;
        m_stopDayOfWeek = 0;
        m_stopWeek = 0;
        m_stopTime = 0;
    }
}

From source file:de.micmun.android.workdaystarget.DayCalculator.java

/**
 * Returns the number of days between today and target, skipped days in
 * appliance of checkedDays.//from   w  w  w .  j  a  v  a 2  s  .  c o  m
 *
 * @param t           Date of the target, to which to calculate the working days.
 * @param checkedDays Array with boolean flags, which says if a weekday should count
 *                    or not.
 * @return days to target.
 * @throws JSONException if an error occurs while getting the holidays from web service.
 */
public int getDaysLeft(Date t, boolean[] checkedDays) throws JSONException {
    // sets target time at midnight
    target.setTime(t);
    setMidnight(target);

    int sign = 1;

    if (target.getTimeInMillis() < today.getTimeInMillis()) {
        Calendar tmp = Calendar.getInstance();
        tmp.setTimeInMillis(target.getTimeInMillis());
        target.setTimeInMillis(today.getTimeInMillis());
        today.setTimeInMillis(tmp.getTimeInMillis());
        sign = -1; // negative days in the past
    }

    // Holidays
    ArrayList<Date> holidays = getHolidays();

    // current time
    Calendar curr = Calendar.getInstance();
    curr.setTime(today.getTime());

    int count = 0;

    while (curr.getTimeInMillis() != target.getTimeInMillis()) {
        curr.add(Calendar.DAY_OF_MONTH, 1);
        int dayOfWeek = curr.get(Calendar.DAY_OF_WEEK);

        if (!checkedDays[POS_HOLIDAY] && holidays.contains(curr.getTime())) {
            continue;
        } else if (!checkedDays[POS_SUNDAY] && dayOfWeek == Calendar.SUNDAY) {
            continue;
        } else if (dayOfWeek != Calendar.SUNDAY && !checkedDays[dayOfWeek - Calendar.MONDAY]) {
            continue;
        }
        count++;
    }

    count *= sign; // if target is in the past, sign == -1

    return count;
}