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:org.richfaces.component.UICalendar.java

protected Date getDefaultPreloadEnd(Date date) {
    Calendar calendar = Calendar.getInstance(getTimeZone(), getAsLocale(getLocale()));
    calendar.setTime(date);//from  ww w. j  a v a2 s.  c  om
    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
    /*
     * //force recalculation calendar.getTimeInMillis();
     * calendar.set(Calendar.DAY_OF_WEEK, getLastDayOfWeek(calendar));
     */
    return calendar.getTime();
}

From source file:org.openconcerto.erp.core.humanresources.payroll.report.FichePayeSheet.java

protected void createMap() {

    this.styleMapRow = new HashMap();
    this.mapReplace = new HashMap();

    this.mCell = new HashMap();

    // Infos societe
    SQLRow rowSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete();
    this.mCell.put("B1", rowSociete.getObject("TYPE") + " " + rowSociete.getObject("NOM"));
    SQLRow rowAdrSociete = tableAdresseCommon.getRow(rowSociete.getInt("ID_ADRESSE_COMMON"));
    this.mCell.put("B2", rowAdrSociete.getObject("RUE"));
    this.mCell.put("B3", rowAdrSociete.getString("CODE_POSTAL") + " " + rowAdrSociete.getString("VILLE"));

    this.mCell.put("D5", rowSociete.getObject("NUM_SIRET"));
    this.mCell.put("D6", rowSociete.getObject("NUM_APE"));
    this.mapReplace.put("D8", rowSociete.getObject("NUMERO_URSSAF"));

    // Infos Salarie
    SQLRow rowSal = tableSalarie.getRow(this.row.getInt("ID_SALARIE"));
    SQLRow rowEtatCivil = tableEtatCivil.getRow(rowSal.getInt("ID_ETAT_CIVIL"));
    this.mCell.put("G8", rowSal.getObject("NOM") + " " + rowSal.getObject("PRENOM"));
    SQLRow rowAdrSal = tableAdresse.getRow(rowEtatCivil.getInt("ID_ADRESSE"));
    this.mCell.put("G9", rowAdrSal.getObject("RUE"));
    this.mCell.put("G11", rowAdrSal.getString("CODE_POSTAL") + " " + rowAdrSal.getString("VILLE"));

    this.mCell.put("D13", rowEtatCivil.getObject("NUMERO_SS"));

    SQLRow rowInfosPaye = tableInfosPaye.getRow(rowSal.getInt("ID_INFOS_SALARIE_PAYE"));
    SQLRow rowContrat = tableContrat.getRow(rowInfosPaye.getInt("ID_CONTRAT_SALARIE"));

    if (this.row.getString("NATURE_EMPLOI").trim().length() == 0) {
        this.mCell.put("D14", rowContrat.getObject("NATURE"));
    } else {/* www  . jav a 2 s  . com*/
        this.mCell.put("D14", this.row.getString("NATURE_EMPLOI"));
    }

    SQLRow rowCC;
    if (this.row.getInt("ID_IDCC") > 1) {
        rowCC = tableConventionC.getRow(this.row.getInt("ID_IDCC"));
    } else {
        rowCC = tableConventionC.getRow(rowInfosPaye.getInt("ID_IDCC"));
    }
    this.mCell.put("D15", rowCC.getString("NOM"));

    // Bulletin du
    // Bulletin de paie du
    Date du = (Date) this.row.getObject("DU");
    Date au = (Date) this.row.getObject("AU");
    this.mCell.put("F1", "Bulletin de paie du " + dateFormat.format(du) + " au " + dateFormat.format(au));

    // Paiement le
    SQLRow rowRegl;
    if (this.row.getInt("ID_REGLEMENT_PAYE") <= 1) {
        rowRegl = tableReglementPaye.getRow(rowSal.getInt("ID_REGLEMENT_PAYE"));
    } else {
        rowRegl = tableReglementPaye.getRow(this.row.getInt("ID_REGLEMENT_PAYE"));
    }
    SQLRow rowModeRegl = tableModeRegl.getRow(rowRegl.getInt("ID_MODE_REGLEMENT_PAYE"));

    Calendar c = Calendar.getInstance();

    c.set(Calendar.MONTH, this.row.getInt("ID_MOIS") - 2);
    c.set(Calendar.YEAR, Integer.parseInt(this.row.getString("ANNEE")));

    if (rowRegl.getInt("LE") != 31) {

        c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
    }

    int max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
    int day = Math.min(rowRegl.getInt("LE"), max);

    c.set(Calendar.DAY_OF_MONTH, day);

    this.mCell.put("H3", dateFormat.format(c.getTime()));
    this.mCell.put("I3", "Par " + rowModeRegl.getObject("NOM"));

    // Congs
    // "G3";
    SQLRow rowConges;
    if (this.row.getInt("ID_CUMULS_CONGES") <= 1) {
        rowConges = tableCumulsConges.getRow(rowSal.getInt("ID_CUMULS_CONGES"));
    } else {
        rowConges = tableCumulsConges.getRow(this.row.getInt("ID_CUMULS_CONGES"));
    }

    SQLRow rowVarSal;
    if (this.row.getInt("ID_VARIABLE_SALARIE") <= 1) {
        rowVarSal = tableVarPeriode.getRow(rowSal.getInt("ID_VARIABLE_SALARIE"));
    } else {
        rowVarSal = tableVarPeriode.getRow(this.row.getInt("ID_VARIABLE_SALARIE"));
    }

    float congesPris = rowVarSal.getFloat("CONGES_PRIS");
    float congesRestant = rowConges.getFloat("RESTANT") - congesPris;
    float congesAcquis = rowConges.getFloat("ACQUIS") + this.row.getFloat("CONGES_ACQUIS");
    this.mCell.put("G14", new Float(congesPris));
    this.mCell.put("H14", new Float(congesRestant));
    this.mCell.put("I14", new Float(congesAcquis));

    // Element Devis
    SQLSelect selElt = new SQLSelect(base);
    selElt.addSelect(tableFicheElt.getField("ID"));
    selElt.setWhere(tableFicheElt.getField("ID_FICHE_PAYE"), "=", this.row.getID());

    String req = selElt.asString() + " ORDER BY \"FICHE_PAYE_ELEMENT\".\"POSITION\"";
    List l = (List) base.getDataSource().execute(req, new ArrayListHandler());
    int pos = 20;
    for (Iterator i = l.iterator(); i.hasNext();) {
        Object[] o = (Object[]) i.next();
        SQLRow rowTmp = tableFicheElt.getRow(Integer.parseInt(o[0].toString()));

        if (rowTmp.getBoolean("IMPRESSION") && rowTmp.getBoolean("IN_PERIODE")) {

            Object nomTmp = rowTmp.getObject("NOM");
            this.mCell.put("B" + pos, nomTmp);

            // Base
            Object baseTmp = rowTmp.getObject("NB_BASE");

            if (baseTmp != null) {
                float base = ((Float) baseTmp).floatValue();
                if (base != 0) {
                    this.mCell.put("E" + pos, baseTmp);
                } else {
                    this.mCell.put("E" + pos, "");
                }
            } else {
                this.mCell.put("E" + pos, baseTmp);
            }

            // Taux Sal
            Object tauxSalTmp = rowTmp.getObject("TAUX_SAL");

            if (tauxSalTmp != null) {
                float tauxSal = ((Float) tauxSalTmp).floatValue();
                if (tauxSal != 0) {
                    this.mCell.put("F" + pos, tauxSalTmp);
                } else {
                    this.mCell.put("F" + pos, "");
                }
            } else {
                this.mCell.put("F" + pos, tauxSalTmp);
            }

            // Montant Sal Aj
            Object montantSalAjTmp = rowTmp.getObject("MONTANT_SAL_AJ");
            if (montantSalAjTmp != null) {
                float montantSalAj = ((Float) montantSalAjTmp).floatValue();
                if (montantSalAj != 0) {
                    this.mCell.put("G" + pos, montantSalAjTmp);
                } else {
                    this.mCell.put("G" + pos, "");
                }
            } else {
                this.mCell.put("G" + pos, montantSalAjTmp);
            }

            // Montant Sal ded
            Object montantSalDedTmp = rowTmp.getObject("MONTANT_SAL_DED");
            if (montantSalDedTmp != null) {
                float montantSalDed = ((Float) montantSalDedTmp).floatValue();
                if (montantSalDed != 0) {
                    this.mCell.put("H" + pos, montantSalDedTmp);
                } else {
                    this.mCell.put("H" + pos, "");
                }
            } else {
                this.mCell.put("H" + pos, montantSalDedTmp);
            }

            // Taux Pat
            Object tauxPatTmp = rowTmp.getObject("TAUX_PAT");
            if (tauxPatTmp != null) {
                float tauxPat = ((Float) tauxPatTmp).floatValue();
                if (tauxPat != 0) {
                    this.mCell.put("I" + pos, tauxPatTmp);
                } else {
                    this.mCell.put("I" + pos, "");
                }
            } else {
                this.mCell.put("I" + pos, tauxPatTmp);
            }

            // Montant Pat
            Object montantPatTmp = rowTmp.getObject("MONTANT_PAT");
            if (montantPatTmp != null) {
                float montantPat = ((Float) montantPatTmp).floatValue();
                if (montantPat != 0) {
                    this.mCell.put("J" + pos, montantPatTmp);
                } else {
                    this.mCell.put("J" + pos, "");
                }
            } else {
                this.mCell.put("J" + pos, montantPatTmp);
            }

            if (rowTmp.getString("SOURCE").equalsIgnoreCase("RUBRIQUE_COMM")) {
                this.mapStyleRow.put(new Integer(pos), "Titre 1");
            } else {
                this.mapStyleRow.put(new Integer(pos), "Normal");
            }

            pos++;
        }
    }

    // Totaux
    float netApayerCumul = this.row.getFloat("NET_A_PAYER");
    float salBrutCumul = this.row.getFloat("SAL_BRUT");
    float cotSalCumul = this.row.getFloat("COT_SAL");
    float cotPatCumul = this.row.getFloat("COT_PAT");
    float netImpCumul = this.row.getFloat("NET_IMP");
    this.mCell.put("I61", this.row.getObject("NET_A_PAYER"));
    this.mCell.put("D61", this.row.getObject("SAL_BRUT"));
    this.mCell.put("E61", this.row.getObject("COT_SAL"));
    this.mCell.put("F61", this.row.getObject("COT_PAT"));
    this.mCell.put("H61", this.row.getObject("NET_IMP"));

    SQLRow rowCumulsPaye;

    if (this.row.getInt("ID_CUMULS_PAYE") == 1) {
        rowCumulsPaye = tableCumulsPaye.getRow(rowSal.getInt("ID_CUMULS_PAYE"));
    } else {
        rowCumulsPaye = tableCumulsPaye.getRow(this.row.getInt("ID_CUMULS_PAYE"));
    }

    netApayerCumul += rowCumulsPaye.getFloat("NET_A_PAYER_C");
    salBrutCumul += rowCumulsPaye.getFloat("SAL_BRUT_C");
    cotSalCumul += rowCumulsPaye.getFloat("COT_SAL_C");
    cotPatCumul += rowCumulsPaye.getFloat("COT_PAT_C");
    netImpCumul += rowCumulsPaye.getFloat("NET_IMP_C");

    this.mCell.put("D62", new Float(salBrutCumul));
    this.mCell.put("E62", new Float(cotSalCumul));
    this.mCell.put("F62", new Float(cotPatCumul));
    this.mCell.put("H62", new Float(netImpCumul));
}

