List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:com.discovery.darchrow.date.DateUtil.java
/** * <span style="color:red">?</span> <code>23:59:59.999</code> . * <p>/* w ww . ja v a 2s.c o m*/ * ?,,2 2829 * </p> * * <pre> * 2012-10-11 17:10:30.701, * return 2012-10-31 23:59:59.999 * </pre> * * @param date * the date * @return Date * @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)); CalendarUtil.resetDayEnd(calendar); return CalendarUtil.toDate(calendar); }
From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java
public Calendar[] getCurrentMonthPeriod(TimeZone zone, Locale locale) { Calendar monthStart = GregorianCalendar.getInstance(zone, locale); Calendar monthEnd = GregorianCalendar.getInstance(zone, locale); monthStart.set(Calendar.DAY_OF_MONTH, 1); int daysInCurrentMonth = monthEnd.getActualMaximum(Calendar.DAY_OF_MONTH); monthEnd.set(Calendar.DAY_OF_MONTH, daysInCurrentMonth); setCalendarToStartOfDay(monthStart); setCalendarToEndOfDay(monthEnd);//w w w . ja v a2s.c o m Calendar[] period = { monthStart, monthEnd }; return period; }
From source file:com.nabla.dc.server.xml.settings.XmlCompany.java
public boolean save(final Connection conn, final Map<String, Integer> companyIds, final SaveContext ctx) throws SQLException, DispatchException { Integer companyId = companyIds.get(getName()); if (companyId != null) { if (ctx.getOption() == SqlInsertOptions.APPEND) return true; Database.executeUpdate(conn, "UPDATE company SET active=? WHERE id=?;", active, companyId); Database.executeUpdate(conn, "DELETE FROM financial_year WHERE company_id=?;", companyId); if (accounts != null) { if (log.isDebugEnabled()) log.debug("deleting all accounts of company '" + getName() + "'"); accounts.clear(conn, companyId); }/*www .j a v a2s. co m*/ if (asset_categories != null) asset_categories.clear(conn, companyId); if (users != null) users.clear(conn, companyId); } else { companyId = Database.addRecord(conn, "INSERT INTO company (name,uname,active) VALUES(?,?,?);", getName(), getName().toUpperCase(), active); if (companyId == null) throw new InternalErrorException(Util.formatInternalErrorDescription("failed to insert company")); companyIds.put(getName(), companyId); } final Integer financialYearId = Database.addRecord(conn, "INSERT INTO financial_year (company_id, name) VALUES(?,?);", companyId, financial_year); final PreparedStatement stmt = conn .prepareStatement("INSERT INTO period_end (financial_year_id,name,end_date) VALUES(?,?,?);"); try { stmt.setInt(1, financialYearId); final Calendar dt = new GregorianCalendar(); dt.setTime(start_date); final SimpleDateFormat financialYearFormat = new SimpleDateFormat("MMM yyyy"); for (int m = 0; m < 12; ++m) { dt.set(GregorianCalendar.DAY_OF_MONTH, dt.getActualMaximum(GregorianCalendar.DAY_OF_MONTH)); final Date end = new Date(dt.getTime().getTime()); stmt.setString(2, financialYearFormat.format(end)); stmt.setDate(3, end); stmt.addBatch(); dt.add(GregorianCalendar.MONTH, 1); } if (!Database.isBatchCompleted(stmt.executeBatch())) throw new InternalErrorException(Util .formatInternalErrorDescription("fail to insert periods for company '" + getName() + "'")); } finally { stmt.close(); } if (accounts != null) accounts.save(conn, companyId); return (asset_categories == null || asset_categories.save(conn, companyId, ctx)) && (users == null || users.save(conn, companyId, ctx)); }
From source file:com.persistent.cloudninja.service.impl.MeteringTotalsDataServiceImpl.java
/** * For the given year and month this method returns the number of days * @param month//from ww w . ja v a 2 s . c o m * @param year * @return the number of days in month */ private int getDaysInMonth(String month, String year) { String date = month + "/" + 1 + "/" + year; SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); Date calDate = null; Calendar calendar = Calendar.getInstance(); try { calDate = formatter.parse(date); } catch (ParseException e) { e.printStackTrace(); } calendar.setTime(calDate); // Get number of days in the given month int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return (daysInMonth); }
From source file:com.health.openscale.gui.GraphFragment.java
private void generateLineData(Calendar calMonth) { scaleDataList = openScale.getScaleDataOfMonth(calYears.get(Calendar.YEAR), calMonth.get(Calendar.MONTH)); float maxValue = openScale.getMaxValueOfScaleData(calYears.get(Calendar.YEAR), calMonth.get(Calendar.MONTH)); SimpleDateFormat day_date = new SimpleDateFormat("dd", Locale.getDefault()); Calendar calDays = (Calendar) calMonth.clone(); calDays.set(Calendar.DAY_OF_MONTH, 1); int maxDays = calDays.getActualMaximum(Calendar.DAY_OF_MONTH); List<AxisValue> axisValues = new ArrayList<AxisValue>(); for (int i = 0; i < maxDays; i++) { String day_name = day_date.format(calDays.getTime()); axisValues.add(new AxisValue(i, day_name.toCharArray())); calDays.add(Calendar.DAY_OF_MONTH, 1); }/* w w w . j ava 2 s. c o m*/ List<PointValue> valuesWeight = new ArrayList<PointValue>(); List<PointValue> valuesFat = new ArrayList<PointValue>(); List<PointValue> valuesWater = new ArrayList<PointValue>(); List<PointValue> valuesMuscle = new ArrayList<PointValue>(); List<Line> lines = new ArrayList<Line>(); Calendar calDB = Calendar.getInstance(); for (ScaleData scaleEntry : scaleDataList) { calDB.setTime(scaleEntry.date_time); valuesWeight.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.weight)); valuesFat.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.fat)); valuesWater.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.water)); valuesMuscle.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.muscle)); } Line lineWeight = new Line(valuesWeight).setColor(Utils.COLOR_VIOLET).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineFat = new Line(valuesFat).setColor(Utils.COLOR_ORANGE).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineWater = new Line(valuesWater).setColor(Utils.COLOR_BLUE).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineMuscle = new Line(valuesMuscle).setColor(Utils.COLOR_GREEN).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); activeLines = new ArrayList<lines>(); if (prefs.getBoolean("weightEnable", true)) { lines.add(lineWeight); activeLines.add(GraphFragment.lines.WEIGHT); } if (prefs.getBoolean("fatEnable", true)) { lines.add(lineFat); activeLines.add(GraphFragment.lines.FAT); } if (prefs.getBoolean("waterEnable", true)) { lines.add(lineWater); activeLines.add(GraphFragment.lines.WATER); } if (prefs.getBoolean("muscleEnable", true)) { lines.add(lineMuscle); activeLines.add(GraphFragment.lines.MUSCLE); } LineChartData lineData = new LineChartData(lines); lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(Color.BLACK)); lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3).setTextColor(Color.BLACK)); chartTop.setLineChartData(lineData); chartTop.setViewportCalculationEnabled(false); if (maxValue == 0.0) { maxValue = 100; } else { maxValue += 20; } Viewport v = new Viewport(0, (int) maxValue, maxDays - 1, 0); chartTop.setMaximumViewport(v); chartTop.setCurrentViewport(v, true); chartTop.setZoomType(ZoomType.HORIZONTAL); }
From source file:org.easyrec.controller.StatisticsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { if (Security.isSignedIn(request)) { int tenant; int month; int year; boolean flot; String actionType = request.getParameter("actionType"); try {//from w ww. j av a2 s .com tenant = Integer.parseInt(request.getParameter("tenant")); month = Integer.parseInt(request.getParameter("month")); year = Integer.parseInt(request.getParameter("year")); flot = Integer.parseInt(request.getParameter("flot")) != 0; } catch (Exception e) { logger.warn(e); return null; } ModelAndView mav = new ModelAndView(); XYSeriesCollection dataset = new XYSeriesCollection(); FlotDataSet flotDataSet = new FlotDataSet(); Calendar from = Calendar.getInstance(); Calendar to = Calendar.getInstance(); from.set(year, month, Calendar.getInstance().getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0, 0); to.set(year, month, from.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); Integer actionTypeId = null; Integer assocTypeId = null; if (!Strings.isNullOrEmpty(actionType)) { if ("CLICKS_ON_RECS".equals(actionType)) assocTypeId = 1001; else if ("CLICKS_ON_CHARTS".equals(actionType)) assocTypeId = 998; else actionTypeId = typeMappingService.getIdOfActionType(tenant, actionType); } HashMap<Integer, HashMap<Integer, Integer>> actionBundleMap = statisticsDAO.getActionBundleMap(tenant, from.getTimeInMillis(), to.getTimeInMillis(), actionTypeId, assocTypeId); Iterator<Integer> iterator = actionBundleMap.keySet().iterator(); while (iterator.hasNext()) { actionTypeId = iterator.next(); if (actionTypeId == 1001) actionType = "clicks on recommendations"; else if (actionTypeId == 998) actionType = "clicks on rankings"; else actionType = typeMappingService.getActionTypeById(tenant, actionTypeId).toLowerCase() + " actions"; XYSeries xySeries = new XYSeries(actionType); FlotSeries flotSeries = new FlotSeries(); flotSeries.setTitle(actionType); for (int i = 1; i <= 31; i++) { Integer y = actionBundleMap.get(actionTypeId).get(i); xySeries.add(i, y != null ? y : 0); flotSeries.add(i, y != null ? y : 0); } //mav.addObject("data",flotDataSet.toString()); dataset.addSeries(xySeries); flotDataSet.add(flotSeries); } // create datapoints that are rendered in the clients browser // return array or html side that renders array if (flot) { boolean onlyData = (ServletUtils.getSafeParameter(request, "onlyData", 0) != 0); if (onlyData) { mav.setViewName("flot/dataOutput"); } else { mav.setViewName("flot/flotPlot"); } mav.addObject("data", flotDataSet.toString()); mav.addObject("flotDataSet", flotDataSet.getData()); mav.addObject("noActions", flotDataSet.getData().isEmpty()); return mav; // create a png } else { JFreeChart action_chart = ChartFactory.createXYLineChart("", "actions", "days", dataset, PlotOrientation.VERTICAL, true, // show legend true, // show tooltips false); // show urls XYPlot plot = action_chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setRange(1, 31); plot.setDomainAxis(axis); BufferedImage bi = action_chart.createBufferedImage(300, 200); byte[] bytes = ChartUtilities.encodeAsPNG(bi); if (bytes != null & !flot) { OutputStream os = response.getOutputStream(); response.setContentType("image/png"); response.setContentLength(bytes.length); os.write(bytes); os.close(); } } return null; } else { return Security.redirectHome(request, response); } }
From source file:de.tor.tribes.ui.components.DatePicker.java
public void buildCalendar() { jLabelMonth.setText(monthAndYear.format(selectedDate)); Calendar temp = new GregorianCalendar(); temp.setTime(selectedDate);/*from ww w .j a v a 2 s .c om*/ int maxDaysInMonth = temp.getActualMaximum(Calendar.DAY_OF_MONTH); int firstdayInMonth = temp.getActualMinimum(Calendar.DAY_OF_MONTH); temp.set(Calendar.DAY_OF_MONTH, firstdayInMonth); int dayOfWeek = mapDayOfWeek(temp.get(Calendar.DAY_OF_WEEK)); int currentField = 0; //ensure that at least one day of prev month is shown int preDaysToAdd = ((dayOfWeek + 5) % 7) + 1; temp.add(Calendar.MONTH, -1); temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH) - preDaysToAdd + 1); for (; currentField < preDaysToAdd; currentField++) { //days belong to last month CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(LIGHT_GRAY); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } //normal days of month for (int i = firstdayInMonth; i <= maxDaysInMonth; i++, currentField++) { CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(BLACK); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } //post days of month for (; currentField < WEEKS_TO_SHOW * 7; currentField++) { CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(LIGHT_GRAY); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } for (int i = 0; i < WEEKS_TO_SHOW * 7; i++) { if (selectedDate.equals(datesInMonth[i / 7][i % 7])) { daysInMonth[i / 7][i % 7].cross(); } else { daysInMonth[i / 7][i % 7].uncross(); } } }
From source file:jef.tools.DateUtils.java
/** * ?/*w w w. ja v a2s . c o m*/ * * @param date * @return 22829131 */ public static final int getDaysInMonth(Date date) { Assert.notNull(date); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); return day; }
From source file:jef.tools.DateUtils.java
/** * ?//from w w w . ja v a2 s . co m * * @param date * @return ? */ public static final Date lastDayOfMonth(Date date) { if (date == null) return null; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// ? calendar = org.apache.commons.lang.time.DateUtils.truncate(calendar, Calendar.DATE);// return calendar.getTime(); }
From source file:jef.tools.DateUtils.java
/** * ?// w ww . ja v a2 s. c o m * * @param date * @return ?1 */ public static final Date monthEnd(Date date) { if (date == null) return null; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// ? calendar = org.apache.commons.lang.time.DateUtils.truncate(calendar, Calendar.DATE);// Date d = calendar.getTime(); d.setTime(d.getTime() + MILLISECONDS_IN_DAY - 1); // ?1 return d; }