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:org.power.commons.lang.util.time.DateUtils.java

/**
 * #func ??<br>//from  w  w  w .  j a  v a2s  .  c om
 *
 * @author dulin
 */
public static Date getFirstDayOfWeek(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return getADayOfWeek(calendar, Calendar.MONDAY).getTime();
}

From source file:org.goobi.production.flow.statistics.StatisticsManager.java

/**
 * Depending on selected Dates oder time range, set the dates for the
 * statistical question here.//from w  w w. j a  v a 2  s . co m
 *
 * @param question
 *            the {@link IStatisticalQuestion} where the dates should be set, if
 *            it is an implementation of
 *            {@link IStatisticalQuestionLimitedTimeframe}
 */
@SuppressWarnings("incomplete-switch")
private void setTimeFrameToStatisticalQuestion(IStatisticalQuestion question) {
    /* only add a date, if correct interface is implemented here */
    if (question instanceof IStatisticalQuestionLimitedTimeframe) {
        /* if a timeunit is selected calculate the dates */
        Calendar cl = Calendar.getInstance();

        if (sourceNumberOfTimeUnits > 0) {

            cl.setFirstDayOfWeek(Calendar.MONDAY);
            cl.setTime(new Date());

            switch (sourceTimeUnit) {
            case days:
                calculatedEndDate = calulateStartDateForTimeFrame(cl);
                calculatedStartDate = calculateEndDateForTimeFrame(cl, Calendar.DATE, -1);
                break;

            case weeks:
                cl.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                calculatedEndDate = calulateStartDateForTimeFrame(cl);
                calculatedStartDate = calculateEndDateForTimeFrame(cl, Calendar.DATE, -7);
                break;

            case months:
                cl.set(Calendar.DAY_OF_MONTH, 1);
                calculatedEndDate = calulateStartDateForTimeFrame(cl);
                calculatedStartDate = calculateEndDateForTimeFrame(cl, Calendar.MONTH, -1);
                break;

            case quarters:
                cl.set(Calendar.DAY_OF_MONTH, 1);
                setCalendarToMidnight(cl);
                while ((cl.get(Calendar.MONTH)) % 3 > 0) {
                    cl.add(Calendar.MONTH, -1);
                }
                cl.add(Calendar.MILLISECOND, -1);
                calculatedEndDate = cl.getTime();
                calculatedStartDate = calculateEndDateForTimeFrame(cl, Calendar.MONTH, -3);
                break;

            case years:
                cl.set(Calendar.DAY_OF_YEAR, 1);
                calculatedEndDate = calulateStartDateForTimeFrame(cl);
                calculatedStartDate = calculateEndDateForTimeFrame(cl, Calendar.YEAR, -1);
                break;
            }

        } else {
            /* take start and end date */
            cl.setTime(sourceDateTo);
            cl.add(Calendar.DATE, 1);
            setCalendarToMidnight(cl);
            cl.add(Calendar.MILLISECOND, -1);
            calculatedStartDate = sourceDateFrom;
            calculatedEndDate = cl.getTime();
        }
        ((IStatisticalQuestionLimitedTimeframe) question).setTimeFrame(calculatedStartDate, calculatedEndDate);
    } else {
        calculatedStartDate = null;
        calculatedEndDate = null;
    }
}

From source file:org.b3log.symphony.processor.JournalProcessor.java

/**
 * Generates journal chapter this week.//w w w  .ja  v a2 s.c  om
 *
 * @param context the specified context
 * @param request the specified request
 * @param response the specified response
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@RequestProcessing(value = "/journal/gen/chapter", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = StopwatchEndAdvice.class)
public void genChapter(final HTTPRequestContext context, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {
    final String key = Symphonys.get("keyOfSymphony");
    if (!key.equals(request.getParameter("key"))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);

        return;
    }

    context.renderJSON();

    if (journalQueryService.hasChapterWeek()) {
        return;
    }

    try {
        final JSONObject admin = userQueryService.getSA();

        final JSONObject chapter = new JSONObject();

        final Calendar cal = Calendar.getInstance();
        final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

        final String from = df.format(cal.getTime());
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

        final String title = from + " - " + df.format(cal.getTime());
        chapter.put(Article.ARTICLE_TITLE, title);
        chapter.put(Article.ARTICLE_TAGS, ",");
        chapter.put(Article.ARTICLE_CONTENT, "");
        chapter.put(Article.ARTICLE_EDITOR_TYPE, 0);
        chapter.put(Article.ARTICLE_AUTHOR_EMAIL, admin.optString(User.USER_EMAIL));
        chapter.put(Article.ARTICLE_AUTHOR_ID, admin.optString(Keys.OBJECT_ID));
        chapter.put(Article.ARTICLE_TYPE, Article.ARTICLE_TYPE_C_JOURNAL_CHAPTER);

        articleMgmtService.addArticle(chapter);

        context.renderTrueResult();
    } catch (final ServiceException e) {
        LOGGER.log(Level.ERROR, "Generates section failed", e);
    }
}

From source file:services.plugins.system.timesheet1.TimesheetLoadableObject.java

/**
 * Return the timesheet report start date matching with the current logDate
 * @return a timesheet report start date
 *//*  www.  jav  a2  s  .c o m*/
private Date getTimesheetReportStartDate() {
    Calendar c = Calendar.getInstance();
    c.setTime(getLogDateAsDate());
    if (c.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            c.add(Calendar.DAY_OF_WEEK, -1);
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        } else {
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        }
    }
    return c.getTime();
}

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 w w  w  . jav a2s. 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:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java

private boolean onValidWeekDay(InfoExam infoExam) {
    int curricularYear = infoExam.getInfoExecutionCourse().getCurricularYear().intValue();
    int weekDay = infoExam.getDay().get(Calendar.DAY_OF_WEEK);

    return ((curricularYear == 1 || curricularYear == 3 || curricularYear == 5)
            && (weekDay == Calendar.MONDAY || weekDay == Calendar.WEDNESDAY || weekDay == Calendar.FRIDAY))
            || ((curricularYear == 2 || curricularYear == 4) && (weekDay == Calendar.TUESDAY
                    || weekDay == Calendar.THURSDAY || weekDay == Calendar.SATURDAY));
}

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

/**
 * .//  w  w  w. j  a  v  a  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: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();
    ////  w ww  . j  a  va2s .  co  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.siblinks.ws.service.impl.VideoSubscriptionsServiceImpl.java

/**
 * {@inheritDoc}/*from w  w  w  . java2  s .c  om*/
 */
@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:com.ubundude.timesheet.ReportFragment.java

/**
 * Method to get the Calendar day of week Integer
 * /*w  w w  .j  a va2s  .c o m*/
 * @param lFirstDay The day of the from the shared preferences
 * @return DOW The integer for the day of the week
 */
private int getFirstDay(String lFirstDay) {
    int DOW = Calendar.SUNDAY;

    if (lFirstDay == "MONDAY")
        DOW = Calendar.MONDAY;
    else if (lFirstDay == "TUESDAY")
        DOW = Calendar.TUESDAY;
    else if (lFirstDay == "WEDNESDAY")
        DOW = Calendar.WEDNESDAY;
    else if (lFirstDay == "THURSDAY")
        DOW = Calendar.THURSDAY;
    else if (lFirstDay == "FRIDAY")
        DOW = Calendar.FRIDAY;
    else if (lFirstDay == "SATURDAY")
        DOW = Calendar.SATURDAY;

    return DOW;
}