From source file:com.xtc.controller.UserController.java

/***
 * //w  w  w.  j  a  v  a  2s .c  om
 * @param map
 * @return
 */
@RequestMapping(value = "getRegistCount", method = RequestMethod.GET)
public String getRegistCount(ModelMap mv, Integer year, Integer month) {
    //
    if (year == null || month == null) {
        Calendar calendarCountDays = new GregorianCalendar();
        calendarCountDays.setTime(new Date());
        year = calendarCountDays.get(Calendar.YEAR);
        month = calendarCountDays.get(Calendar.MONTH) + 1;
    }
    //
    Map<String, String> map = new HashMap<String, String>();
    map.put("begin", year + "-" + (month < 10 ? "0" + month : month));
    map.put("end", year + "-" + ((month + 1) < 10 ? "0" + (month + 1) : (month + 1)));
    //
    Calendar cd = new GregorianCalendar();
    SimpleDateFormat s = new SimpleDateFormat("yyyy-MM");
    try {
        cd.setTime(s.parse(map.get("begin")));
    } catch (ParseException e) {
        System.out.println("");
    }
    int daysCount = cd.getActualMaximum(Calendar.DAY_OF_MONTH);
    List<String> daysList = new ArrayList<String>();// ---------
    for (int i = 1; i <= daysCount; i++) {
        map.put(map.get("begin") + "-" + (i < 10 ? "0" + i : i), 0 + "");
        daysList.add("'" + map.get("begin") + "-" + i + "'");
    }
    List<RegistCountDto> olist = new ArrayList<RegistCountDto>();
    List<Object> list = us.RegistCount(year, month);
    for (int i = 0; i < list.size(); i++) {
        Object[] o = (Object[]) list.get(i);
        RegistCountDto or = new RegistCountDto();
        or.setDatecreated((String) o[0]);
        or.setCount((Object) o[1]);
        olist.add(or);
        map.put(olist.get(i).getDatecreated(), olist.get(i).getCount() + "");
    }
    List<String> daysListDate = new ArrayList<String>();//---------
    for (int i = 1; i <= daysCount; i++) {
        daysListDate.add(map.get(map.get("begin") + "-" + (i < 10 ? "0" + i : i)));
    }
    mv.addAttribute("daysList", daysList);//
    mv.addAttribute("daysListDate", daysListDate);//
    mv.addAttribute("year", year);//
    mv.addAttribute("month", month);//
    return "RegistCount";
}

