Example usage for java.util Calendar MONDAY

List of usage examples for java.util Calendar MONDAY

Introduction

In this page you can find the example usage for java.util Calendar MONDAY.

Prototype

int MONDAY

To view the source code for java.util Calendar MONDAY.

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Monday.

Usage

From source file:com.daoke.mobileserver.user.controller.UserController.java

/**
 * @param appKey/*from  ww  w . j  a va2s .c  o m*/
 * @param accountID
 * @param taskInfoType 1. 2  3 4 ?
 * @return
 */
@RequestMapping("/getUserTaskInfo")
@ResponseBody
public CommonJsonResult getUserTaskInfo(@RequestParam String appKey, @RequestParam String accountID,
        @RequestParam int taskInfoType) {
    CommonJsonResult result = new CommonJsonResult();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    List<Map<String, Object>> map = null;
    Map<String, Object> resultMap = new HashMap<String, Object>();
    Map<String, Object> taskInfo = null;
    long resultInfo = 0;
    String viewInfo = "";
    try {

        if (taskInfoType == 1) {
            Long dis = drivingRedisService.getHRuleValue(RedisVariable.powerDay.POWEROFF_SEVEN_DAY, accountID);
            resultInfo = dis % 1000;
            Calendar cd = Calendar.getInstance();
            //1970-01-01
            long allDays = AbDateUtil.getAllDays();
            long restDays = dis / 1000;
            if (((allDays - restDays) + 1) != resultInfo) {
                resultInfo = 0;
            }
            viewInfo = "" + resultInfo + "";
            map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                    format.format(cd.getTime()));
        }
        if (taskInfoType == 2) {
            Long dis = drivingRedisService.getHRuleValue(RedisVariable.Mileage.DRIVER_MILEAGE_WEEKLY,
                    accountID);
            resultInfo = dis % 100000000;
            viewInfo = "" + (resultInfo / 1000) + "";
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                    format.format(cal.getTime()));

        }
        if (taskInfoType == 3) {
            Calendar c = Calendar.getInstance();
            c.add(Calendar.MONTH, 0);
            c.set(Calendar.DAY_OF_MONTH, 1);
            Long dis = drivingRedisService.getHRuleValue(RedisVariable.Mileage.DRIVER_MILEAGE_MONTH, accountID);
            resultInfo = dis % 100000000;
            viewInfo = "" + (resultInfo / 1000) + "";
            map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType,
                    format.format(c.getTime()));
        }
        if (taskInfoType == 4) {
            UserGrade ug = userGradeService.queryByAccountID(accountID);
            viewInfo = "" + (ug == null ? 0 : ug.getGrade()) + "";
            map = userRochelleRuleService.queryRochellReceiveStatus(accountID, taskInfoType, null);
        }
    } catch (Exception e) {
        result.setERRORCODE(ConstantsUtil.ERRORCODE_SERVICE_ERROR);
        result.setRESULT(ConstantsUtil.RESULT_SERVICE_ERROR);
        return result;
    }
    result.setERRORCODE(ConstantsUtil.ERRORCODE_OK);
    resultMap.put("taskInfo", map);
    resultMap.put("resultInfo", viewInfo);
    result.setRESULT(resultMap);
    return result;
}

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

/**
 * <p>//from w w w . ja  v a 2  s.  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.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 w  w .j  ava2s. c om
            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();
}

From source file:org.unitime.timetable.solver.studentsct.StudentSectioningDatabaseLoader.java

private String datePatternName(DatePattern dp, TimeLocation time) {
    if ("never".equals(iDatePatternFormat))
        return dp.getName();
    if ("extended".equals(iDatePatternFormat) && dp.getType() != DatePattern.sTypeExtended)
        return dp.getName();
    if ("alternate".equals(iDatePatternFormat) && dp.getType() == DatePattern.sTypeAlternate)
        return dp.getName();
    if (time.getWeekCode().isEmpty())
        return time.getDatePatternName();
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.setLenient(true);/*from   w  w  w  . j  a v a2 s . com*/
    cal.setTime(iDatePatternFirstDate);
    int idx = time.getWeekCode().nextSetBit(0);
    cal.add(Calendar.DAY_OF_YEAR, idx);
    Date first = null;
    while (idx < time.getWeekCode().size() && first == null) {
        if (time.getWeekCode().get(idx)) {
            int dow = cal.get(Calendar.DAY_OF_WEEK);
            switch (dow) {
            case Calendar.MONDAY:
                if ((time.getDayCode() & DayCode.MON.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.TUESDAY:
                if ((time.getDayCode() & DayCode.TUE.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.WEDNESDAY:
                if ((time.getDayCode() & DayCode.WED.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.THURSDAY:
                if ((time.getDayCode() & DayCode.THU.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.FRIDAY:
                if ((time.getDayCode() & DayCode.FRI.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.SATURDAY:
                if ((time.getDayCode() & DayCode.SAT.getCode()) != 0)
                    first = cal.getTime();
                break;
            case Calendar.SUNDAY:
                if ((time.getDayCode() & DayCode.SUN.getCode()) != 0)
                    first = cal.getTime();
                break;
            }
        }
        cal.add(Calendar.DAY_OF_YEAR, 1);
        idx++;
    }
    if (first == null)
        return time.getDatePatternName();
    cal.setTime(iDatePatternFirstDate);
    idx = time.getWeekCode().length() - 1;
    cal.add(Calendar.DAY_OF_YEAR, idx);
    Date last = null;
    while (idx >= 0 && last == null) {
        if (time.getWeekCode().get(idx)) {
            int dow = cal.get(Calendar.DAY_OF_WEEK);
            switch (dow) {
            case Calendar.MONDAY:
                if ((time.getDayCode() & DayCode.MON.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.TUESDAY:
                if ((time.getDayCode() & DayCode.TUE.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.WEDNESDAY:
                if ((time.getDayCode() & DayCode.WED.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.THURSDAY:
                if ((time.getDayCode() & DayCode.THU.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.FRIDAY:
                if ((time.getDayCode() & DayCode.FRI.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.SATURDAY:
                if ((time.getDayCode() & DayCode.SAT.getCode()) != 0)
                    last = cal.getTime();
                break;
            case Calendar.SUNDAY:
                if ((time.getDayCode() & DayCode.SUN.getCode()) != 0)
                    last = cal.getTime();
                break;
            }
        }
        cal.add(Calendar.DAY_OF_YEAR, -1);
        idx--;
    }
    if (last == null)
        return time.getDatePatternName();
    Formats.Format<Date> dpf = Formats.getDateFormat(Formats.Pattern.DATE_PATTERN);
    return dpf.format(first) + (first.equals(last) ? "" : " - " + dpf.format(last));
}