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

/**
 * ??? 20081231 - 1 20081201 20080831 + 1
 * 20080930//from w  ww.ja  v a2 s.c o  m
 *
 * @param dt
 * @param n
 * @return?11:22:39
 */
public static Date getNextMonthExtention(Date dt, Long n) {

    Calendar cal = new GregorianCalendar();
    cal.setTime(dt);

    Calendar firstCal = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(),
            1);
    if (firstCal.getActualMaximum(Calendar.DAY_OF_MONTH) < cal.get(Calendar.DAY_OF_MONTH)) {
        return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue() + 1, 1)
                .getTime();

    } else {
        return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + n.intValue(),
                cal.get(Calendar.DAY_OF_MONTH)).getTime();
    }
}

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * return a timestamp Object which correspond with the string specified in parameter.
 * @param date the date who must convert
 * @param locale the locale//from   w w w  .j av a  2s .  co  m
 * @return a timestamp Object which correspond with the string specified in parameter.
 */
public static Timestamp getDateLastMinute(Date date, Locale locale) {
    if (date == null) {
        return null;
    }

    Calendar caldate = new GregorianCalendar();
    caldate.setTime(date);
    caldate.set(Calendar.MILLISECOND, 0);
    caldate.set(Calendar.SECOND, 0);
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE));

    Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

    return timeStamp;
}

From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java

/**
 * return a timestamp Object which correspond to the timestamp
 * in parameter add with a  number of times unit (day,week,month)specify in strTimesUnit .
 * @param timestamp date/*w ww.j  av a  2s  .  co m*/
 * @param strTimesUnit (day,week,month)
 * @param nDecal the number of timesUnit
 * @return a timestamp Object which correspond with the string specified in parameter
 * add with a  number of times unit (day,week,month)specify in strTimesUnit.
 */
public static Timestamp addStatisticInterval(Timestamp timestamp, String strTimesUnit, int nDecal) {
    int nTimesUnit = Calendar.DAY_OF_MONTH;

    if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_WEEK)) {
        nTimesUnit = Calendar.WEEK_OF_MONTH;
    } else if (strTimesUnit.equals(FormUtils.CONSTANT_GROUP_BY_MONTH)) {
        nTimesUnit = Calendar.MONTH;
    }

    Calendar caldate = new GregorianCalendar();
    caldate.setTime(timestamp);
    caldate.set(Calendar.MILLISECOND, 0);
    caldate.set(Calendar.SECOND, 0);
    caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY));
    caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE));
    caldate.add(nTimesUnit, nDecal);

    Timestamp timeStamp1 = new Timestamp(caldate.getTimeInMillis());

    return timeStamp1;
}

From source file:com.xumpy.thuisadmin.controllers.rest.OverviewMonthCategory.java

@RequestMapping("/json/report_overzicht_groep_bedragen_per_maand")
public @ResponseBody OverzichtGroepBedragenTotal fetchReportOverzichtGroepBedragenPerMonth(
        @RequestBody OverviewMonthCategoryReport overviewMonthCategoryReport) throws ParseException {
    SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyy");
    Date startDate = dt.parse("01/" + overviewMonthCategoryReport.getDate());
    Calendar c = Calendar.getInstance();
    c.setTime(dt.parse("01/" + overviewMonthCategoryReport.getDate()));
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
    Date endDate = c.getTime();/* w  w w.  j  a  v a 2 s .  c om*/

    OverzichtGroepBedragenTotal overzicht = new OverzichtGroepBedragenTotal();
    OverzichtGroepBedragenTotal overzichtGroep = bedragenSrv.rapportOverzichtGroepBedragen(
            overviewMonthCategoryReport.getMainGroup(), startDate, endDate, 0, overzichtGroepBedragenTotal);
    overzicht.setOverzichtGroepBedragen(overzichtGroep.getOverzichtGroepBedragen());
    overzicht.setSomBedrag(overzichtGroep.getSomBedrag());

    return overzicht;
}

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

