List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:it.scoppelletti.mobilepower.types.SimpleDate.java
/** * Restituisce la data corrispondente ad un codice giorno. * /*from w w w .jav a 2 s .co m*/ * @param dayCode Codice giorno. * @return Data. * @see #calcDayCode */ public static SimpleDate fromDayCode(long dayCode) { int year, month, day, delta, monthDays; Calendar cal; if (dayCode < 0) { throw new IllegalArgumentException("Argument dayCode is less than 0."); } if (dayCode == 0) { return SimpleDate.NIL; } // Calcolo l'anno year al quale appartiene la data ricercata per // approssimazioni successive basate sul concetto di codice anno: dato // infatti un numero di giorni, il minimo numero di anni che // intercorrono in quel periodo e' il rapporto tra quel numero di giorni // e 366 (durata massima in giorni di un anno). cal = Calendar.getInstance(); year = (int) (dayCode / 366l); while (true) { delta = (int) (dayCode - SimpleDate.calcYearCode(year)); if (delta < 366) { break; } year = year + delta / 366; } if (delta == 0) { // Definizione di codice anno year--; cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, Calendar.DECEMBER); day = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return new SimpleDate(year, Calendar.DECEMBER, day); } // delta corrisponde al numero progressivo del giorno ricercato // nell'anno: // Sottraendo progressivamente la durata in giorni dei mesi, si // determina il numero progressivo del mese nell'anno; il residuo finale // corrisponde al numero progressivo del giorno nel mese. cal.set(Calendar.YEAR, year); day = 0; // avoid warning for (month = 0; delta > 0; month++) { cal.set(Calendar.MONTH, month); monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH); if (delta <= monthDays) { day = delta; break; } delta = delta - monthDays; } return new SimpleDate(year, month, day); }
From source file:net.groupbuy.controller.admin.PurchaseRankingController.java
/** * /*w w w . ja v a 2 s. c o m*/ */ @RequestMapping(value = "/list", method = RequestMethod.GET) public String list(Date beginDate, Date endDate, Integer count, Model model) { if (beginDate != null) { Calendar calendar = DateUtils.toCalendar(beginDate); 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)); beginDate = calendar.getTime(); } if (endDate != null) { Calendar calendar = DateUtils.toCalendar(endDate); 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)); endDate = calendar.getTime(); } if (count == null || count <= 0) { count = DEFAULT_COUNT; } model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); model.addAttribute("count", count); model.addAttribute("data", memberService.findPurchaseList(beginDate, endDate, count)); return "/admin/purchase_ranking/list"; }
From source file:net.groupbuy.controller.admin.SalesRankingController.java
/** * /*from w w w . ja v a 2s. co m*/ */ @RequestMapping(value = "/list", method = RequestMethod.GET) public String list(Date beginDate, Date endDate, Integer count, Model model) { if (beginDate != null) { Calendar calendar = DateUtils.toCalendar(beginDate); 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)); beginDate = calendar.getTime(); } if (endDate != null) { Calendar calendar = DateUtils.toCalendar(endDate); 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)); endDate = calendar.getTime(); } if (count == null || count <= 0) { count = DEFAULT_COUNT; } model.addAttribute("beginDate", beginDate); model.addAttribute("endDate", endDate); model.addAttribute("count", count); model.addAttribute("data", productService.findSalesList(beginDate, endDate, count)); return "/admin/sales_ranking/list"; }
From source file:org.projectforge.web.calendar.TimesheetEventsProvider.java
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, * org.joda.time.DateTime)//ww w .j a v a2 s . c o m */ @Override protected void buildEvents(final DateTime start, final DateTime end) { totalDuration = 0; for (int i = 0; i < durationsPerDayOfMonth.length; i++) { durationsPerDayOfMonth[i] = 0; } for (int i = 0; i < durationsPerDayOfYear.length; i++) { durationsPerDayOfYear[i] = 0; } final Integer userId = calFilter.getTimesheetUserId(); if (userId == null) { return; } breaksMap = new HashMap<String, TimesheetDO>(); int breaksCounter = 0; final TimesheetFilter filter = new TimesheetFilter(); filter.setUserId(userId); filter.setStartTime(start.toDate()); filter.setStopTime(end.toDate()); filter.setOrderType(OrderDirection.ASC); timesheets = timesheetDao.getList(filter); boolean longFormat = false; days = Days.daysBetween(start, end).getDays(); if (days < 10) { // Week or day view: longFormat = true; month = null; firstDayOfMonth = null; } else { // Month view: final DateTime currentMonth = new DateTime(start.plusDays(10), ThreadLocalUserContext.getDateTimeZone()); // Now we're definitely in the right // month. month = currentMonth.getMonthOfYear(); firstDayOfMonth = currentMonth.withDayOfMonth(1); } if (CollectionUtils.isEmpty(timesheets) == false) { DateTime lastStopTime = null; for (final TimesheetDO timesheet : timesheets) { final DateTime startTime = new DateTime(timesheet.getStartTime(), ThreadLocalUserContext.getDateTimeZone()); final DateTime stopTime = new DateTime(timesheet.getStopTime(), ThreadLocalUserContext.getDateTimeZone()); if (stopTime.isBefore(start) == true || startTime.isAfter(end) == true) { // Time sheet doesn't match time period start - end. continue; } if (calFilter.isShowBreaks() == true) { if (lastStopTime != null && DateHelper.isSameDay(stopTime, lastStopTime) == true && startTime.getMillis() - lastStopTime.getMillis() > 60000) { // Show breaks between time sheets of one day (> 60s). final Event breakEvent = new Event(); breakEvent.setEditable(false); final String breakId = String.valueOf(++breaksCounter); breakEvent.setClassName(Const.BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime) .setEnd(startTime).setTitle(getString("timesheet.break")); breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9"); events.put(breakId, breakEvent); final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate()) .setStopTime(startTime.getMillis()); breaksMap.put(breakId, breakTimesheet); } lastStopTime = stopTime; } final long duration = timesheet.getDuration(); final MyWicketEvent event = new MyWicketEvent(); final String id = "" + timesheet.getId(); event.setClassName(Const.EVENT_CLASS_NAME); event.setId(id); event.setStart(startTime); event.setEnd(stopTime); final String title = CalendarHelper.getTitle(timesheet); if (longFormat == true) { // Week or day view: event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false)); } else { // Month view: event.setTitle(title); } if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) { // Display time sheets of other month as grey blue: event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8"); } events.put(id, event); if (month == null || startTime.getMonthOfYear() == month) { totalDuration += duration; addDurationOfDay(startTime.getDayOfMonth(), duration); } final int dayOfYear = startTime.getDayOfYear(); addDurationOfDayOfYear(dayOfYear, duration); event.setTooltip(getString("timesheet"), new String[][] { { title }, { timesheet.getLocation(), getString("timesheet.location") }, { KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2") }, { TaskFormatter.getTaskPath(timesheet.getTaskId(), true, OutputType.PLAIN), getString("task") }, { timesheet.getDescription(), getString("description") } }); } } if (calFilter.isShowStatistics() == true) { // Show statistics: duration of every day is shown as all day event. DateTime day = start; final Calendar cal = DateHelper.getCalendar(); cal.setTime(start.toDate()); final int numberOfDaysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR); int paranoiaCounter = 0; do { if (++paranoiaCounter > 1000) { log.error( "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents."); break; } final int dayOfYear = day.getDayOfYear(); final long duration = durationsPerDayOfYear[dayOfYear]; final boolean firstDayOfWeek = day.getDayOfWeek() == ThreadLocalUserContext.getJodaFirstDayOfWeek(); if (firstDayOfWeek == false && duration == 0) { day = day.plusDays(1); continue; } final Event event = new Event().setAllDay(true); final String id = "s-" + (dayOfYear); event.setId(id); event.setStart(day); final String durationString = formatDuration(duration, false); if (firstDayOfWeek == true) { // Show week of year at top of first day of week. long weekDuration = 0; for (short i = 0; i < 7; i++) { int d = dayOfYear + i; if (d > numberOfDaysInYear) { d -= numberOfDaysInYear; } weekDuration += durationsPerDayOfYear[d]; } final StringBuffer buf = new StringBuffer(); buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day)); if (days > 1 && weekDuration > 0) { // Show total sum of durations over all time sheets of current week (only in week and month view). buf.append(": ").append(formatDuration(weekDuration, false)); } if (duration > 0) { buf.append(", ").append(durationString); } event.setTitle(buf.toString()); } else { event.setTitle(durationString); } event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9"); event.setEditable(false); events.put(id, event); day = day.plusDays(1); } while (day.isAfter(end) == false); } }
From source file:com.feilong.core.date.DateUtilTest.java
/** * Test1.// w w w . j a v a 2 s. c o m */ @Test public void test1() { Calendar calendar = DateUtil.toCalendar(TESTDATE_20141231013024); LOGGER.debug(calendar.getActualMaximum(Calendar.SECOND) + ""); LOGGER.debug(calendar.getTimeInMillis() + ""); LOGGER.debug(calendar.hashCode() + ""); LOGGER.debug(DateUtil.getDayOfMonth(NOW) + ""); }
From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java
/** * Check if converted time to the time zone of user is the previous day, * the same day or next day. // ww w. j a v a 2 s . c o m * @param startTime denotes the time set by user (in his own TimeZone) * @return if converted from stored time zone to user time zone get the previous day returns -1 * if converted from stored time zone to user time zone get the same day returns 0 * if converted from stored time zone to user time zone get the next day returns +1 */ private static final int shiftDay(String str) { if (StringUtils.trimToNull(str) == null) { return 0; } try { SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_LONG); sdf.parse(str); return 0; } catch (Exception e) { // Stored in other format, with date and time zone. try { SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ); Calendar src = new GregorianCalendar(); src.setTime(sdf.parse(str)); TimeZone srcTz = sdf.getTimeZone(); TimeZone userTz = timeService.getLocalTimeZone(); Calendar user = new GregorianCalendar(userTz); src.set(Calendar.DAY_OF_MONTH, user.get(Calendar.DAY_OF_MONTH)); src.set(Calendar.YEAR, user.get(Calendar.YEAR)); src.set(Calendar.MONTH, user.get(Calendar.MONTH)); user.setTimeInMillis(src.getTimeInMillis()); src.setTimeZone(srcTz); int shift = user.get(Calendar.DAY_OF_MONTH) - src.get(Calendar.DAY_OF_MONTH); // Days from two differents months if (shift > 8) { src.add(Calendar.MONTH, -1); shift -= src.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); } else if (shift < -8) { user.add(Calendar.MONTH, -1); shift += user.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); } return shift; } catch (Exception ex) { if (log.isDebugEnabled()) log.debug("Unable to parse " + str); return 0; } } }
From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataFormEntryOverviewController.java
@RequestMapping("/module/facilitydata/formEntryOverview.form") public void formEntryOverview(ModelMap map, @RequestParam(required = true) FacilityDataForm form, @RequestParam(required = false) Integer yearIncrement, @RequestParam(required = false) Integer monthIncrement) throws Exception { FacilityDataService service = Context.getService(FacilityDataService.class); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1);/*from w w w .j a v a2 s. c o m*/ if (yearIncrement != null) { cal.add(Calendar.YEAR, yearIncrement); } if (monthIncrement != null) { cal.add(Calendar.DATE, monthIncrement * 21); } if (form.getFrequency() == Frequency.MONTHLY) { cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); } Date endDate = cal.getTime(); if (form.getFrequency() == Frequency.MONTHLY) { // For monthly reports, display last year cal.set(Calendar.DATE, 1); cal.add(Calendar.YEAR, -1); } else if (form.getFrequency() == Frequency.DAILY) { // For daily reports, display last 3 weeks cal.add(Calendar.DATE, -21); } else { throw new RuntimeException("Unable to handle a report with frequency: " + form.getFrequency()); } Date startDate = cal.getTime(); Map<Integer, Map<String, Integer>> questionsAnswered = service.getNumberOfQuestionsAnswered(form, startDate, endDate); DateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat monthFormat = new SimpleDateFormat("MMM"); List<Integer> daysOfWeekSupported = FacilityDataConstants.getDailyReportDaysOfWeek(); Map<Integer, Integer> yearCols = new LinkedHashMap<Integer, Integer>(); // Year -> Number of columns Map<String, Integer> monthCols = new LinkedHashMap<String, Integer>(); // Month -> Number of columns Map<String, Date> dayCols = new LinkedHashMap<String, Date>(); Map<Integer, Map<String, Integer>> dayData = new HashMap<Integer, Map<String, Integer>>(); // LocationId -> Day -> Number of questions Map<Object, String> displayKeys = new HashMap<Object, String>(); // Map key -> Display format Set<String> datesSupported = new HashSet<String>(); // Dates support entry while (cal.getTime().before(endDate)) { String dateStr = ymdFormat.format(cal.getTime()); Integer year = cal.get(Calendar.YEAR); String month = monthFormat.format(cal.getTime()); Integer day = cal.get(Calendar.DAY_OF_MONTH); yearCols.put(year, yearCols.get(year) == null ? 1 : yearCols.get(year) + 1); monthCols.put(year + month, monthCols.get(year + month) == null ? 1 : monthCols.get(year + month) + 1); dayCols.put(dateStr, cal.getTime()); if (form.getFrequency() == Frequency.MONTHLY || daysOfWeekSupported.contains(cal.get(Calendar.DAY_OF_WEEK))) { datesSupported.add(dateStr); } for (Integer locationId : questionsAnswered.keySet()) { Map<String, Integer> questionsAnsweredAtLocation = questionsAnswered.get(locationId); Integer numAnswered = questionsAnsweredAtLocation == null ? null : questionsAnsweredAtLocation.get(dateStr); Map<String, Integer> locationData = dayData.get(locationId); if (locationData == null) { locationData = new HashMap<String, Integer>(); dayData.put(locationId, locationData); } locationData.put(dateStr, numAnswered == null ? 0 : numAnswered); } displayKeys.put(year, year.toString()); displayKeys.put(year + month, month); displayKeys.put(dateStr, day.toString()); cal.add(form.getFrequency().getCalendarField(), form.getFrequency().getCalendarIncrement()); } Map<FacilityDataFormSchema, Integer> numQuestionsBySchema = new HashMap<FacilityDataFormSchema, Integer>(); for (FacilityDataFormSchema schema : form.getSchemas()) { numQuestionsBySchema.put(schema, schema.getTotalNumberOfQuestions()); } map.addAttribute("today", new Date()); map.addAttribute("form", form); map.addAttribute("yearIncrement", yearIncrement); map.addAttribute("monthIncrement", monthIncrement); map.addAttribute("yearCols", yearCols); map.addAttribute("monthCols", monthCols); map.addAttribute("dayCols", dayCols); map.addAttribute("dayData", dayData); map.addAttribute("displayKeys", displayKeys); map.addAttribute("numQuestionsBySchema", numQuestionsBySchema); map.addAttribute("questionsAnswered", questionsAnswered); map.addAttribute("locations", FacilityDataConstants.getSupportedFacilities()); map.addAttribute("datesSupported", datesSupported); }
From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java
/** * return a timestamp Object which correspond at the last minute of the date * .//from w w w. j a v a 2s. com * @param date the date * @return a timestamp Object which correspond at the last minute of the * date . */ public static Timestamp getLastMinute(Timestamp date) { Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, caldate.getActualMaximum(Calendar.MILLISECOND)); caldate.set(Calendar.SECOND, caldate.getActualMaximum(Calendar.SECOND)); 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.suggest.utils.SuggestUtils.java
/** * return the last day of week function of the date . * @param date the date//from w w w . java 2s .c o m * @return the last day of week function of the date. */ public static Timestamp getLastDayOfWeek(Timestamp date) { Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, caldate.getActualMaximum(Calendar.MILLISECOND)); caldate.set(Calendar.SECOND, caldate.getActualMaximum(Calendar.SECOND)); caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY)); caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE)); caldate.set(Calendar.DAY_OF_WEEK, caldate.getFirstDayOfWeek() + 6); Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis()); return timeStamp; }
From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java
/** * return the last day of month function of the date . * @param date the date// w w w. j a va2s . c o m * @return the last day of mont function of the date. */ public static Timestamp getLastDayOfMonth(Timestamp date) { Calendar caldate = new GregorianCalendar(); caldate.setTime(date); caldate.set(Calendar.MILLISECOND, caldate.getActualMaximum(Calendar.MILLISECOND)); caldate.set(Calendar.SECOND, caldate.getActualMaximum(Calendar.SECOND)); caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY)); caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE)); caldate.set(Calendar.DAY_OF_MONTH, caldate.getActualMaximum(Calendar.DAY_OF_MONTH)); Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis()); return timeStamp; }