Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

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

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:com.appeligo.search.actions.SearchResults.java

private Query generateLuceneQuery(String givenQuery, IndexSearcher searcher) throws ParseException {
    if (givenQuery == null) {
        givenQuery = getQuery();//w w w.j a va 2 s . c  o  m
    }
    HashMap<String, Float> boost = new HashMap<String, Float>();
    boost.put("programTitle", 8.0f);
    boost.put("episodeTitle", 3.0f);
    boost.put("description", 2.0f);
    MultiFieldQueryParser parser = new MultiFieldQueryParser(
            new String[] { "text", "description", "programTitle", "episodeTitle", "credits", "genre" },
            analyzer, boost);
    parser.setDefaultOperator(Operator.AND);

    Query luceneQuery = null;
    try {
        luceneQuery = parser.parse(givenQuery);
    } catch (ParseException e) {
        log.error("Error parsing query for : " + givenQuery);
        if (log.isDebugEnabled()) {
            log.debug("Error parsing query for : " + givenQuery, e);
        }
        givenQuery = QueryParser.escape(givenQuery);
        luceneQuery = parser.parse(givenQuery);
    }
    BooleanQuery combinedQuery = new BooleanQuery();
    combinedQuery.add(luceneQuery, Occur.MUST);

    //This will move into a setting on the user.
    Query tvma = new TermQuery(new Term("tvRating", "TVMA"));
    combinedQuery.add(tvma, Occur.MUST_NOT);

    if (lineup != null) {
        //Only find programs that were on networks that are in the lineup
        TermQuery lineupQuery = new TermQuery(new Term("lineup-" + lineup, "true"));
        combinedQuery.add(lineupQuery, Occur.MUST);
    }

    if (searchType != null) {
        if (lineup == null) {
            throw new ParseException(
                    "Lineup cannot be null if searching based on date.  searchType=" + searchType);
        }
        switch (searchType) {
        case FUTURE: {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_YEAR, 14);
            Date future = cal.getTime();
            Date now = new Date();
            ConstantScoreRangeQuery dateQuery = new ConstantScoreRangeQuery("lineup-" + lineup + "-endTime",
                    DateTools.dateToString(now, DateTools.Resolution.MINUTE),
                    DateTools.dateToString(future, DateTools.Resolution.MINUTE), true, true);
            combinedQuery.add(dateQuery, Occur.MUST);
            break;
        }
        case TODAY: {
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
            Date future = cal.getTime();
            Date now = new Date();
            ConstantScoreRangeQuery dateQuery = new ConstantScoreRangeQuery("lineup-" + lineup + "-endTime",
                    DateTools.dateToString(now, DateTools.Resolution.MINUTE),
                    DateTools.dateToString(future, DateTools.Resolution.MINUTE), true, true);
            combinedQuery.add(dateQuery, Occur.MUST);
            break;
        }
        }
    }
    if (modifiedSince != null) {
        Date now = new Date();
        ConstantScoreRangeQuery dateQuery = new ConstantScoreRangeQuery("lastModified",
                DateTools.dateToString(modifiedSince, DateTools.Resolution.MINUTE),
                DateTools.dateToString(now, DateTools.Resolution.MINUTE), true, true);
        combinedQuery.add(dateQuery, Occur.MUST);
    }
    return combinedQuery;
}

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

private Calendar shiftMonth(FacesContext facesContext, Calendar timeKeeper, int currentDay, int shift) {
    Calendar cal = copyCalendar(facesContext, timeKeeper);

    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + shift);

    if (currentDay > cal.getActualMaximum(Calendar.DAY_OF_MONTH))
        currentDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

    cal.set(Calendar.DAY_OF_MONTH, currentDay);
    return cal;//from ww w  .j  ava 2 s.  co  m
}

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

/**
 * ? ?  ./*from w  w  w.ja  v  a 2  s  . c o  m*/
 * @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";
}

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

/**
 * ? //from  w w w  .ja  va2s.  co m
 * @param restde
 * @param model
 * @return "/cmm/sym/cal/EgovNormalMonthCalendar"
 * @throws Exception
 */
@RequestMapping(value = "/com/EgovNormalMonthCalendar.do")
public String selectNormalMonthCalendar(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);

    List NormalMonthRestdeList = restdeManageService.selectNormalMonthRestde(restde);

    model.addAttribute("resultList", CalInfoList);
    model.addAttribute("RestdeList", NormalMonthRestdeList);

    return "/cms/com/EgovNormalMonthCalendar";
}

From source file:org.oscarehr.web.OcanReportUIBean.java

private static Date getEndDate(int year, int month) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);/*from  ww w  .  j a va2  s  .c  o m*/
    c.set(Calendar.MONTH, month - 1);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DATE));
    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    return c.getTime();
}

From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java