/**
 *  <code>date</code><span style="color:red">?</span>,<code>23:59:59.999</code> .
 * //from   w ww  .j a  v  a 2 s.c o  m
 * <p>
 *  <code>date</code> ,,2 2829
 * </p>
 * 
 * <pre class="code">
 * DateUtil.getLastDateOfThisMonth(2012-10-11 17:10:30.701)=2012-10-31 23:59:59.999
 * </pre>
 * 
 * @param date
 *            ?
 * @return  <code>date</code> null, {@link NullPointerException}
 * @see #toCalendar(Date)
 * @see Calendar#set(int, int)
 * @see CalendarUtil#resetDayEnd(Calendar)
 * @see Calendar#getTime()
 */
public static Date getLastDateOfThisMonth(Date date) {
    Calendar calendar = toCalendar(date);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    return CalendarUtil.toDate(CalendarUtil.resetDayEnd(calendar));
}

From source file:com.xumpy.thuisadmin.controllers.rest.OverviewMonthCategory.java

@RequestMapping("/json/fetchOverviewMonthCategory")
public @ResponseBody OverviewMonthCategoryResulst fetchMonthCategory(
        @RequestBody OverviewMonthCategoryInput overviewMonthCategory) throws ParseException {
    this.overviewMonthCategoryInput = overviewMonthCategory;

    SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyy");
    Date startDate = dt.parse("01/" + overviewMonthCategory.getBeginDate());
    Calendar c = Calendar.getInstance();
    c.setTime(dt.parse("01/" + overviewMonthCategory.getEndDate()));
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
    Date endDate = c.getTime();/*from  www .  jav  a 2 s  . co m*/

    List<Integer> mainGroups = new ArrayList<Integer>();
    for (MainGroupValue mainGroup : overviewMonthCategory.getMainGroupValues()) {
        mainGroups.add(mainGroup.getPk_id());
    }

    List<? extends Bedragen> bedragen = bedragenSrv
            .filterBedragenWithMainGroup(bedragenSrv.selectBedragenInPeriode(startDate, endDate), mainGroups);
    OverviewMonthCategoryResulst overviewMonthCategoryResult = new OverviewMonthCategoryResulst(bedragen,
            groepenSrv, bedragenSrv);

    return overviewMonthCategoryResult;
}

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

@Test(expected = ConfigurationException.class)
public void testDoActivateInvalidHighDayOfMonth() throws Exception {
    Calendar test = Calendar.getInstance();
    int val = test.getActualMaximum(Calendar.DAY_OF_MONTH) + 1;
    properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, val);
    filter.doActivate(componentContext);
}

From source file:rzd.vivc.documentexamination.form.service.DateFilterServiceWithCalendar.java

@Override
public DateFilter createFirstAndLastDayOfMonth(Date dayOfMonth) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dayOfMonth);//from  ww w .j  av a  2  s .  c  om
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); // ?   ??
    Date start = calendar.getTime();
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    Date finish = calendar.getTime();
    return new DateFilter(start, finish);
}

From source file:com.xumpy.timesheets.services.implementations.JobsSrvImpl.java

@Override
@Transactional// w ww  .j a v  a  2 s.co m
public List<? extends Jobs> selectMonth(String month) throws ParseException {
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date startDate = df.parse("01/" + month);

    Calendar c = Calendar.getInstance();
    c.setTime(startDate);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
    Date endDate = c.getTime();

    return jobsDao.selectPeriode(startDate, endDate);
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
 * ?//from   w  w w .  j  a v a 2  s .c o  m
 *
 * @param date
 * @param dd
 * @return
 */
public static boolean isSameDate(Date date, String dd) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int day = Integer.parseInt(dd);

    if (calendar.get(Calendar.DATE) == day)
        return true;

    if (calendar.get(Calendar.DATE) < day) {
        if (calendar.get(Calendar.DATE) == calendar.getActualMaximum(Calendar.DATE))
            return true;
    }

    return false;
}