List of usage examples for java.util Calendar getActualMinimum
public int getActualMinimum(int field)
Calendar
. From source file:org.richfaces.renderkit.CalendarRendererBase.java
protected Map<String, String[]> getSymbolsMap(FacesContext facesContext, UICalendar calendar) { Map<String, String[]> map = new HashMap<String, String[]>(); Locale locale = calendar.getAsLocale(calendar.getLocale()); Calendar cal = calendar.getCalendar(); int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK); int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK); int monthMax = cal.getActualMaximum(Calendar.MONTH); int monthMin = cal.getActualMinimum(Calendar.MONTH); DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels()); if (weekDayLabels == null) { weekDayLabels = symbols.getWeekdays(); weekDayLabels = shiftDates(minimum, maximum, weekDayLabels); }// w w w. java 2 s . c om String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort()); if (weekDayLabelsShort == null) { weekDayLabelsShort = symbols.getShortWeekdays(); weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort); } String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels()); if (monthLabels == null) { monthLabels = symbols.getMonths(); monthLabels = shiftDates(monthMin, monthMax, monthLabels); } String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort()); if (monthLabelsShort == null) { monthLabelsShort = symbols.getShortMonths(); monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort); } map.put(WEEK_DAY_LABELS, weekDayLabels); map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort); map.put(MONTH_LABELS, monthLabels); map.put(MONTH_LABELS_SHORT, monthLabelsShort); return map; }
From source file:org.richfaces.component.UICalendar.java
protected int getDefaultFirstWeekDay() { Calendar cal = getCalendar(); return cal.getFirstDayOfWeek() - cal.getActualMinimum(Calendar.DAY_OF_WEEK); }
From source file:it.scoppelletti.mobilepower.types.SimpleDate.java
/** * Costruttore.// w w w .j a v a 2s. c o m * * @param year Anno. * @param month Mese. * @param day Giorno. */ public SimpleDate(int year, int month, int day) { int min, max; Calendar cal = Calendar.getInstance(); min = cal.getMinimum(Calendar.YEAR); max = cal.getMaximum(Calendar.YEAR); if (year < min || year > max) { throw new IllegalArgumentException( String.format("Argument year %1$d is ouf of range [%2$d, %3$d].", year, min, max)); } cal.set(Calendar.YEAR, year); min = cal.getActualMinimum(Calendar.MONTH); max = cal.getActualMaximum(Calendar.MONTH); if (month < min || month > max) { throw new IllegalArgumentException( String.format("Argument month %1$d is ouf of range [%2$d, %3$d].", month, min, max)); } cal.set(Calendar.MONTH, month); min = cal.getActualMinimum(Calendar.DAY_OF_MONTH); max = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (day < min || day > max) { throw new IllegalArgumentException( String.format("Argument day %1$d is ouf of range [%2$d, %3$d].", day, min, max)); } myYear = year; myMonth = month; myDay = day; }
From source file:com.mss.msp.util.DateUtility.java
public String FirstDateOfLastMonth() throws ParseException { Calendar cal = Calendar.getInstance(); int cur_year = cal.get(Calendar.YEAR); int cur_month = cal.get(Calendar.MONTH); int last_month = cur_month - 1; cal.set(cur_year, last_month, 1);/*from w w w . j a v a 2 s .c o m*/ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); String lastDate = sdf.format(cal.getTime()); return lastDate; }
From source file:org.richfaces.component.UICalendar.java
protected Date getDefaultPreloadBegin(Date date) { Calendar calendar = Calendar.getInstance(getTimeZone(), getAsLocale(getLocale())); calendar.setTime(date);//from w w w.j a v a 2s . c om calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); /* * //force recalculation calendar.getTimeInMillis(); * calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); */ return calendar.getTime(); }
From source file:com.silverpeas.scheduler.simple.SchedulerJob.java
/** * The constructor has proteceted access, because the generation of jobs should be done in a * central way by the class 'SimpleScheduler' * @param aController The controller, that controls all job executions * @param aOwner The owner of the job/*from w ww. j ava 2 s . c o m*/ * @param aJobName The name of the job * @param aLogBaseFile The log file for the job */ protected SchedulerJob(SimpleScheduler aController, SchedulerEventListener aOwner, String aJobName) throws SchedulerException { if (aController == null) { throw new SchedulerException("SchedulerJob.SchedulerJob: Parameter 'aController' is null"); } if (aOwner == null) { throw new SchedulerException("SchedulerJob.SchedulerJob: Parameter 'aOwner' is null"); } if (aJobName == null) { throw new SchedulerException("SchedulerJob.SchedulerJob: Parameter 'aJobName' is null"); } theOwner = aOwner; sJobName = aJobName; vMinutes = new ArrayList<Integer>(); vHours = new ArrayList<Integer>(); vDaysOfMonth = new ArrayList<Integer>(); vMonths = new ArrayList<Integer>(); vDaysOfWeek = new ArrayList<Integer>(); // Instead Calendar calInit = Calendar.getInstance(); currentMinute = 0; currentHour = 0; if (calInit.getActualMinimum(Calendar.DAY_OF_MONTH) == calInit.get(Calendar.DAY_OF_MONTH)) { currentDayOfMonth = calInit.getActualMaximum(Calendar.DAY_OF_MONTH); if (calInit.getActualMinimum(Calendar.MONTH) == calInit.get(Calendar.MONTH)) { currentMonth = calInit.getActualMaximum(Calendar.MONTH); currentYear = calInit.get(Calendar.YEAR) - 1; } else { currentMonth = calInit.get(Calendar.MONTH) - 1; currentYear = calInit.get(Calendar.YEAR); } } else { currentDayOfMonth = calInit.get(Calendar.DAY_OF_MONTH) - 1; currentMonth = calInit.get(Calendar.MONTH); currentYear = calInit.get(Calendar.YEAR); } if (calInit.getActualMinimum(Calendar.MONTH) == currentMonth) { currentMonth = calInit.getActualMaximum(Calendar.MONTH); currentYear = currentYear - 1; } else { currentMonth = currentMonth - 1; } nextTimeStamp = 0; bRunnable = true; }
From source file:org.gss_project.gss.server.ejb.GSSDAOBean.java
@Override public void updateAccounting(User user, Date date, long bandwidthDiff) { AccountingInfo ai = null;/*w w w.j ava 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); }
From source file:stg.utils.immutable.Day.java
/** * Returns the minimum value for the given field. * //from ww w .j a v a2 s .c om * @param field * Calendar constants for fields. * @return int minimum value for the given field. */ public int getMinimum(int field) { Calendar calendar = getCalendar(); return calendar.getActualMinimum(field); }
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 w w .ja va 2 s .co 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:org.kuali.mobility.events.controllers.CalendarController.java
@RequestMapping(value = "/month", method = RequestMethod.GET) public String month(HttpServletRequest request, Model uiModel, @RequestParam(required = false) String date) { User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat my = new SimpleDateFormat("yyyyMM"); Calendar selectedDate = Calendar.getInstance(); try {// w w w. ja v a 2 s . c o m if (date != null) { selectedDate.setTime(my.parse(date)); } } catch (ParseException e) { } try { Filter filter = (Filter) request.getSession().getAttribute("calendar.event.filterId"); MonthViewEvents monthEvents = calendarEventOAuthService.retrieveMonthEvents(user.getUserId(), selectedDate.getTime(), filter != null ? filter.getFilterId() : null); uiModel.addAttribute("viewData", monthEvents.getViewData()); uiModel.addAttribute("appData", monthEvents.getAppData()); int days = selectedDate.getActualMaximum(Calendar.DATE); Calendar startDate = (Calendar) selectedDate.clone(); startDate.set(Calendar.DATE, selectedDate.getActualMinimum(Calendar.DATE)); days += startDate.get(Calendar.DAY_OF_WEEK) - 1; Calendar endDate = (Calendar) selectedDate.clone(); endDate.set(Calendar.DATE, selectedDate.getActualMaximum(Calendar.DATE)); days += 7 - endDate.get(Calendar.DAY_OF_WEEK); startDate.set(Calendar.DAY_OF_WEEK, 1); Map<String, MobileDayOfMonth> daysInMonth = new LinkedHashMap<String, MobileDayOfMonth>(); uiModel.addAttribute("selectedDate", sdf.format(selectedDate.getTime())); for (int i = 0; i < days; i++) { MobileDayOfMonth mobileDayOfMonth = new MobileDayOfMonth(startDate.get(Calendar.DATE)); mobileDayOfMonth.setCurrentMonth(startDate.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH)); if (!mobileDayOfMonth.isCurrentMonth()) { mobileDayOfMonth.setBeforeCurrentMonth( startDate.get(Calendar.MONTH) < selectedDate.get(Calendar.MONTH)); } mobileDayOfMonth.setMonthYear(my.format(startDate.getTime())); mobileDayOfMonth.setDayOfWeek(startDate.get(Calendar.DAY_OF_WEEK)); daysInMonth.put(sdf.format(startDate.getTime()), mobileDayOfMonth); startDate.add(Calendar.DATE, 1); } for (Iterator iterator = monthEvents.getEvents().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, List<CalendarViewEvent>> entry = (Map.Entry<String, List<CalendarViewEvent>>) iterator .next(); MobileDayOfMonth dayInMonth = daysInMonth.get(entry.getKey()); dayInMonth.setHasEvents(true); dayInMonth.setEvents(entry.getValue()); } uiModel.addAttribute("events", daysInMonth); Calendar previousCalendar = (Calendar) selectedDate.clone(); previousCalendar.set(Calendar.DATE, 1); previousCalendar.getTime(); previousCalendar.add(Calendar.MONTH, -1); Calendar nextCalendar = (Calendar) selectedDate.clone(); nextCalendar.set(Calendar.DATE, 1); nextCalendar.getTime(); nextCalendar.add(Calendar.MONTH, 1); uiModel.addAttribute("previousMonth", my.format(previousCalendar.getTime())); uiModel.addAttribute("nextMonth", my.format(nextCalendar.getTime())); uiModel.addAttribute("monthYear", my.format(selectedDate.getTime())); uiModel.addAttribute("today", sdf.format(new Date())); uiModel.addAttribute("filter", filter); } catch (PageLevelException pageLevelException) { uiModel.addAttribute("message", pageLevelException.getMessage()); return "calendar/message"; } return "calendar/month"; }