From source file:org.projectforge.fibu.AuftragDao.java

private List<AuftragDO> getList(final BaseSearchFilter filter, final boolean checkAccess) {
    final AuftragFilter myFilter;
    if (filter instanceof AuftragFilter) {
        myFilter = (AuftragFilter) filter;
    } else {//from   w w  w . j a v  a  2s. c  om
        myFilter = new AuftragFilter(filter);
    }
    final QueryFilter queryFilter = new QueryFilter(myFilter);
    if (myFilter.getYear() > 1900) {
        final Calendar cal = DateHelper.getUTCCalendar();
        cal.set(Calendar.YEAR, myFilter.getYear());
        java.sql.Date lo = null;
        java.sql.Date hi = null;
        cal.set(Calendar.DAY_OF_YEAR, 1);
        lo = new java.sql.Date(cal.getTimeInMillis());
        final int lastDayOfYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
        cal.set(Calendar.DAY_OF_YEAR, lastDayOfYear);
        hi = new java.sql.Date(cal.getTimeInMillis());
        queryFilter.add(Restrictions.between("angebotsDatum", lo, hi));
    }
    queryFilter.addOrder(Order.desc("nummer"));
    Boolean vollstaendigFakturiert = null;
    if (myFilter.isShowBeauftragtNochNichtVollstaendigFakturiert() == true) {
        queryFilter.add(Restrictions.not(Restrictions.in("auftragsStatus",
                new AuftragsStatus[] { AuftragsStatus.ABGELEHNT, AuftragsStatus.ERSETZT, AuftragsStatus.GELEGT,
                        AuftragsStatus.GROB_KALKULATION, AuftragsStatus.IN_ERSTELLUNG })));
        vollstaendigFakturiert = false;
    } else if (myFilter.isShowNochNichtVollstaendigFakturiert() == true) {
        queryFilter.add(Restrictions.not(Restrictions.in("auftragsStatus",
                new AuftragsStatus[] { AuftragsStatus.ABGELEHNT, AuftragsStatus.ERSETZT })));
        vollstaendigFakturiert = false;
    } else if (myFilter.isShowVollstaendigFakturiert() == true) {
        vollstaendigFakturiert = true;
    } else if (myFilter.isShowAbgelehnt() == true) {
        queryFilter.add(Restrictions.eq("auftragsStatus", AuftragsStatus.ABGELEHNT));
    } else if (myFilter.isShowAbgeschlossenNichtFakturiert() == true) {
        queryFilter.createAlias("positionen", "position")
                .add(Restrictions.or(Restrictions.eq("auftragsStatus", AuftragsStatus.ABGESCHLOSSEN),
                        Restrictions.and(
                                Restrictions.eq("position.status", AuftragsPositionsStatus.ABGESCHLOSSEN),
                                Restrictions.eq("position.vollstaendigFakturiert", false))));
        vollstaendigFakturiert = false; // Und noch nicht fakturiert.
    } else if (myFilter.isShowAkquise() == true) {
        queryFilter.add(Restrictions.in("auftragsStatus", new AuftragsStatus[] { AuftragsStatus.GELEGT,
                AuftragsStatus.IN_ERSTELLUNG, AuftragsStatus.GROB_KALKULATION }));
    } else if (myFilter.isShowBeauftragt() == true) {
        queryFilter.add(Restrictions.in("auftragsStatus", new AuftragsStatus[] { AuftragsStatus.BEAUFTRAGT,
                AuftragsStatus.LOI, AuftragsStatus.ESKALATION }));
    } else if (myFilter.isShowErsetzt() == true) {
        queryFilter.add(Restrictions.eq("auftragsStatus", AuftragsStatus.ERSETZT));
    }
    final List<AuftragDO> list;
    if (checkAccess == true) {
        list = getList(queryFilter);
    } else {
        list = internalGetList(queryFilter);
    }
    if (vollstaendigFakturiert != null || myFilter.getAuftragsPositionsArt() != null) {
        final Boolean fakturiert = vollstaendigFakturiert;
        final AuftragFilter fil = myFilter;
        CollectionUtils.filter(list, new Predicate() {
            public boolean evaluate(final Object object) {
                final AuftragDO auftrag = (AuftragDO) object;
                if (fil.getAuftragsPositionsArt() != null) {
                    boolean match = false;
                    if (CollectionUtils.isNotEmpty(auftrag.getPositionen()) == true) {
                        for (final AuftragsPositionDO position : auftrag.getPositionen()) {
                            if (fil.getAuftragsPositionsArt() == position.getArt()) {
                                match = true;
                                break;
                            }
                        }
                    }
                    if (match == false) {
                        return false;
                    }
                }
                if (fakturiert != null) {
                    return auftrag.isVollstaendigFakturiert() == fakturiert;
                }
                return true;
            }
        });
    }
    return list;
}

