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:org.skfiy.typhon.spi.hero.HeroProvider.java

/**
 * //from  ww w.ja  va 2  s .c om
 * @param packet
 */
public void buyTuhaoLottery(Packet packet) {
    Player player = SessionUtils.getPlayer();
    MultipleValue result = MultipleValue.createResult(packet);

    Calendar cal = Calendar.getInstance();
    // ?
    int weekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
    if (weekOfYear != 1 && cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        weekOfYear--;
    }

    TuhaoWeekLottery tuhaoWeekLottery = tuhaoWeekLotteries.get(weekOfYear - 1);

    boolean heroed = drawTuhao0(player, tuhaoWeekLottery);
    if (heroed) {
        result.addVal(pushLottery(tuhaoWeekLottery, false, true));
    } else {
        int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        Lottery tuhaoDayLottery = spueLottery(tuhaoRandom, tuhaoDayLotteries.get(dayOfMonth - 1), 100);
        result.addVal(pushLottery(tuhaoDayLottery, false, true));
    }

    Lottery tuhaoLottery;
    for (int i = 0; i < 5; i++) {
        tuhaoLottery = spueLottery(tuhaoRandom, tuhaoLotteries, tuhaoRandomFactor);
        result.addVal(pushLottery(tuhaoLottery, false, true));
    }

    int diamond = Typhons.getInteger("typhon.spi.hero.diamondTuhaoLottery.1.depletion");

    JSONObject plog = new JSONObject();
    plog.put("name", "Tuhao");
    plog.put("items", result.getVals());
    SessionUtils.decrementDiamond(diamond, plog.toJSONString());

    player.getSession().write(result);
}

From source file:com.xunlei.util.DateUtils.java

/**
 * <p>/* ww  w.j ava  2s .c o m*/
 * This constructs an <code>Iterator</code> over each day in a date range defined by a focus date and range style.
 * </p>
 * <p>
 * For instance, passing Thursday, July 4, 2002 and a <code>RANGE_MONTH_SUNDAY</code> will return an <code>Iterator</code> that starts with Sunday, June 30, 2002 and ends with Saturday, August 3,
 * 2002, returning a Calendar instance for each intermediate day.
 * </p>
 * <p>
 * This method provides an iterator that returns Calendar objects. The days are progressed using {@link Calendar#add(int, int)}.
 * </p>
 * 
 * @param focus the date to work with
 * @param rangeStyle the style constant to use. Must be one of {@link DateUtils#RANGE_MONTH_SUNDAY}, {@link DateUtils#RANGE_MONTH_MONDAY}, {@link DateUtils#RANGE_WEEK_SUNDAY},
 *        {@link DateUtils#RANGE_WEEK_MONDAY}, {@link DateUtils#RANGE_WEEK_RELATIVE}, {@link DateUtils#RANGE_WEEK_CENTER}
 * @return the date iterator
 * @throws IllegalArgumentException if the date is <code>null</code>
 * @throws IllegalArgumentException if the rangeStyle is invalid
 */
public static Iterator iterator(Calendar focus, int rangeStyle) {
    if (focus == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    Calendar start = null;
    Calendar end = null;
    int startCutoff = Calendar.SUNDAY;
    int endCutoff = Calendar.SATURDAY;
    switch (rangeStyle) {
    case RANGE_MONTH_SUNDAY:
    case RANGE_MONTH_MONDAY:
        // Set start to the first of the month
        start = truncate(focus, Calendar.MONTH);
        // Set end to the last of the month
        end = (Calendar) start.clone();
        end.add(Calendar.MONTH, 1);
        end.add(Calendar.DATE, -1);
        // Loop start back to the previous sunday or monday
        if (rangeStyle == RANGE_MONTH_MONDAY) {
            startCutoff = Calendar.MONDAY;
            endCutoff = Calendar.SUNDAY;
        }
        break;
    case RANGE_WEEK_SUNDAY:
    case RANGE_WEEK_MONDAY:
    case RANGE_WEEK_RELATIVE:
    case RANGE_WEEK_CENTER:
        // Set start and end to the current date
        start = truncate(focus, Calendar.DATE);
        end = truncate(focus, Calendar.DATE);
        switch (rangeStyle) {
        case RANGE_WEEK_SUNDAY:
            // already set by default
            break;
        case RANGE_WEEK_MONDAY:
            startCutoff = Calendar.MONDAY;
            endCutoff = Calendar.SUNDAY;
            break;
        case RANGE_WEEK_RELATIVE:
            startCutoff = focus.get(Calendar.DAY_OF_WEEK);
            endCutoff = startCutoff - 1;
            break;
        case RANGE_WEEK_CENTER:
            startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3;
            endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3;
            break;
        }
        break;
    default:
        throw new IllegalArgumentException("The range style " + rangeStyle + " is not valid.");
    }
    if (startCutoff < Calendar.SUNDAY) {
        startCutoff += 7;
    }
    if (startCutoff > Calendar.SATURDAY) {
        startCutoff -= 7;
    }
    if (endCutoff < Calendar.SUNDAY) {
        endCutoff += 7;
    }
    if (endCutoff > Calendar.SATURDAY) {
        endCutoff -= 7;
    }
    while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) {
        start.add(Calendar.DATE, -1);
    }
    while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) {
        end.add(Calendar.DATE, 1);
    }
    return new DateIterator(start, end);
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private Map<Integer, String> getWeekDaysMap() {
    weekDaysMap = new HashMap<Integer, String>();
    weekDaysMap.put(Calendar.SUNDAY, msgs.getString("day_sun"));
    weekDaysMap.put(Calendar.MONDAY, msgs.getString("day_mon"));
    weekDaysMap.put(Calendar.TUESDAY, msgs.getString("day_tue"));
    weekDaysMap.put(Calendar.WEDNESDAY, msgs.getString("day_wed"));
    weekDaysMap.put(Calendar.THURSDAY, msgs.getString("day_thu"));
    weekDaysMap.put(Calendar.FRIDAY, msgs.getString("day_fri"));
    weekDaysMap.put(Calendar.SATURDAY, msgs.getString("day_sat"));
    return weekDaysMap;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSunday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SUNDAY];
    weekdays[1] = localeWeekdays[Calendar.MONDAY];
    weekdays[2] = localeWeekdays[Calendar.TUESDAY];
    weekdays[3] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[4] = localeWeekdays[Calendar.THURSDAY];
    weekdays[5] = localeWeekdays[Calendar.FRIDAY];
    weekdays[6] = localeWeekdays[Calendar.SATURDAY];

    return weekdays;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSaturday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SATURDAY];
    weekdays[1] = localeWeekdays[Calendar.SUNDAY];
    weekdays[2] = localeWeekdays[Calendar.MONDAY];
    weekdays[3] = localeWeekdays[Calendar.TUESDAY];
    weekdays[4] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[5] = localeWeekdays[Calendar.THURSDAY];
    weekdays[6] = localeWeekdays[Calendar.FRIDAY];

    return weekdays;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapWeekdaysStartingWithSunday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SUNDAY];
    weekdays[1] = localeWeekdays[Calendar.MONDAY];
    weekdays[2] = localeWeekdays[Calendar.TUESDAY];
    weekdays[3] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[4] = localeWeekdays[Calendar.THURSDAY];
    weekdays[5] = localeWeekdays[Calendar.FRIDAY];
    weekdays[6] = localeWeekdays[Calendar.SATURDAY];

    return weekdays;
}

