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:net.sourceforge.fenixedu.presentationTier.Action.publico.RoomSiteViewerDispatchAction.java

public ActionForward roomViewer(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    User userView = getUserView(request);

    String roomName = request.getParameter("roomName");
    if (roomName == null) {
        roomName = (String) request.getAttribute("roomName");
    }//from ww w . jav  a 2 s .  c  o m
    request.setAttribute("roomName", roomName);
    RoomKey roomKey = null;

    if (roomName != null) {
        roomKey = new RoomKey(roomName);

        ISiteComponent bodyComponent = new InfoSiteRoomTimeTable();
        DynaActionForm indexForm = (DynaActionForm) form;
        Integer indexWeek = (Integer) indexForm.get("indexWeek");
        // Integer executionPeriodID = (Integer)
        // indexForm.get("selectedExecutionPeriodID");
        String executionPeriodIDString = request.getParameter("selectedExecutionPeriodID");
        if (executionPeriodIDString == null) {
            executionPeriodIDString = (String) request.getAttribute("selectedExecutionPeriodID");
        }
        String executionPeriodID = (executionPeriodIDString != null) ? executionPeriodIDString : null;
        if (executionPeriodID == null) {
            try {
                // executionPeriodID = (Integer)
                // indexForm.get("selectedExecutionPeriodID");
                executionPeriodID = indexForm.get("selectedExecutionPeriodID").equals("") ? null
                        : (String) indexForm.get("selectedExecutionPeriodID");
            } catch (IllegalArgumentException ex) {
            }
        }
        Calendar today = new DateMidnight().toCalendar(null);
        ArrayList weeks = new ArrayList();

        InfoExecutionPeriod executionPeriod;
        if (executionPeriodID == null) {
            executionPeriod = ReadCurrentExecutionPeriod.run();
            executionPeriodID = executionPeriod.getExternalId();
            try {
                indexForm.set("selectedExecutionPeriodID", executionPeriod.getExternalId().toString());
            } catch (IllegalArgumentException ex) {
            }
        } else {
            executionPeriod = ReadExecutionPeriodByOID.run(executionPeriodID);
        }

        // weeks
        Calendar begin = Calendar.getInstance();
        begin.setTime(executionPeriod.getBeginDate());
        Calendar end = Calendar.getInstance();
        end.setTime(executionPeriod.getEndDate());
        ArrayList weeksLabelValueList = new ArrayList();
        begin.add(Calendar.DATE, Calendar.MONDAY - begin.get(Calendar.DAY_OF_WEEK));
        int i = 0;
        boolean selectedWeek = false;
        while (begin.before(end) || begin.before(Calendar.getInstance())) {
            Calendar day = Calendar.getInstance();
            day.setTimeInMillis(begin.getTimeInMillis());
            weeks.add(day);
            String beginWeekString = DateFormatUtils.format(begin.getTime(), "dd/MM/yyyy");
            begin.add(Calendar.DATE, 5);
            String endWeekString = DateFormatUtils.format(begin.getTime(), "dd/MM/yyyy");
            weeksLabelValueList.add(
                    new LabelValueBean(beginWeekString + " - " + endWeekString, new Integer(i).toString()));
            begin.add(Calendar.DATE, 2);
            if (!selectedWeek && indexWeek == null && Calendar.getInstance().before(begin)) {
                indexForm.set("indexWeek", new Integer(i));
                selectedWeek = true;
            }
            i++;
        }

        final Collection<ExecutionSemester> executionSemesters = rootDomainObject.getExecutionPeriodsSet();
        final List<LabelValueBean> executionPeriodLabelValueBeans = new ArrayList<LabelValueBean>();
        for (final ExecutionSemester ep : executionSemesters) {
            if (ep.getState().equals(PeriodState.OPEN) || ep.getState().equals(PeriodState.CURRENT)) {
                executionPeriodLabelValueBeans.add(new LabelValueBean(
                        ep.getName() + " " + ep.getExecutionYear().getYear(), ep.getExternalId().toString()));
            }
        }
        request.setAttribute(PresentationConstants.LABELLIST_EXECUTIONPERIOD, executionPeriodLabelValueBeans);

        request.setAttribute(PresentationConstants.LABELLIST_WEEKS, weeksLabelValueList);
        if (indexWeek != null) {
            final int xpto = indexWeek.intValue();
            if (xpto < weeks.size()) {
                today = (Calendar) weeks.get(xpto);
            } else {
                today = (Calendar) weeks.iterator().next();
                indexForm.set("indexWeek", new Integer(0));
            }
        }

        try {
            SiteView siteView = (SiteView) RoomSiteComponentServiceByExecutionPeriodID.run(bodyComponent,
                    roomKey, today, executionPeriodID);

            request.setAttribute("siteView", siteView);

        } catch (NonExistingServiceException e) {
            throw new NonExistingActionException(e);
        } catch (FenixServiceException e) {
            throw new FenixActionException(e);
        }
        return mapping.findForward("roomViewer");
    }
    throw new FenixActionException();

}