From source file:com.borax12.materialdaterangepicker.single.date.DatePickerDialog.java

private void adjustDayInMonthIfNeeded(Calendar calendar) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    if (day > daysInMonth) {
        calendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
    }//from   ww w .  j  ava  2s. c om
    setToNearestDate(calendar);
}

From source file:me.diskstation.ammon.gpsrunner.ui.CalendarFragment.java

protected ArrayList<Run> getRuns(final Bundle args) {
    int year = args.getInt("spinner_selection_year");
    int month = args.getInt("spinner_selection_month");
    Calendar calendar = Calendar.getInstance();
    if (year != 0) {
        calendar.set(Calendar.YEAR, year);
    }/*  w  w  w . j  av a  2  s .c  om*/
    if (month != 0) {
        calendar.set(Calendar.MONTH, month);
    }
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND));
    long startTimestamp = calendar.getTimeInMillis();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
    calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND));
    long endTimestamp = calendar.getTimeInMillis();
    LocationDBHelper dbHelp = new LocationDBHelper(getActivity());
    LocationDBReader dbRead = new LocationDBReader(dbHelp);
    return dbRead.getRuns(startTimestamp, endTimestamp, "ASC");
}

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

/**
 * ??// w ww .  ja va2 s  .  c  o m
 * 
 * @param level
 * @param parentMember
 * @return
 */
