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.wso2telco.core.dbutils.DbService.java

public SpendLimitDAO getGroupTotalMonthAmount(String groupName, String operator, String msisdn)
        throws DBUtilException {

    Connection con = null;/*from  w ww  .  jav  a 2s . c o  m*/
    PreparedStatement ps = null;
    ResultSet rs = null;
    SpendLimitDAO spendLimitDAO = null;

    try {
        con = DbUtils.getDBConnection();

        Calendar calendarFrom = GregorianCalendar.getInstance();
        calendarFrom.set(Calendar.DAY_OF_MONTH, calendarFrom.getActualMinimum(Calendar.DAY_OF_MONTH));

        calendarFrom.set(Calendar.HOUR_OF_DAY, 0);
        calendarFrom.set(Calendar.MINUTE, 0);
        calendarFrom.set(Calendar.SECOND, 0);
        calendarFrom.set(Calendar.MILLISECOND, 0);

        Calendar calendarTo = GregorianCalendar.getInstance();
        calendarTo.setTime(new Date());
        calendarTo.set(Calendar.DAY_OF_MONTH, calendarTo.getActualMaximum(Calendar.DAY_OF_MONTH));
        calendarTo.set(Calendar.HOUR_OF_DAY, 23);
        calendarTo.set(Calendar.MINUTE, 59);
        calendarTo.set(Calendar.SECOND, 59);
        calendarTo.set(Calendar.MILLISECOND, 999);

        String sql = "SELECT SUM(amount) AS amount " + "FROM spendlimitdata  "
                + "where effectiveTime between ? and ? " + "and groupName=? " + "and operatorId=? "
                + "and msisdn=? " + "group by groupName,  operatorId, msisdn";

        ps = con.prepareStatement(sql);
        ps.setLong(1, calendarFrom.getTimeInMillis());
        ps.setLong(2, calendarTo.getTimeInMillis());
        ps.setString(3, groupName);
        ps.setString(4, operator);
        ps.setString(5, msisdn);
        rs = ps.executeQuery();

        rs = ps.executeQuery();

        if (rs.next()) {
            spendLimitDAO = new SpendLimitDAO();
            spendLimitDAO.setAmount(rs.getDouble("amount"));
        }
    } catch (Exception e) {
        DbUtils.handleException("Error while checking Operator Spend Limit. ", e);
    } finally {
        DbUtils.closeAllConnections(ps, con, rs);
    }
    return spendLimitDAO;
}

From source file:fragment.web.AbstractReportControllerTest.java

/**
 * Author: vinayv Description: Test to generate and validate New Registration Report with Null Start and End Dates
 * using GET./*  ww  w  .  j  av a 2 s .co  m*/
 */
@Test
public void testNewRegistrationsWithNullDatesGet() throws Exception {

    int count = 0;
    request.setParameter("lang", Locale.getDefault().toString());
    String resultString = reportController.newRegistrations(null, null, map, request);
    Assert.assertNotNull(resultString);
    Assert.assertEquals("report.newRegistration", resultString);
    Report report = (Report) map.get("report");
    Assert.assertTrue(report.getTitle().contains("New Registrations"));
    Calendar cal = Calendar.getInstance();
    DateFormat format = new SimpleDateFormat("dd MMM, yyyy");
    cal.set(Calendar.DATE, 1);
    String start = format.format(cal.getTime());
    cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
    String end = format.format(cal.getTime());
    Assert.assertEquals("New Registrations " + start + " - " + end, report.getTitle());
    String reportData = report.getData().replace("\\", "");

    JSONObject jsonObj = new JSONObject(reportData);
    org.codehaus.jettison.json.JSONArray jsonArray = (org.codehaus.jettison.json.JSONArray) jsonObj
            .get("series");
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        org.codehaus.jettison.json.JSONArray jsonArr = jsonObject.getJSONArray("data");
        if (jsonArr.length() > 0) {
            count = count + jsonArr.getInt(0);
        }
    }
    Assert.assertEquals(0, count);
}