From source file:fr.paris.lutece.plugins.extend.modules.rating.service.security.RatingSecurityService.java

/**
 * {@inheritDoc}//from  ww w .j a va  2  s. c o  m
 */
@Override
public boolean isVoteClosed(RatingExtenderConfig config) {

    if ((config.getDateStart() != null) || (config.getDateEnd() != null)) {
        // Check activation date
        if ((config.getDateStart() != null) && (config.getDateStart().compareTo(new Date()) > 0)) {
            return true;
        } else if (config.getDateEnd() != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(config.getDateEnd());
            cal.add(Calendar.DAY_OF_WEEK, 1);

            if (cal.getTime().compareTo(new Date()) < 0) {
                return true;
            }
        }
    }

    return false;
}

From source file:cn.mypandora.util.MyDateUtils.java

/**
 * ./*from www .j a va 2s.  c o  m*/
 *
 * @param c
 * @return
 */
public static String getWeekDay(Calendar c) {
    if (c == null) {
        return "";
    }
    switch (c.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        return "";
    case Calendar.TUESDAY:
        return "";
    case Calendar.WEDNESDAY:
        return "";
    case Calendar.THURSDAY:
        return "";
    case Calendar.FRIDAY:
        return "";
    case Calendar.SATURDAY:
        return "";
    default:
        return "";
    }
}

From source file:com.haulmont.timesheets.gui.approve.ApproveScreen.java

protected void initDaysColumns() {
    for (Date current = firstDayOfWeek; current.getTime() <= lastDayOfWeek.getTime(); current = DateUtils
            .addDays(current, 1)) {//from  w ww.j a v a2s.  c  o  m
        final DayOfWeek day = DayOfWeek
                .fromCalendarDay(DateUtils.toCalendar(current).get(Calendar.DAY_OF_WEEK));
        final String columnId = day.getId() + COLUMN_SUFFIX;
        weeklyReportsTable.addGeneratedColumn(columnId, new Table.ColumnGenerator<WeeklyReportEntry>() {
            @Override
            public Component generateCell(final WeeklyReportEntry entity) {
                List<TimeEntry> timeEntries = entity.getDayOfWeekTimeEntries(day);
                if (CollectionUtils.isNotEmpty(timeEntries)) {
                    if (timeEntries.size() == 1) {
                        return createLinkToSingleTimeEntry(entity, timeEntries);
                    } else {
                        return createLinkToMultipleTimeEntries(entity, timeEntries.get(0).getDate());
                    }
                }
                return null;
            }

            private Component createLinkToMultipleTimeEntries(final WeeklyReportEntry reportEntry,
                    final Date date) {
                final LinkButton linkButton = componentsFactory.createComponent(LinkButton.class);
                linkButton.setCaption(StringFormatHelper.getDayHoursString(reportEntry.getTotalForDay(day)));
                linkButton.setAction(new AbstractAction("edit") {

                    @Override
                    public void actionPerform(Component component) {
                        User user = usersTable.getSingleSelected();
                        if (user != null) {
                            openLookup("ts$TimeEntry.lookup", items -> {
                                if (CollectionUtils.isNotEmpty(items)) {
                                    TimeEntry timeEntry = (TimeEntry) items.iterator().next();
                                    openTimeEntryEditor(timeEntry);
                                }
                            }, WindowManager.OpenType.DIALOG,
                                    ParamsMap.of("date", date, "task", reportEntry.getTask(), "activityType",
                                            reportEntry.getActivityType(), "user", user.getId()));
                        }
                    }
                });
                return linkButton;
            }

            private Component createLinkToSingleTimeEntry(WeeklyReportEntry reportEntry,
                    List<TimeEntry> timeEntries) {
                final TimeEntry timeEntry = timeEntries.get(0);
                final LinkButton linkButton = componentsFactory.createComponent(LinkButton.class);
                linkButton.setCaption(StringFormatHelper.getDayHoursString(reportEntry.getTotalForDay(day)));
                linkButton.setAction(new AbstractAction("edit") {
                    @Override
                    public void actionPerform(Component component) {
                        openTimeEntryEditor(timeEntry);
                    }
                });
                return linkButton;
            }
        });
        weeklyReportsTable.setColumnWidth(columnId, 80);

        Table.Column column = weeklyReportsTable.getColumn(columnId);
        column.setAggregation(ComponentsHelper.createAggregationInfo(
                projectsService.getEntityMetaPropertyPath(WeeklyReportEntry.class, day.getId()),
                new WeeklyReportEntryAggregation()));
    }
}

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

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *///www . jav  a2  s.  c  o m
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<Rule>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:com.feilong.core.date.DateUtil.java