private List<MiniCubeMember> genMembersWithQuarterParentForAll(Level level, Member parentMember) {
    List<MiniCubeMember> members = Lists.newArrayList();
    Calendar cal = Calendar.getInstance(); // ?
    cal.set(Calendar.DAY_OF_MONTH, 1); // 1?
    int nowMonth = cal.get(Calendar.MONTH) + 1; // ?
    int quarterIndex = nowMonth / 3; // 
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    for (int i = 0; i <= quarterIndex; i++) {
        cal.set(Calendar.MONTH, i * 3);// 
        cal.set(Calendar.DATE, 1);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(cal.getTime());
        calEnd.add(Calendar.MONTH, 2);
        calEnd.add(Calendar.DATE, calEnd.getActualMaximum(Calendar.DATE) - 1); // 
        String day = sf.format(cal.getTime());
        String year = day.substring(0, 4);
        String caption = year + "" + (i + 1) + "";
        MiniCubeMember firstDayOfQuarter = new MiniCubeMember(day);
        firstDayOfQuarter.setCaption(caption);
        firstDayOfQuarter.setLevel(level);
        firstDayOfQuarter.setParent(parentMember);
        firstDayOfQuarter.setName(day);
        firstDayOfQuarter.setVisible(true);
        while (cal.before(calEnd) || (cal.compareTo(calEnd) == 0)) {
            firstDayOfQuarter.getQueryNodes().add(sf.format(cal.getTime()));
            cal.add(Calendar.DATE, 1);
        }
        members.add(firstDayOfQuarter);
    }
    return members;
}