From source file:com.autentia.tnt.bean.activity.ActivityBean.java

private void fillHolidays(SimpleScheduleModel model) {

    Calendar calMin = Calendar.getInstance();
    Calendar calMax = Calendar.getInstance();

    calMin = getMinimumSearchTime(selectedDate);
    calMax = getMaximumSearchTime(selectedDate);

    RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
    RequestHolidaySearch rhSearch = new RequestHolidaySearch();
    rhSearch.setUserRequest(authManager.getCurrentPrincipal().getUser());
    rhSearch.setState(HolidayState.ACCEPT);
    rhSearch.setStartBeginDate(calMin.getTime());
    rhSearch.setEndBeginDate(calMax.getTime());
    rhSearch.setStartFinalDate(calMin.getTime());
    rhSearch.setEndFinalDate(calMax.getTime());

    List<RequestHoliday> listH = rhManager.getAllEntities(rhSearch, null);

    for (RequestHoliday rH : listH) {
        Calendar cActual = Calendar.getInstance();
        cActual.setTime(rH.getBeginDate());
        while (!cActual.getTime().after(rH.getFinalDate())) {
            if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                    && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                model.setHoliday(cActual.getTime(), FacesUtils.getMessage("activity.acceptedHolidays"));
            }/* w  w  w .j ava2  s . com*/
            cActual.add(Calendar.DAY_OF_MONTH, 1);
        }

    }

    HolidaySearch monthSearch = new HolidaySearch();

    monthSearch.setStartDate(calMin.getTime());
    monthSearch.setEndDate(calMax.getTime());
    List<Holiday> listaHolidays = holidayManager.getAllEntities(monthSearch, null);

    for (Holiday holiday : listaHolidays) {
        model.setHoliday(holiday.getDate(), holiday.getDescription());
    }

}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private static String[] mapWeekdays(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private static String[] mapWeekdaysLong(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}

From source file:edu.jhuapl.openessence.controller.ReportController.java

private int getCalWeekStartDay(Map<String, ResolutionHandler> resolutionHandlers) {
    ResolutionHandler handler = resolutionHandlers.get("weekly");
    int startDay;
    if (handler == null || !(handler instanceof PgSqlWeeklyHandler)) {
        switch (Integer.parseInt(messageSource.getMessage("epidemiological.day.start",
                Integer.toString(DEFAULT_WEEK_STARTDAY)))) {
        case 0:/*from w ww  .  j a va  2s  .c  o  m*/
            startDay = Calendar.SUNDAY;
            break;
        case 2:
            startDay = Calendar.TUESDAY;
            break;
        case 3:
            startDay = Calendar.WEDNESDAY;
            break;
        case 4:
            startDay = Calendar.THURSDAY;
            break;
        case 5:
            startDay = Calendar.FRIDAY;
            break;
        case 6:
            startDay = Calendar.SATURDAY;
            break;
        default:
            startDay = Calendar.MONDAY;
            break;
        }
        return startDay;
    }
    return ((PgSqlWeeklyHandler) handler).getCalWeekStartDay();
}