/**
 * date <span style="color:red">?()</span> <code>23:59:59.999</code> .
 * //from ww w .j av  a  2  s  .  c o m
 * <pre class="code">
 * DateUtil.getLastDateOfThisWeek(2012-10-11 17:10:30.701)   =2012-10-13 23:59:59.999
 * DateUtil.getLastDateOfThisWeek(2014-12-31 05:00:00)       =2015-01-03 23:59:59.999 //
 * </pre>
 * 
 * <h3>?:</h3>
 * <blockquote>
 * <ol>
 * <li>,<span style="color:red">,?</span></li>
 * <li>,?</li>
 * </ol>
 * </blockquote>
 * 
 * @param date
 *            ?
 * @return  <code>date</code> null, {@link NullPointerException}
 * @see #toCalendar(Date)
 * @see Calendar#set(int, int)
 * @see CalendarUtil#resetDayEnd(Calendar)
 * @see Calendar#getTime()
 * @since 1.0.1
 */
public static Date getLastDateOfThisWeek(Date date) {
    Calendar calendar = toCalendar(date);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    return CalendarUtil.toDate(CalendarUtil.resetDayEnd(calendar));
}

From source file:io.lavagna.service.SearchFilter.java

private static void fromDateIdentifier(String identifier, List<Object> params) {
    Date todayTruncated = truncate(new Date(), Calendar.DAY_OF_MONTH);
    Date beginMonth = truncate(new Date(), Calendar.MONTH);

    // TODO: internazionalization...
    Calendar c = truncate(Calendar.getInstance(), Calendar.DAY_OF_MONTH);
    c.setFirstDayOfWeek(Calendar.MONDAY);
    c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Date beginOfWeek = c.getTime();
    ///*from  www.  ja  v  a  2  s  . c  o  m*/

    switch (identifier) {
    case "late":
        params.add(new Date(0));
        params.add(todayTruncated);
        break;
    case "today":
        params.add(todayTruncated);
        params.add(addDays(todayTruncated, 1));
        break;
    case "yesterday":
        params.add(addDays(todayTruncated, -1));
        params.add(todayTruncated);
        break;
    case "tomorrow":
        params.add(addDays(todayTruncated, 1));
        params.add(addDays(todayTruncated, 2));
        break;
    case "this week":
        params.add(beginOfWeek);
        params.add(addWeeks(beginOfWeek, 1));
        break;
    case "this month":
        params.add(beginMonth);
        params.add(addMonths(beginMonth, 1));
        break;
    case "next week":
        params.add(addWeeks(beginOfWeek, 1));
        params.add(addWeeks(beginOfWeek, 2));
        break;
    case "next month":
        params.add(addMonths(beginMonth, 1));
        params.add(addMonths(beginMonth, 2));
        break;
    case "previous week":
        params.add(addWeeks(beginOfWeek, -1));
        params.add(beginOfWeek);
        break;
    case "previous month":
        params.add(addMonths(beginMonth, -1));
        params.add(beginMonth);
        break;
    case "last week":
        params.add(addDays(todayTruncated, -6));
        params.add(addDays(todayTruncated, 1));
        break;
    case "last month":
        params.add(addDays(todayTruncated, -29));
        params.add(addDays(todayTruncated, 1));
        break;
    default:
        break;
    }
}