From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java

@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
    log.debug("encodeEnd - component=\"" + component + "\".");
    RendererUtils.checkParamValidity(facesContext, component, HtmlOcupationCalendar.class);

    HtmlOcupationCalendar inputCalendar = (HtmlOcupationCalendar) component;

    Locale currentLocale = facesContext.getViewRoot().getLocale();

    Date value = null;//from  ww  w  .  j a v  a2s.  c  o  m

    Calendar timeKeeper = Calendar.getInstance(currentLocale);
    timeKeeper.setTime(new Date());

    try {
        value = new CalendarDateTimeConverter().getAsDate(facesContext, inputCalendar);
        timeKeeper.setTime(value);
    } catch (IllegalArgumentException i) {
        log.warn("encodeEnd - IllegalArgumentException", i);
    }

    if (log.isDebugEnabled()) {
        log.debug("encodeEnd - timeKeeper=\"" + timeKeeper.getTime() + "\".");
    }

    DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);

    String[] weekdays = mapShortWeekdays(symbols);

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

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

    if (currentDay > lastDayInMonth)
        currentDay = lastDayInMonth;

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

    // render table
    writer.startElement(HTML.TABLE_ELEM, component);

    HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.UNIVERSAL_ATTRIBUTES);
    HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.EVENT_HANDLER_ATTRIBUTES);
    writer.flush();

    HtmlRendererUtils.writePrettyLineSeparator(facesContext);

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

    writer.endElement(HTML.TABLE_ELEM);
}

From source file:com.borax12.materialdaterangepicker.date.DatePickerDialog.java

private void adjustDayInMonthIfNeeded(Calendar calendar) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    if (day > daysInMonth) {
        calendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
    }//from ww  w  .  j a  v  a2  s  . co  m
}

From source file:org.hil.core.dao.hibernate.ChildrenDaoHibernate.java