private List<Calendar> expandMonthDayList(List<Calendar> list) {
    // this func ONLY works for expanding, NOT for contracting
    assert (mFreq == Frequency.MONTHLY || mFreq == Frequency.YEARLY);

    if (mByMonthDayList.size() <= 0)
        return list;

    List<Calendar> toRet = new LinkedList<Calendar>();

    for (Calendar cur : list) {
        int curMonth = cur.get(Calendar.MONTH);
        int lastMonthDay = cur.getActualMaximum(Calendar.DAY_OF_MONTH);
        boolean seenLastMonthDay = false;
        for (Integer moday : mByMonthDayList) {
            if (moday != 0) {
                if (moday > 0) {
                    if (moday >= lastMonthDay) {
                        if (seenLastMonthDay)
                            continue;
                        seenLastMonthDay = true;
                        moday = lastMonthDay;
                    }//from   w  ww  . j  a  v a2  s .  c o m
                    cur.set(Calendar.DAY_OF_MONTH, moday);
                } else {
                    if (moday == -1) {
                        if (seenLastMonthDay)
                            continue;
                        seenLastMonthDay = true;
                    }
                    cur.set(Calendar.DAY_OF_MONTH, 1);
                    cur.roll(Calendar.DAY_OF_MONTH, moday);
                }
                assert (cur.get(Calendar.MONTH) == curMonth);
                toRet.add((Calendar) (cur.clone()));
            }
        }
    }

    return toRet;
}

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

private void renderInline(FacesContext facesContext, HtmlInputCalendar inputCalendar, Calendar timeKeeper,
        DateFormatSymbols symbols) throws IOException {
    String[] weekdays = mapShortWeekdays(symbols);
    String[] months = mapMonths(symbols);

    int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH);

    int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH);

    if (currentDay > lastDayInMonth)
        currentDay = lastDayInMonth;/*from  w ww .j  a  v  a2 s.  com*/

    timeKeeper.set(Calendar.DAY_OF_MONTH, 1);

    int weekDayOfFirstDayOfMonth = mapCalendarDayToCommonDay(timeKeeper.get(Calendar.DAY_OF_WEEK));

    int weekStartsAtDayIndex = mapCalendarDayToCommonDay(timeKeeper.getFirstDayOfWeek());

    ResponseWriter writer = facesContext.getResponseWriter();

    HtmlRendererUtils.writePrettyLineSeparator(facesContext);
    HtmlRendererUtils.writePrettyLineSeparator(facesContext);

    writer.startElement(HTML.TABLE_ELEM, inputCalendar);
    HtmlRendererUtils.renderHTMLAttributes(writer, inputCalendar, HTML.UNIVERSAL_ATTRIBUTES);

    Map<String, List<ClientBehavior>> behaviors = inputCalendar.getClientBehaviors();

    if (behaviors != null && !behaviors.isEmpty()) {
        writer.writeAttribute(HTML.ID_ATTR, inputCalendar.getClientId(facesContext), null);
        HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, inputCalendar, behaviors);
        HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer,
                inputCalendar, behaviors);
    } else {
        HtmlRendererUtils.writeIdIfNecessary(writer, inputCalendar, facesContext);
        HtmlRendererUtils.renderHTMLAttributes(writer, inputCalendar, HTML.EVENT_HANDLER_ATTRIBUTES);
        HtmlRendererUtils.renderHTMLAttributes(writer, inputCalendar,
                HTML.COMMON_FIELD_EVENT_ATTRIBUTES_WITHOUT_ONSELECT_AND_ONCHANGE);
    }
    writer.flush();

    HtmlRendererUtils.writePrettyLineSeparator(facesContext);

    writer.startElement(HTML.TR_ELEM, inputCalendar);

    if (inputCalendar.getMonthYearRowClass() != null)
        writer.writeAttribute(HTML.CLASS_ATTR, inputCalendar.getMonthYearRowClass(), null);

    writeMonthYearHeader(facesContext, writer, inputCalendar, timeKeeper, currentDay, weekdays, months);

    writer.endElement(HTML.TR_ELEM);

    HtmlRendererUtils.writePrettyLineSeparator(facesContext);

    writer.startElement(HTML.TR_ELEM, inputCalendar);

    if (inputCalendar.getWeekRowClass() != null)
        writer.writeAttribute(HTML.CLASS_ATTR, inputCalendar.getWeekRowClass(), null);

    writeWeekDayNameHeader(weekStartsAtDayIndex, weekdays, facesContext, writer, inputCalendar);

    writer.endElement(HTML.TR_ELEM);

    HtmlRendererUtils.writePrettyLineSeparator(facesContext);

    writeDays(facesContext, writer, inputCalendar, timeKeeper, currentDay, weekStartsAtDayIndex,
            weekDayOfFirstDayOfMonth, lastDayInMonth, weekdays);

    writer.endElement(HTML.TABLE_ELEM);
}