From source file:fragment.web.AbstractReportControllerTest.java

/**
 * Author: vinayv Description: Test to generate and validate New Registration Report with Null Start and End Dates.
 *//*from  ww w.  j  a v  a 2 s.c  o m*/
@Test
public void testNewRegistrationsWithNullDates() throws Exception {

    int count = 0;
    NewRegistrationReportForm form = new NewRegistrationReportForm();
    form.setStartDate(null);
    form.setEndDate(null);
    BindingResult result = validate(form);
    request.setParameter("lang", Locale.getDefault().toString());
    String resultString = reportController.newRegistrations(map, request, form, result);
    Assert.assertNotNull(resultString);
    Assert.assertEquals("report.newRegistration", resultString);
    Report report = (Report) map.get("report");
    Assert.assertTrue(report.getTitle().contains("New Registrations"));
    Calendar cal = Calendar.getInstance();
    DateFormat format = new SimpleDateFormat("dd MMM, yyyy");
    cal.set(Calendar.DATE, 1);
    String start = format.format(cal.getTime());
    cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
    String end = format.format(cal.getTime());
    Assert.assertEquals("New Registrations " + start + " - " + end, report.getTitle());
    String reportData = report.getData().replace("\\", "");

    JSONObject jsonObj = new JSONObject(reportData);
    org.codehaus.jettison.json.JSONArray jsonArray = (org.codehaus.jettison.json.JSONArray) jsonObj
            .get("series");
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        org.codehaus.jettison.json.JSONArray jsonArr = jsonObject.getJSONArray("data");
        if (jsonArr.length() > 0) {
            count = count + jsonArr.getInt(0);
        }
    }
    Assert.assertEquals(0, count);
}

From source file:org.sakaiproject.tool.summarycalendar.ui.CalendarBean.java

private List getWeeks() {
    if (reloadCalendarEvents()) {
        initializeWeeksDataStructure();/*from   w w  w.jav a2 s.co  m*/

        // selected month
        Calendar c = Calendar.getInstance(getCurrentUserTimezone(), msgs.getLocale());
        c.setTime(getViewingDate());
        int selYear = c.get(Calendar.YEAR);
        int selMonth = c.get(Calendar.MONTH);
        c.set(Calendar.MONTH, selMonth);
        c.set(Calendar.DAY_OF_MONTH, 1);
        int dayOfWeek = new CalendarUtil(c).getDay_Of_Week(true);
        int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        int currDay = 1;
        // prev month
        c.add(Calendar.MONTH, -1);
        int prevMonthLastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);

        // fill weeks
        int weekNo = -1;
        int nextMonthDay = 1;
        while (currDay <= lastDay) {
            MonthWeek week = null;
            try {
                ++weekNo;
                week = (MonthWeek) weeks.get(weekNo);
            } catch (IndexOutOfBoundsException e) {
                // if previous had less weeks (4, 5)
                if (weekNo == 4) {
                    weeks.add(week5);
                    week = week5;
                }
                if (weekNo == 5) {
                    weeks.add(week6);
                    week = week6;
                }
            }
            for (int i = 0; i < 7; i++) {
                Day day = week.getDay(i);
                CalendarEventVector vector = null;
                if ((weekNo == 0) && (i < dayOfWeek - 1)) {
                    int nDay = prevMonthLastDay - dayOfWeek + 2 + i;
                    c.set(Calendar.MONTH, selMonth - 1);
                    c.set(Calendar.DAY_OF_MONTH, nDay);
                    vector = getScheduleEventsForDay(c);
                    day = new Day(c, getDayEventCount(vector) > 0);
                    day.setOccursInOtherMonth(true);
                    day.setBackgroundCSSProperty(getDayPriorityCSSProperty(vector));
                } else if (currDay > lastDay) {
                    c.set(Calendar.MONTH, selMonth + 1);
                    c.set(Calendar.DAY_OF_MONTH, nextMonthDay++);
                    vector = getScheduleEventsForDay(c);
                    day = new Day(c, getDayEventCount(vector) > 0);
                    day.setOccursInOtherMonth(true);
                    day.setBackgroundCSSProperty(getDayPriorityCSSProperty(vector));
                } else {
                    c.set(Calendar.YEAR, selYear);
                    c.set(Calendar.MONTH, selMonth);
                    c.set(Calendar.DAY_OF_MONTH, currDay++);
                    vector = getScheduleEventsForDay(c);
                    day = new Day(c, getDayEventCount(vector) > 0);
                    day.setOccursInOtherMonth(false);
                    day.setBackgroundCSSProperty(getDayPriorityCSSProperty(vector));
                }
                day.setToday(sameDay(c, getToday()));
                day.setSelected(selectedDay != null && sameDay(c, selectedDay));
                day.setDayEvents(getDayEvents(vector));
                week.setDay(i, day);

            }
            weeks.set(weekNo, week);
        }
        // remove unused weeks (5th, 6th week of month)
        while (((weeks.size() - 1) - weekNo) > 0) {
            weeks.remove(weeks.size() - 1);
        }
    }
    return weeks;
}