From source file:com.clustercontrol.calendar.util.CalendarUtil.java

/**
 * detailInfo?timeFrom,timeTo??0-24????/*from   w  w w. j  av  a  2 s .c  o  m*/
 * @param detailInfo
 * @param date ?
 * @return
 */
public static boolean isRunByDetailDate(CalendarDetailInfo detailInfo, Date date) {
    // from, to?0-24??????
    long timezoneOffset = HinemosTime.getTimeZoneOffset();
    long hour24 = 24 * 60 * 60 * 1000 - timezoneOffset;

    if (detailInfo.getTimeFrom() < (0 - timezoneOffset) || hour24 < (detailInfo.getTimeFrom())) {
        m_log.trace("detailInfo.getTimeFrom = " + detailInfo.getTimeFrom());
        return false;
    }
    if ((detailInfo.getTimeTo()) < (0 - timezoneOffset) || hour24 < (detailInfo.getTimeTo())) {
        m_log.trace("detailInfo.getTimeTo = " + (detailInfo.getTimeTo()));
        return false;
    }

    //null?
    if (detailInfo.getMonth() == null) {
        m_log.warn("detailInfo.getMonth() is NULL");
        return false;
    }

    //?
    Calendar detailCal = HinemosTime.getCalendarInstance();
    //???
    detailCal.setTime(new Date(date.getTime() - (long) detailInfo.getAfterday() * 24 * 3600 * 1000));
    //
    int year = detailCal.get(Calendar.YEAR);
    //
    int month = detailCal.get(Calendar.MONTH) + 1;
    //
    int weekXth = detailCal.get(Calendar.DAY_OF_WEEK_IN_MONTH);
    //
    int weekday = detailCal.get(Calendar.DAY_OF_WEEK);
    //
    int dateNo = detailCal.get(Calendar.DATE);

    m_log.debug("detailCal=" + detailCal.getTime());

    /**
     * 
     */
    //? ? ?????????0?
    if (detailInfo.getYear() != year && detailInfo.getYear() != 0) {
        m_log.trace("Year is false : Schdule year =" + detailInfo.getYear() + ", Current Year =" + year);
        return false;
    }
    m_log.trace("Year is TRUE : Schduler Year =" + detailInfo.getYear() + ", Current Year =" + year);

    /**
     * 
     */
    //? ? ?????????0?
    if (detailInfo.getMonth() != month && detailInfo.getMonth() != 0) {
        m_log.trace("Month is False : Schduler Month =" + detailInfo.getMonth() + ", Current Month =" + month);
        return false;
    }
    m_log.trace("Month is TRUE : Schduler Month =" + detailInfo.getMonth() + ", Current Month =" + month);

    /**
     * 
     */
    //null?
    if (detailInfo.getDayType() == null) {
        m_log.warn("detailInfo.getDayType() is NULL");
        return false;
    }
    //??? ? ??????
    //????
    if (detailInfo.getDayType() == 0) {
        m_log.trace(
                "DateALL is TRUE : Schduler dayType=" + detailInfo.getDayType() + ", Current Date =" + dateNo);
        return true;
    }
    //???
    else if (detailInfo.getDayType() == 1) {
        //null?
        if (detailInfo.getDayOfWeekInMonth() == null) {
            m_log.trace("detailInfo.getDayOfWeekInMonth() is NULL");
            return false;
        }
        //null?
        if (detailInfo.getDayOfWeek() == null) {
            m_log.warn("detailInfo.getDayOfWeek() is NULL");
            return false;
        }
        if (detailInfo.getDayOfWeekInMonth() == weekXth || detailInfo.getDayOfWeekInMonth() == 0) {
            m_log.trace("WeekXth is TRUE : Schduler Xth =" + detailInfo.getDayOfWeekInMonth()
                    + ", Current weekXth =" + weekXth);
            if (detailInfo.getDayOfWeek() == weekday) {
                m_log.trace("Weekday is TRUE : Schduler Weekday =" + detailInfo.getDayOfWeek()
                        + ", Current Weekday =" + weekday);
                return true;
            }
        }
    }
    // ???
    else if (detailInfo.getDayType() == 2) {
        //null?
        if (detailInfo.getDate() == null) {
            m_log.trace("detailInfo.getDate() is NULL");
            return false;
        }
        if (detailInfo.getDate() == dateNo) {
            m_log.trace("Date is TRUE : Schduler Date =" + detailInfo.getDate() + ", Current Date =" + dateNo);
            return true;
        }
    }
    //???
    else if (detailInfo.getDayType() == 3) {
        //null?
        if (detailInfo.getCalPatternId() == null) {
            m_log.trace("detailInfo.getCalPatternId() is NULL");
            return false;
        }
        m_log.trace("CalendarPatternID = " + detailInfo.getCalPatternId());
        CalendarPatternInfo calPatternInfo = null;
        calPatternInfo = detailInfo.getCalPatternInfo();
        if (calPatternInfo.isRun(year, month, dateNo)) {
            m_log.trace(year + "/" + month + "/" + dateNo);
            return true;
        }
    }
    return false;
}