From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java

/**
 * //from   ww w .j  a v a 2  s .co m
 * @param level
 * @param parentMember
 * @param members
 * 
 */
private List<MiniCubeMember> genMembersWithMonthParentForAll(Level level, Member parentMember) {
    List<MiniCubeMember> members = Lists.newArrayList();
    Calendar cal = Calendar.getInstance();
    int nowMonth = cal.get(Calendar.MONTH); // ?-1
    int year = cal.get(Calendar.YEAR); // ?
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    for (int i = 0; i <= nowMonth; i++) {
        cal.set(year, i, 1); // ?
        String day = sf.format(cal.getTime());
        String month = day.substring(4, 6);
        String caption = year + "" + month + "";
        MiniCubeMember firstDayOfMonth = new MiniCubeMember(day);
        firstDayOfMonth.setCaption(caption);
        firstDayOfMonth.setLevel(level);
        firstDayOfMonth.setParent(parentMember);
        firstDayOfMonth.setName(day);
        firstDayOfMonth.setVisible(true);
        int daysOfMonth = cal.getActualMaximum(Calendar.DATE);
        for (int j = 0; j < daysOfMonth; j++) {
            firstDayOfMonth.getQueryNodes().add(sf.format(cal.getTime()));
            cal.add(Calendar.DATE, 1);
        }
        members.add(firstDayOfMonth);
    }
    return members;
}

From source file:org.kuali.kra.s2s.generator.impl.PHS398FellowshipSupplementalV1_1Generator.java

private BudgetDecimal getNumberOfMonths(Date dateStart, Date dateEnd) {
    BudgetDecimal monthCount = BudgetDecimal.ZERO;
    int fullMonthCount = 0;

    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    startDate.setTime(dateStart);//from w  w  w. j  a  v a  2s  .  c o m
    endDate.setTime(dateEnd);

    startDate.clear(Calendar.HOUR);
    startDate.clear(Calendar.MINUTE);
    startDate.clear(Calendar.SECOND);
    startDate.clear(Calendar.MILLISECOND);

    endDate.clear(Calendar.HOUR);
    endDate.clear(Calendar.MINUTE);
    endDate.clear(Calendar.SECOND);
    endDate.clear(Calendar.MILLISECOND);

    if (startDate.after(endDate)) {
        return BudgetDecimal.ZERO;
    }
    int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE);
    startMonthDays++;
    int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE);
    BudgetDecimal startMonthFraction = new BudgetDecimal(startMonthDays)
            .divide(new BudgetDecimal(startMonthMaxDays));

    int endMonthDays = endDate.get(Calendar.DATE);
    int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE);

    BudgetDecimal endMonthFraction = new BudgetDecimal(endMonthDays).divide(new BudgetDecimal(endMonthMaxDays));

    startDate.set(Calendar.DATE, 1);
    endDate.set(Calendar.DATE, 1);

    while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
        startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1);
        fullMonthCount++;
    }
    fullMonthCount = fullMonthCount - 1;
    monthCount = monthCount.add(new BudgetDecimal(fullMonthCount)).add(startMonthFraction)
            .add(endMonthFraction);
    return monthCount;
}

From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java

/**
 * ?????/* www .  java 2  s. c  o m*/
 * 
 * @param level
 * @param parentMember
 * @param name
 * @param tmpArray
 * @param quarterIndex
 * 
 */
private List<MiniCubeMember> genMonthMemberWithQuarterParent(Level level, Member parentMember, String name,
        String[] tmpArray, int quarterIndex) {
    List<MiniCubeMember> members = Lists.newArrayList();
    Calendar cal = Calendar.getInstance();
    String[] months = QUARTER_MONTH_MAPPING[quarterIndex];
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    for (String month : months) {
        String memberName = "[Time]." + tmpArray[1] + ".[" + month.substring(0, 2) + "]";
        MiniCubeMember monthMember = new MiniCubeMember(memberName);
        monthMember.setCaption(tmpArray[1].substring(1, 5) + "" + month.substring(0, 2) + "");
        monthMember.setLevel(level);
        monthMember.setName(tmpArray[1].substring(1, 5) + month);
        monthMember.setParent(parentMember);
        monthMember.setVisible(true);
        cal.set(Calendar.YEAR, Integer.valueOf(tmpArray[1].substring(1, 5)));
        cal.set(Calendar.MONTH, Integer.valueOf(month.substring(0, 2)) - 1);
        cal.set(Calendar.DATE, 1);
        int daysOfMonth = cal.getActualMaximum(Calendar.DATE);
        for (int i = 0; i < daysOfMonth; i++) {
            String day = sf.format(cal.getTime());
            monthMember.getQueryNodes().add(day);
            cal.add(Calendar.DATE, 1);
        }
        members.add(monthMember);
    }
    return members;
}