public List<ChildrenVaccinatedInLocationVO> getChildrenVaccinatedInLocationReport(String timeFrom,
        String timeTo, Commune commune, District district, Vaccination vaccine) {
    List<ChildrenVaccinatedInLocationVO> statistics = new ArrayList<ChildrenVaccinatedInLocationVO>();

    String[] timeFromYM = timeFrom.split("/");
    String strTimeFrom = timeFromYM[1] + "-" + timeFromYM[0] + "-01 00:00:00";
    log.debug("From: " + strTimeFrom);

    Calendar calendar = Calendar.getInstance();
    String[] timeToYM = timeTo.split("/");
    int year = Integer.parseInt(timeToYM[1]);
    String strTimeFromY = year + "-01-01 00:00:00";
    calendar.set(year, Integer.parseInt(timeToYM[0]), 1);
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    String strTimeTo = year + "-" + timeToYM[0] + "-" + maxDay + " 23:59:59";
    log.debug("To: " + strTimeTo);

    String sql = "";

    if (commune != null) {
        sql = "(SELECT c.id as id, cm.commune_name as communeName, v.village_name as villageName, c.child_code as childCode, "
                + " c.full_name as fullName, c.gender as gender, c.date_of_birth as dateOfBirth, c.mother_name as motherName, "
                + "   cvh.date_of_immunization as dateOfImmunization, cvh.other_vaccinated_location as otherLocation, null as vaccinatedCommune "
                + " FROM children_vaccination_history cvh, children c, village v, commune cm "
                + " WHERE cvh.id_vaccination=:vaccine AND cvh.vaccinated=1 AND cvh.other_vaccinated_location BETWEEN 1 AND 4 AND cvh.id_children=c.id "
                + " AND c.id_village=v.id AND v.id_commune=cm.id AND cm.id=:cId "
                + " AND DATE(cvh.date_of_immunization) BETWEEN :beginTime AND :endTime) " + " UNION ALL "
                + " (SELECT c.id as id, cm2.commune_name as communeName, v.village_name as villageName, c.child_code as childCode, "
                + " c.full_name as fullName, c.gender as gender, c.date_of_birth as dateOfBirth, c.mother_name as motherName, "
                + " cvh.date_of_immunization as dateOfImmunization, cvh.other_vaccinated_location as otherLocation, cm.commune_name as vaccinatedCommune "
                + " FROM children_vaccination_history cvh, children c, village v,commune cm, commune cm2 "
                + " WHERE cvh.id_vaccination=:vaccine AND cvh.vaccinated=1 AND cvh.id_vaccinated_location=cm.id AND cm.id=:cId "
                + " AND DATE(cvh.date_of_immunization) BETWEEN :beginTime AND :endTime "
                + " And cvh.id_children=c.id and v.id=c.id_village and cm2.id=v.id_commune) order by id";
    } else if (district != null) {
        sql = "(SELECT c.id as id, cm.commune_name as communeName, v.village_name as villageName, c.child_code as childCode, "
                + " c.full_name as fullName, c.gender as gender, c.date_of_birth as dateOfBirth, c.mother_name as motherName, "
                + " cvh.date_of_immunization as dateOfImmunization, cvh.other_vaccinated_location as otherLocation, null as vaccinatedCommune"
                + " FROM children_vaccination_history cvh, children c, village v, commune cm, district d "
                + " WHERE cvh.id_vaccination=:vaccine AND cvh.vaccinated=1 AND cvh.other_vaccinated_location BETWEEN 1 AND 4 AND cvh.id_children=c.id "
                + " AND c.id_village=v.id AND v.id_commune=cm.id AND cm.id_district=d.id AND d.id=:dId "
                + " AND DATE(cvh.date_of_immunization) BETWEEN :beginTime AND :endTime)" + " UNION ALL "
                + " (SELECT c.id as id, cm2.commune_name as communeName, v.village_name as villageName, c.child_code as childCode, "
                + " c.full_name as fullName, c.gender as gender, c.date_of_birth as dateOfBirth, c.mother_name as motherName, "
                + " cvh.date_of_immunization as dateOfImmunization, cvh.other_vaccinated_location as otherLocation, cm.commune_name as vaccinatedCommune "
                + " FROM children_vaccination_history cvh, children c, village v,commune cm, district d, commune cm2 "
                + " WHERE cvh.id_vaccination=:vaccine AND cvh.vaccinated=1 AND cvh.id_vaccinated_location=cm.id AND cm.id_district=d.id AND d.id=:dId"
                + " AND DATE(cvh.date_of_immunization) BETWEEN :beginTime AND :endTime "
                + " AND cvh.id_children=c.id and v.id=c.id_village and cm2.id=v.id_commune) ORDER BY id";
    }//w w  w  . ja va 2 s.  c o  m

    log.debug(sql);

    SQLQuery qry = getSession().createSQLQuery(sql);
    if (commune != null)
        qry.setParameter("cId", commune.getId());
    else if (district != null)
        qry.setParameter("dId", district.getId());
    qry.setParameter("vaccine", vaccine.getId());
    qry.setParameter("beginTime", strTimeFrom);
    qry.setParameter("endTime", strTimeTo);

    qry.addScalar("id", Hibernate.LONG);
    qry.addScalar("communeName", Hibernate.STRING);
    qry.addScalar("villageName", Hibernate.STRING);
    qry.addScalar("childCode", Hibernate.STRING);
    qry.addScalar("fullName", Hibernate.STRING);
    qry.addScalar("gender", Hibernate.BOOLEAN);
    qry.addScalar("dateOfBirth", Hibernate.DATE);
    qry.addScalar("motherName", Hibernate.STRING);
    qry.addScalar("dateOfImmunization", Hibernate.DATE);
    qry.addScalar("otherLocation", Hibernate.SHORT);
    qry.addScalar("vaccinatedCommune", Hibernate.STRING);

    qry.setResultTransformer(Transformers.aliasToBean(ChildrenVaccinatedInLocationVO.class));

    statistics = qry.list();

    log.debug("Report: " + statistics.size());

    return statistics;
}