From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java

/**
 * Returns all displayed days of the specified month with their corresponding entries as lists.<p>
 * /*from  w  w w  . j  a v  a 2 s.c om*/
 * The key of the Map has to be a Date object.<p>
 * 
 * The Map values are always lists of {@link CmsCalendarEntry} objects, if no entries are available for a specific day,
 * an empty List is returned.<p>
 * 
 * @param year the year of the month to display
 * @param month the month to display
 * @return all displayed days of the specified day range with their corresponding entries as lists
 */
public Map getEntriesForMonth(int year, int month) {

    Calendar startDay = new GregorianCalendar(year, month, 1);
    Calendar endDay = new GregorianCalendar(year, month, startDay.getActualMaximum(Calendar.DAY_OF_MONTH));
    return getEntriesForDays(startDay, endDay);
}

From source file:net.audumla.climate.bom.BOMStatisticalClimateDataObserver.java

private void loadHistoricalData(CSVReader reader) {
    // http://www.bom.gov.au/clim_data/cdio/tables/text/IDCJCM0035_086351.csv
    try {//from w w w. j a v a2s  .com
        String[] data;
        while ((data = reader.readNext()) != null) {
            if (data.length > 0) {
                if (data[0].contains("Elevation")) {
                    Matcher m = numberPattern.matcher(data[0]);
                    if (m.find()) {
                        source.setElevation(SafeParse.parseDouble(m.group(1)));
                    }
                    continue;
                }
                if (data[0].contains("Latitude")) {
                    Matcher m = numberPattern.matcher(data[0]);
                    if (m.find()) {
                        source.setLatitude(-1 * SafeParse.parseDouble(m.group(1)));
                    }
                    continue;
                }
                if (data[0].contains("Longitude")) {
                    Matcher m = numberPattern.matcher(data[0]);
                    if (m.find()) {
                        source.setLongitude(SafeParse.parseDouble(m.group(1)));
                    }
                    continue;
                }
                if (data[0].contains("Commenced")) {
                    Matcher m = numberPattern.matcher(data[0]);
                    if (m.find()) {
                        Calendar c = Calendar.getInstance();
                        c.setTime(Time.getZeroDate());
                        c.set(Calendar.YEAR, SafeParse.parseInteger(m.group(1)));
                        source.setFirstRecord(c.getTime());
                    }
                    continue;
                }
                if (data[0].contains("Last Record")) {
                    Matcher m = numberPattern.matcher(data[0]);
                    if (m.find()) {
                        Calendar c = Calendar.getInstance();
                        c.setTime(Time.getZeroDate());
                        c.set(Calendar.YEAR, SafeParse.parseInteger(m.group(1)));
                        c.set(Calendar.DAY_OF_YEAR, c.getActualMaximum(Calendar.DAY_OF_YEAR));
                        source.setLastRecord(c.getTime());
                    }
                    continue;
                }
                if (data[0].contains("State")) {
                    Matcher m = wordPattern.matcher(data[0]);
                    if (m.find()) {
                        source.setState(m.group(1));
                    }
                    continue;
                }
                if (data[0].contains("Mean maximum temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setMaximumTemperature(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean minimum temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setMinimumTemperature(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean rainfall")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setAvgRainfall(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean number of days of rain >= 1 mm")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setRainfallDaysAbove1mm(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean daily sunshine")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setSunshineHours(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean daily solar exposure")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setSolarRadiation(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean daily evaporation")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        bomdata.setEvaporation(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean daily wind run")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        Double ws = SafeParse.parseDouble(data[i]);
                        if (ws != null) {
                            bomdata.setAverageWindSpeed(ws / 24);
                            bomdata.setWindSpeedHeight(10.0);
                        }
                        ++i;
                    }
                    continue;
                }

                /*
                      * Mean 3pm temperature (Degrees C) for years 1979 to 2002 Mean 3pm dew point temperature (Degrees C) for years 1979 to 2002 Mean 3pm
                 * relative humidity (%) for years 1979 to 2002 Mean 3pm wind speed (km/h) for years 1979 to 2002
                 */
                if (data[0].contains("Mean 3pm temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 15);
                        obs.setTemperature(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 3pm dew point temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 15);
                        obs.setDewPoint(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 3pm relative humidity")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 15);
                        obs.setHumidity(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 3pm wind speed")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 15);
                        obs.setWindSpeed(SafeParse.parseDouble(data[i]));
                        obs.setWindSpeedHeight(10.0);
                        ++i;
                    }
                    continue;
                }

                if (data[0].contains("Mean 9am temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 9);
                        obs.setTemperature(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 9am dew point temperature")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 9);
                        obs.setDewPoint(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 9am relative humidity")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 9);
                        obs.setHumidity(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
                if (data[0].contains("Mean 9am wind speed")) {
                    int i = 1;
                    for (WritableClimateData statdata : statData.values()) {
                        BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
                        WritableClimateObservation obs = getObservation(bomdata, 9);
                        obs.setWindSpeed(SafeParse.parseDouble(data[i]));
                        ++i;
                    }
                    continue;
                }
            }
        }
        for (WritableClimateData statdata : statData.values()) {
            BOMClimateStatisticalData bomdata = (BOMClimateStatisticalData) statdata;
            Calendar c = Calendar.getInstance();
            c.setTime(bomdata.getTime());
            int daysInMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH);
            bomdata.setRainfall(bomdata.getAvgRainfall() / bomdata.getRainfallDaysAbove1mm());
            bomdata.setRainfallProbability((bomdata.getRainfallDaysAbove1mm() / daysInMonth) * 100);
        }
    } catch (Exception e) {
        //e.printStackTrace();
        // logger.error("Error reading statistic data", e);
        logger.error(
                "Error loading statistic data for station - " + getSource().getId() + " : " + e.getMessage());
    }
}

From source file:com.krawler.spring.hrms.employee.hrmsEmpDAOImpl.java

public KwlReturnObject salaryGeneratedUpdates(HashMap<String, Object> requestParams) {
    Boolean success = false;//from  w ww . j  av  a2s  . c o  m
    Calendar calendar = Calendar.getInstance();
    Date date1;
    Date date2;
    List<Updates> list = new ArrayList<Updates>();
    try {
        Locale locale = null;
        if (requestParams.get("locale") != null) {
            locale = (Locale) requestParams.get("locale");
        }
        DateFormat df = (DateFormat) requestParams.get("df");
        String userid = requestParams.get("userid").toString();
        Date userdate = (Date) requestParams.get("userdate");
        String companyid = requestParams.get("companyid").toString();
        calendar.setTime(userdate);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.MONTH, -(Calendar.MONTH - 1));
        date1 = calendar.getTime();
        date1.setDate(1);
        date2 = calendar.getTime();
        date2.setDate(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        String query = "from Payhistory where userID.company.companyID=? and userID.userID=? and salarystatus=? and generatedon is not null and createdon is not null  and paycyclestart is not null and paycyclestart between ? and ?";
        List<Payhistory> recordTotalCount = HibernateUtil.executeQuery(hibernateTemplate, query,
                new Object[] { companyid, userid, 3, date1, date2 });
        Iterator<Payhistory> itr = recordTotalCount.iterator();
        while (itr.hasNext()) {
            Payhistory payhistory = itr.next();
            String updateDiv = "";
            updateDiv += messageSource.getMessage("hrms.common.Alert.salaryGeneratedUpdates",
                    new Object[] { "<font color='green'>" + df.format(payhistory.getPaycyclestart())
                            + "</font> <a href='#' onclick='viewmypayslip()'>", "</a>" },
                    "Salary is generated for month <font color='green'>"
                            + df.format(payhistory.getPaycyclestart())
                            + "</font> <a href='#' onclick='viewmypayslip()'>download</a> payslip.",
                    locale);
            list.add(new Updates(StringUtil.getContentSpan(updateDiv), payhistory.getGeneratedon()));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        success = false;
    } finally {
        return new KwlReturnObject(success, "", "", list, list.size());
    }
}

From source file:org.egov.mrs.application.reports.service.MarriageRegistrationReportsService.java

public Date getMonthEndday(final String monthyear) {
    Date monthEndDate = new Date();
    if (monthyear != null) {
        final String[] monthYear = monthyear.split("/");
        final Calendar calnew = Calendar.getInstance();
        calnew.set(Calendar.MONTH, Integer.parseInt(monthYear[0]) - 1);
        calnew.set(Calendar.YEAR, Integer.parseInt(monthYear[1]));
        calnew.set(Calendar.HOUR_OF_DAY, 23);
        calnew.set(Calendar.MINUTE, 59);
        calnew.set(Calendar.SECOND, 59);
        calnew.set(Calendar.MILLISECOND, 999);
        calnew.set(Calendar.DAY_OF_MONTH, calnew.getActualMaximum(Calendar.DAY_OF_MONTH));
        monthEndDate = calnew.getTime();

    }//from   www.  j a v  a 2 s .  c  om
    return monthEndDate;
}

From source file:com.samsistemas.calendarview.widget.CalendarView.java

/**
 * This method prepare and populate the days in the CalendarView
 *//*from  www. j a  v a 2 s  .co m*/
private void setDaysInCalendar() {
    Calendar calendar = Calendar.getInstance(getLocale());
    calendar.setTime(mCalendar.getTime());
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.setFirstDayOfWeek(mFirstDayOfWeek);
    int firstDayOfMonth = calendar.get(Calendar.DAY_OF_WEEK);

    // Calculate dayOfMonthIndex
    int dayOfMonthIndex = CalendarUtility.getWeekIndex(firstDayOfMonth, calendar);
    int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    final Calendar startCalendar = (Calendar) calendar.clone();
    //Add required number of days
    startCalendar.add(Calendar.DATE, -(dayOfMonthIndex - 1));
    int monthEndIndex = 42 - (actualMaximum + dayOfMonthIndex - 1);

    DayView dayView;
    ViewGroup dayOfMonthContainer;
    for (int i = 1; i < 43; i++) {
        dayOfMonthContainer = (ViewGroup) mView
                .findViewWithTag(mContext.getString(R.string.day_of_month_container) + i);
        dayView = (DayView) mView.findViewWithTag(mContext.getString(R.string.day_of_month_text) + i);
        if (dayView == null)
            continue;

        //Apply the default styles
        dayOfMonthContainer.setOnClickListener(null);
        dayView.bind(startCalendar.getTime(), getDecoratorsList());
        dayView.setVisibility(View.VISIBLE);

        if (null != getTypeface()) {
            dayView.setTypeface(getTypeface());
        }

        if (CalendarUtility.isSameMonth(calendar, startCalendar)) {
            dayOfMonthContainer.setOnClickListener(onDayOfMonthClickListener);
            dayOfMonthContainer.setOnLongClickListener(onDayOfMonthLongClickListener);
            dayView.setBackgroundColor(mCalendarBackgroundColor);
            mIsCommonDay = true;
            if (totalDayOfWeekend().length != 0) {
                for (int weekend : totalDayOfWeekend()) {
                    if (startCalendar.get(Calendar.DAY_OF_WEEK) == weekend) {
                        dayView.setTextColor(mWeekendColor);
                        mIsCommonDay = false;
                    }
                }
            }

            if (mIsCommonDay) {
                dayView.setTextColor(mDayOfWeekTextColor);
            }
        } else {
            dayView.setBackgroundColor(mDisabledDayBackgroundColor);
            dayView.setTextColor(mDisabledDayTextColor);

            if (!isOverflowDateVisible())
                dayView.setVisibility(View.GONE);
            else if (i >= 36 && ((float) monthEndIndex / 7.0f) >= 1) {
                dayView.setVisibility(View.GONE);
            }
        }
        dayView.decorate();

        //Set the current day color
        if (mCalendar.get(Calendar.MONTH) == startCalendar.get(Calendar.MONTH))
            setCurrentDay(mCalendar.getTime());

        startCalendar.add(Calendar.DATE, 1);
        dayOfMonthIndex++;
    }

    // If the last week row has no visible days, hide it or show it in case
    ViewGroup weekRow = (ViewGroup) mView.findViewWithTag("weekRow6");
    dayView = (DayView) mView.findViewWithTag("dayOfMonthText36");
    if (dayView.getVisibility() != VISIBLE) {
        weekRow.setVisibility(GONE);
    } else {
        weekRow.setVisibility(VISIBLE);
    }
}

From source file:org.gss_project.gss.server.ejb.GSSDAOBean.java

@Override
public void updateAccounting(User user, Date date, long bandwidthDiff) {
    AccountingInfo ai = null;//from w ww  .  j  a  v a 2 s. c  o m
    try {
        ai = (AccountingInfo) manager
                .createQuery("select ai from AccountingInfo ai "
                        + "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date")
                .setParameter("user", user).setParameter("date", date).getSingleResult();
    } catch (NoResultException e) {
        ai = null;
    }

    if (ai == null) {
        Calendar dateFrom;
        Calendar dateTo;
        Calendar thisDate = new GregorianCalendar();
        thisDate.setTime(date);
        dateFrom = (Calendar) thisDate.clone();
        dateFrom.set(Calendar.DAY_OF_MONTH, thisDate.getActualMinimum(Calendar.DAY_OF_MONTH));
        dateFrom.set(Calendar.HOUR_OF_DAY, thisDate.getActualMinimum(Calendar.HOUR_OF_DAY));
        dateFrom.set(Calendar.MINUTE, thisDate.getActualMinimum(Calendar.MINUTE));
        dateFrom.set(Calendar.SECOND, thisDate.getActualMinimum(Calendar.SECOND));
        dateFrom.set(Calendar.MILLISECOND, thisDate.getActualMinimum(Calendar.MILLISECOND));

        dateTo = (Calendar) thisDate.clone();
        dateTo.set(Calendar.DAY_OF_MONTH, thisDate.getActualMaximum(Calendar.DAY_OF_MONTH));
        dateTo.set(Calendar.HOUR_OF_DAY, thisDate.getActualMaximum(Calendar.HOUR_OF_DAY));
        dateTo.set(Calendar.MINUTE, thisDate.getActualMaximum(Calendar.MINUTE));
        dateTo.set(Calendar.SECOND, thisDate.getActualMaximum(Calendar.SECOND));
        dateTo.set(Calendar.MILLISECOND, thisDate.getActualMaximum(Calendar.MILLISECOND));

        ai = new AccountingInfo(user, dateFrom.getTime(), dateTo.getTime());
        manager.persist(ai);
    }

    // Do the update.
    ai.updateBandwidth(bandwidthDiff);
}