From source file:com.siblinks.ws.service.impl.VideoSubscriptionsServiceImpl.java

/**
 * {@inheritDoc}/*from ww w . j  av  a 2s .co m*/
 */
@Override
@RequestMapping(value = "/getListVideoOfWeek", method = RequestMethod.POST)
public ResponseEntity<Response> getListVideoOfWeek(@RequestParam("subjectId") final String subjectId) {
    SimpleResponse response = null;
    try {
        String method = "getListVideoOfWeek()";

        logger.debug(method + " start");

        String entityName = null;
        List<Object> readObject = null;
        String currentDate = "";
        String firstDayOfCurrentWeek = "";

        try {
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            cal.setFirstDayOfWeek(Calendar.MONDAY);
            cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
            Date firstDayOfTheWeek = cal.getTime();

            currentDate = DateUtil.date2YYYYMMDD000000(new Date());
            firstDayOfCurrentWeek = DateUtil.date2YYYYMMDD000000(firstDayOfTheWeek);

            System.out.println(firstDayOfCurrentWeek);

            entityName = SibConstants.SqlMapper.SQL_SIB_GET_LIST_VIDEO_OF_WEEK;

            Object[] queryParams = { subjectId, firstDayOfCurrentWeek, currentDate };

            readObject = dao.readObjects(entityName, queryParams);

        } catch (ParseException e) {
            e.printStackTrace();
        }

        response = new SimpleResponse("true", readObject);
    } catch (Exception e) {
        logger.error(e.getMessage());
        response = new SimpleResponse(SibConstants.FAILURE, "videoAdmission", "getVideoTuttorialAdmission",
                e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:de.feanor.yeoldemensa.data.MensaFactory.java

/**
 * Returns the Date for next Saturday midnight. Used for valiTo in Mensa.
 * //from  w  w  w  .  j  a v a 2 s.co  m
 * @return Date of next Saturday
 */
private static Date getNextSaturday() {
    Calendar calendar = Calendar.getInstance();
    int weekday = calendar.get(Calendar.DAY_OF_WEEK);

    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);

    // TODO: Better solved with locales probably
    if (weekday == Calendar.SATURDAY) {
        calendar.add(Calendar.DAY_OF_MONTH, 7);
        return calendar.getTime();
    } else if (weekday == Calendar.SUNDAY) {
        calendar.add(Calendar.DAY_OF_MONTH, 6);
        return calendar.getTime();
    } else {
        calendar.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY - weekday);
    }

    return calendar.getTime();
}