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:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImplTest.java

@Test
public void testDonotFindExpiredInvitationByInviteId() throws Exception {
    Invitation invitation = new Invitation(email, team.getId());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_WEEK, -16);
    invitation.setTimestamp(calendar.getTimeInMillis());

    String hash = invitation.getInvitationHash();

    assertEquals(0, teamInviteService.findAll().size());
    assertNull("Nothing saved yet", teamInviteService.findInvitationByInviteId(hash));
    teamInviteService.saveOrUpdate(invitation);
    assertEquals(1, teamInviteService.findAll().size());
    assertNull("Don't find expired", teamInviteService.findInvitationByInviteId(hash));

}

From source file:com.glaf.core.web.springmvc.WorkCalendarController.java

/**
 * /* ww w.  j a  va2 s. co m*/
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping("/showCalendar")
public ModelAndView showCalendar(HttpServletRequest request, ModelMap modelMap) {
    Calendar cal = Calendar.getInstance();
    int month = RequestUtils.getIntParameter(request, "month", cal.get(Calendar.MONTH));
    int year = RequestUtils.getIntParameter(request, "year", cal.get(Calendar.YEAR));

    cal.set(Calendar.MONTH, month); // 
    cal.set(Calendar.YEAR, year); // 
    cal.setFirstDayOfWeek(Calendar.SUNDAY);
    cal.set(Calendar.DAY_OF_MONTH, 1);

    logger.info("month:" + month);
    int firstIndex = cal.get(Calendar.DAY_OF_WEEK) - 1; // 
    logger.info("firstIndex:" + firstIndex);
    int maxIndex = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// 
    logger.info("maxIndex:" + maxIndex);
    int weeks = Calendar.WEEK_OF_MONTH;// 
    cal.set(Calendar.DATE, 1);// 1?
    if (cal.get(Calendar.DAY_OF_WEEK) == 7)
        weeks += 1;
    logger.info("day of week:" + cal.get(Calendar.DAY_OF_WEEK));
    logger.info("weeks:" + weeks);

    String days[] = new String[42];
    for (int i = 0; i < 42; i++) {
        days[i] = "";
    }
    for (int i = 0; i < maxIndex; i++) {
        days[firstIndex + i] = String.valueOf(i + 1);
    }

    List<Integer> list = workCalendarService.getWorkDateList(year, month + 1);
    if (list == null) {
        list = new java.util.ArrayList<Integer>();
    }

    request.setAttribute("list", list);
    request.setAttribute("year", String.valueOf(year));
    request.setAttribute("month", String.valueOf(month));
    request.setAttribute("weeks", String.valueOf(weeks));
    request.setAttribute("days", days);

    String x_view = ViewProperties.getString("calendar.showCalendar");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/modules/sys/calendar/calendar", modelMap);
}

From source file:com.zigbee.framework.common.util.Utils.java

/**
 * //from www.  jav a  2 s.co  m
 * @Date        :      2011-6-27
 * @return
 */
public static String getMondayOfThisWeek() {
    Calendar c = Calendar.getInstance();
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
    if (dayOfWeek == 0) {
        dayOfWeek = 7;
    }
    c.add(Calendar.DATE, -dayOfWeek + 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf.format(c.getTime());
}

From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresFutureWeekday() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());//  w  ww .ja v a  2  s  . com
    expected.add(Calendar.DAY_OF_WEEK, 2);

    int dayOfweek = expected.get(Calendar.DAY_OF_WEEK);
    properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, dayOfweek);

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
    assertEquals(dayOfweek, actual.get(Calendar.DAY_OF_WEEK));
}

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

/**
 * {@inheritDoc}/*  w ww  .j  a va  2s  .c  om*/
 */
@Override
@RequestMapping(value = "/getListVideoSubscription", method = RequestMethod.GET)
public ResponseEntity<Response> getListVideoSubscription(@RequestParam("userId") final String userId,
        @RequestParam("subjectId") final String subjectId) {
    SimpleResponse response = null;
    try {
        String method = "getListVideoSubscription()";
        logger.debug(method + " start");

        String entityName = null;
        List<Object> readObject = null;
        String currentDate = "";
        String firstDayOfCurrentWeek = "";
        Object[] queryParams = null;
        Map<String, List<Object>> mapListVideo = new HashMap<String, List<Object>>();

        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);

            if ("-2".equals(subjectId)) {
                entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION;
                queryParams = new Object[] { userId, currentDate, userId, firstDayOfCurrentWeek, currentDate,
                        userId, firstDayOfCurrentWeek };
                readObject = dao.readObjects(entityName, queryParams);
            } else {
                // Get child category by subjectId
                List<Map<String, Object>> readObjectNoCondition = dao
                        .readObjectNoCondition(SibConstants.SqlMapper.SQL_GET_ALL_CATEGORY_TOPIC);

                MapSqlParameterSource params = new MapSqlParameterSource();

                String allChildCategory = CommonUtil.getAllChildCategory(subjectId, readObjectNoCondition);
                if (!StringUtil.isNull(allChildCategory)) {
                    List<Integer> listChildCategory = new ArrayList<Integer>();
                    String[] arrChildCategory = allChildCategory.split(",");
                    for (String string : arrChildCategory) {
                        listChildCategory.add(Integer.parseInt(string));
                    }
                    params.addValue("subjectID", listChildCategory);

                }
                params.addValue("userID", userId);
                params.addValue("currentDate", currentDate);
                params.addValue("firstDayOfCurrentWeek", firstDayOfCurrentWeek);

                entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION_BY_CATEGORY;

                readObject = dao.readObjectNamedParameter(entityName, params);
            }

            if (readObject == null) {
                readObject = new ArrayList<Object>();
            }

            JSONArray jsonAraay = new JSONArray(readObject);

            for (int i = 0; i < jsonAraay.length(); i++) {
                JSONObject jsonObj = jsonAraay.getJSONObject(i);
                ObjectMapper mapper = new ObjectMapper();
                Object obj = mapper.readValue(jsonObj.toString(), Object.class);
                addMapVideo(mapListVideo, jsonObj.get("flag").toString(), obj);
            }

        } catch (ParseException | IOException e) {
            logger.error(method + " - error : " + e.getMessage());
        }

        response = new SimpleResponse("true", mapListVideo);
    } catch (Exception e) {
        e.printStackTrace();
        response = new SimpleResponse(SibConstants.FAILURE, "video", "getListVideoSubscription",
                e.getMessage());
    }
    return new ResponseEntity<Response>(response, HttpStatus.OK);
}

From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java

@Cacheable(value = "inicioCache")
@Transactional(readOnly = true)/*from   w w  w .  j  a  v  a  2  s .c  o  m*/
@Override
public Inicio inicio(Inicio inicio) {
    Integer anio = new Integer(inicio.getAnio());
    String trimestre = inicio.getTrimestre();
    String leccion = inicio.getLeccion();
    String dia = inicio.getDia();
    if (StringUtils.isBlank(dia)) {
        dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK));
        inicio.setDia(dia);
    }
    log.debug("DIA: {}", dia);

    Publicacion leccion1 = publicacionService.obtiene(anio, trimestre, leccion, dia, "leccion");

    Publicacion versiculo = publicacionService.obtiene(anio, trimestre, leccion, null, "versiculo");

    Publicacion video = publicacionService.obtiene(anio, trimestre, leccion, null, "video");

    Publicacion podcast = publicacionService.obtiene(anio, trimestre, leccion, null, "podcast");

    List<Publicacion> dialoga = publicacionService.obtiene(anio, trimestre, leccion, "dialoga");

    List<Publicacion> comunica = publicacionService.obtiene(anio, trimestre, leccion, "comunica");

    PageRequest page = new PageRequest(0, 10, Sort.Direction.ASC, "id");

    List<Publicacion> populares = publicacionService.populares(page);

    Trimestre t = trimestreService.obtiene(anio + trimestre);
    if (t != null) {
        try {
            Calendar cal = new GregorianCalendar(Locale.ENGLISH);
            cal.setTime(t.getInicia());
            cal.add(Calendar.SECOND, 1);
            cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia));
            int weeks = ((Long) nf.parse(leccion.substring(1))).intValue();
            if (dia.equals("sabado")) {
                weeks--;
            }
            cal.add(Calendar.WEEK_OF_YEAR, weeks);
            Date hoy = cal.getTime();

            inicio.setPublicacion(leccion1);
            inicio.setDialoga(dialoga);
            inicio.setComunica(comunica);
            inicio.setVideo(video);
            inicio.setPodcast(podcast);
            inicio.setVersiculo(versiculo);
            inicio.setHoy(hoy);
            int max = Math.max(dialoga.size(), comunica.size());
            List<Publicacion> articulos = new ArrayList<>();
            for (int i = 0; i < max; i++) {
                if (i < dialoga.size()) {
                    articulos.add(dialoga.get(i));
                }
                if (i < comunica.size()) {
                    articulos.add(comunica.get(i));
                }
            }
            articulos.addAll(populares);
            inicio.setArticulos(articulos);

            return inicio;
        } catch (ParseException e) {
            log.error("No pude poner la fecha de hoy", e);
        }
    }

    return null;
}

From source file:org.shredzone.cilla.site.renderer.CalendarRenderStrategyImpl.java

/**
 * Writes the calendar table itself.//from  ww  w  . ja v a2s  . co  m
 */
protected void writeCalendar() throws IOException {
    Calendar cal = generator.getDisplayCalendar();

    int firstDay = cal.getFirstDayOfWeek() - 1;
    int firstWeekday = cal.get(Calendar.DAY_OF_WEEK) - 1;
    int numberOfDays = cal.getActualMaximum(Calendar.DATE);
    int skipDays = (firstWeekday + 7 - firstDay) % 7;

    out.append("<tr>");

    int column = 0;
    for (int ix = -skipDays; ix < numberOfDays; ix++) {
        if (ix >= 0) {
            String url = generator.getDayUrl(ix + 1);
            if (url != null) {
                writeLinkedDay(ix + 1, url);
            } else {
                writeDay(ix + 1);
            }
        } else {
            writeEmptyDay();
        }

        column++;
        if (column == 7) {
            column = 0;
            out.append("</tr>");
            out.append("<tr>");
        }

    }

    for (; column < 7; column++) {
        writeEmptyDay();
    }

    out.append("</tr>");
}

From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java

private Calendar calcAlignedStartDate(Calendar cal) {
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }//from w  ww .  j  a v a2s. com
    return cal;
}

From source file:net.granoeste.commons.util.DateUtils.java

/**
 * ????//  ww w.j a va2 s .c  om
 *
 * @param cal
 * @param amount ex) last month : -1. the current month : 0. the next month : 1
 */
public static void shiftDateOnSundayOfTheWeekOfTheEndOfTheMonth(final Calendar cal, final int amount) {

    cal.set(Calendar.DATE, 1);
    cal.add(Calendar.MONTH, amount);
    cal.add(Calendar.DATE, -1);
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        cal.add(Calendar.DATE, 1);
    } else {
        cal.add(Calendar.DATE, 7 - cal.get(Calendar.DAY_OF_WEEK) + 1);
    }
}

From source file:egovframework.oe1.cms.com.web.EgovOe1CalRestdeManageController.java

/**
 * ? ?  .//  w ww .j  a  v  a 2 s . com
 * @param restde
 * @param model
 * @return "/cmm/sym/cal/EgovNormalCalendar"
 * @throws Exception
 */
@RequestMapping(value = "/com/EgovselectNormalCalendar.do")
public String selectNormalRestdePopup(EgovOe1Restde restde, ModelMap model) throws Exception {

    Calendar cal = Calendar.getInstance();

    if (restde.getYear() == null || restde.getYear().equals("")) {
        restde.setYear(Integer.toString(cal.get(Calendar.YEAR)));
    }
    if (restde.getMonth() == null || restde.getMonth().equals("")) {
        restde.setMonth(Integer.toString(cal.get(Calendar.MONTH) + 1));
    }
    int iYear = Integer.parseInt(restde.getYear());
    int iMonth = Integer.parseInt(restde.getMonth());

    if (iMonth < 1) {
        iYear--;
        iMonth = 12;
    }
    if (iMonth > 12) {
        iYear++;
        iMonth = 1;
    }
    if (iYear < 1) {
        iYear = 1;
        iMonth = 1;
    }
    if (iYear > 9999) {
        iYear = 9999;
        iMonth = 12;
    }
    restde.setYear(Integer.toString(iYear));
    restde.setMonth(Integer.toString(iMonth));

    cal.set(iYear, iMonth - 1, 1);

    restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK));
    restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE));

    List CalInfoList = restdeManageService.selectNormalRestdePopup(restde);

    model.addAttribute("resultList", CalInfoList);

    return "/cms/com/EgovNormalCalendar";
}