public void cargarMesAnterior(int mes, int ano) { Calendar calendarioo = GregorianCalendar.getInstance(); calendarioo.setFirstDayOfWeek(Calendar.MONDAY); calendarioo.set( ano, mes, calendarioo.getActualMinimum(Calendar.DAY_OF_MONTH), calendarioo.get(Calendar.HOUR_OF_DAY), calendarioo.get(Calendar.MINUTE), calendarioo.get(Calendar.SECOND)); int primerDia = calendarioo.get(Calendar.DAY_OF_WEEK) - 2; Log.e("primerDia", primerDia + ""); calendarioo.set( calendarioo.get(Calendar.YEAR), calendarioo.get(Calendar.MONTH) - 1, calendarioo.getActualMinimum(Calendar.DAY_OF_MONTH), calendarioo.get(Calendar.HOUR_OF_DAY), calendarioo.get(Calendar.MINUTE), calendarioo.get(Calendar.SECOND)); if (primerDia == -1) { primerDia = 6; } int ultimoDia = calendarioo.getActualMaximum(Calendar.DAY_OF_MONTH); int diaPartida = ultimoDia - primerDia + 1; Log.e("primerDia", calendarioo.getFirstDayOfWeek() + ""); for (int i = 0; i < primerDia; i++) { diasCalendarios.add(new DiasCalendario(diaPartida, diaPartida, mes, ano, 4)); diaPartida++; } }
void updateSpinners() { if (mDayEnabled) { if (mCurrentDate.equals(mMinDate)) { mDaySpinner.setMinValue(mCurrentDate.get(Calendar.DAY_OF_MONTH)); mDaySpinner.setMaxValue(mCurrentDate.getActualMaximum(Calendar.DAY_OF_MONTH)); } else if (mCurrentDate.equals(mMaxDate)) { mDaySpinner.setMinValue(mCurrentDate.getActualMinimum(Calendar.DAY_OF_MONTH)); mDaySpinner.setMaxValue(mCurrentDate.get(Calendar.DAY_OF_MONTH)); } else { mDaySpinner.setMinValue(1); mDaySpinner.setMaxValue(mCurrentDate.getActualMaximum(Calendar.DAY_OF_MONTH)); } mDaySpinner.setValue(mCurrentDate.get(Calendar.DAY_OF_MONTH)); } if (mWeekEnabled) { mWeekSpinner.setMinValue(1); mWeekSpinner.setMaxValue(mCurrentDate.getActualMaximum(Calendar.WEEK_OF_YEAR)); mWeekSpinner.setValue(mCurrentDate.get(Calendar.WEEK_OF_YEAR)); } if (mMonthEnabled) { mMonthSpinner.setDisplayedValues(null); if (mCurrentDate.equals(mMinDate)) { mMonthSpinner.setMinValue(mCurrentDate.get(Calendar.MONTH)); mMonthSpinner.setMaxValue(mCurrentDate.getActualMaximum(Calendar.MONTH)); } else if (mCurrentDate.equals(mMaxDate)) { mMonthSpinner.setMinValue(mCurrentDate.getActualMinimum(Calendar.MONTH)); mMonthSpinner.setMaxValue(mCurrentDate.get(Calendar.MONTH)); } else { mMonthSpinner.setMinValue(Calendar.JANUARY); mMonthSpinner.setMaxValue(Calendar.DECEMBER); } String[] displayedValues = Arrays.copyOfRange( mShortMonths, mMonthSpinner.getMinValue(), mMonthSpinner.getMaxValue() + 1); mMonthSpinner.setDisplayedValues(displayedValues); mMonthSpinner.setValue(mCurrentDate.get(Calendar.MONTH)); } if (mYearEnabled) { mYearSpinner.setMinValue(mMinDate.get(Calendar.YEAR)); mYearSpinner.setMaxValue(mMaxDate.get(Calendar.YEAR)); mYearSpinner.setValue(mCurrentDate.get(Calendar.YEAR)); } if (mHourEnabled) { if (mIs12HourMode) { mHourSpinner.setValue(mCurrentDate.get(Calendar.HOUR)); mAMPMSpinner.setValue(mCurrentDate.get(Calendar.AM_PM)); mAMPMSpinner.setDisplayedValues(mShortAMPMs); } else { mHourSpinner.setValue(mCurrentDate.get(Calendar.HOUR_OF_DAY)); } } if (mMinuteEnabled) { mMinuteSpinner.setValue(mCurrentDate.get(Calendar.MINUTE)); } }
/** * 获取一小时的第一秒 * * @param timeInMillis * @return */ public static long getFirstSecondInHour(long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeInMillis); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); return calendar.getTimeInMillis(); }
@Override public void start() throws ProcessException { super.start(); // dataLancamentoInicial.set(Calendar.DATE, // dataLancamentoInicial.getActualMinimum(Calendar.DATE)); dataVencimentoInicial.set(Calendar.DATE, dataVencimentoInicial.getActualMinimum(Calendar.DATE)); dataRecebimentoInicial.set( Calendar.DATE, dataRecebimentoInicial.getActualMinimum(Calendar.DATE)); }
/** * 获取一个月的第一毫秒 * * @param startTimeMillis * @return */ public static long getFirstSecondInMonth(long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeInMillis); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); 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)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); return calendar.getTimeInMillis(); }
/** * 获取一星期的第一毫秒 * * @param timeInMillis * @return */ public static long getFirstSecondInWeek(long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeInMillis); calendar.setFirstDayOfWeek(Calendar.SUNDAY); calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK)); 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)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); return calendar.getTimeInMillis(); }
/** * 获取指定月份的日历数组 * * @param year * @param month * @return */ private int[] getDays(int year, int month) { int[] daysArray = new int[42]; getDaysCalendar.set(Calendar.YEAR, year); getDaysCalendar.set(Calendar.MONTH, month - 1); getDaysCalendar.set( Calendar.DAY_OF_MONTH, getDaysCalendar.getActualMinimum(Calendar.DAY_OF_MONTH)); int start = getDaysCalendar.get(Calendar.DAY_OF_WEEK) - 1; int end = getDaysCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); int day = 1; if (year < startYear || (year == startYear && month < startMonth)) { return null; } if (year == startYear && month == startMonth) { for (int i = 0; i < days.length; i++) { if (i < start || day > end) { daysArray[i] = 0; } else { if (day >= startDay) { daysArray[i] = day; } day++; } } return daysArray; } for (int i = 0; i < days.length; i++) { if (i < start || day > end) { daysArray[i] = 0; } else { daysArray[i] = day; day++; } } return daysArray; }
public static Date getStartDate(String type) { Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.MONDAY); switch (type) { case MONTHLY: c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH)); break; case WEEKLY: c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); break; case DAILY: c.set(Calendar.HOUR_OF_DAY, c.getActualMinimum(Calendar.HOUR_OF_DAY)); break; } return c.getTime(); }
private void getUsageInfo() { final Calendar now = Calendar.getInstance(); final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(Calendar.YEAR, now.get(Calendar.YEAR)); cal.set(Calendar.MONTH, now.get(Calendar.MONTH)); final int dayMin = now.getActualMinimum(Calendar.DAY_OF_MONTH); final int dayMax = now.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, dayMin); cal.setTimeZone(now.getTimeZone()); final Date start = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, dayMax); cal.add(Calendar.DATE, 1); final Date end = cal.getTime(); final TaskRunnable<Object[], NetworkUsageInfo, NetworkUsageSummaryPreferences> task; task = new TaskRunnable<Object[], NetworkUsageInfo, NetworkUsageSummaryPreferences>() { @Override public NetworkUsageInfo doLongOperation(Object[] params) throws InterruptedException { final int[] network = {ConnectivityManager.TYPE_MOBILE}; return NetworkUsageInfo.get( (Context) params[0], (Date) params[1], (Date) params[2], dayMin, dayMax, network); } @Override public void callback(NetworkUsageSummaryPreferences handler, NetworkUsageInfo result) { handler.setUsage(result); } }; task.setResultHandler(this); task.setParams(new Object[] {getContext(), start, end}); AsyncManager.runBackgroundTask(task); }
private void previousMonth() { if (cal.get(Calendar.MONTH) == cal.getActualMinimum(Calendar.MONTH)) { cal.set((cal.get(Calendar.YEAR) - 1), Calendar.DECEMBER, 1); } else { cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); } rebuildCalendar(); }
public static java.util.Date getDate(int y, int m, int d, boolean inclusive) { java.util.Date dt = null; Calendar c = Calendar.getInstance(); c.clear(); if (c.getActualMinimum(1) <= y && y <= c.getActualMaximum(1)) { c.set(1, y); if (c.getActualMinimum(2) <= m && m <= c.getActualMaximum(2)) { c.set(2, m); if (c.getActualMinimum(5) <= d && d <= c.getActualMaximum(5)) c.set(5, d); } if (inclusive) { c.add(5, 1); c.add(14, -1); } dt = c.getTime(); } return dt; }
public static Date getPrimerDiaDelMes() { Calendar cal = Calendar.getInstance(); cal.set( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getActualMinimum(Calendar.DAY_OF_MONTH), cal.getMinimum(Calendar.HOUR_OF_DAY), cal.getMinimum(Calendar.MINUTE), cal.getMinimum(Calendar.SECOND)); return cal.getTime(); }
/** * Met à 0 tous les champs du calendrier inférieur au champ {@code field} spécifié. Note: si le * calendrier spécifié est {@link #calendar}, il est de la responsabilité de l'appelant de * restituer {@link #calendar} dans son état correct après l'appel de cette méthode. */ private static void truncate(final Calendar calendar, int field) { for (int i = 0; i < FIELD.length; i++) { if (FIELD[i] == field) { calendar.get(field); // Force la mise à jour des champs. while (++i < FIELD.length) { field = FIELD[i]; calendar.set(field, calendar.getActualMinimum(field)); } break; } } }
private void updateDate() { System.out.println( "Month: " + mCalendar.get(Calendar.MONTH) + " Max: " + mCalendar.getActualMaximum(Calendar.DATE)); mDayPicker.setMinValue(mCalendar.getActualMinimum(Calendar.DATE)); mDayPicker.setMaxValue(mCalendar.getActualMaximum(Calendar.DATE)); mDayPicker.setValue(mCalendar.get(Calendar.DATE)); mMonthPicker.setValue(mCalendar.get(Calendar.MONTH)); mYearPicker.setValue(mCalendar.get(Calendar.YEAR)); }
/** Prepare example objects */ @Before public void createRoom() { MockitoAnnotations.initMocks(this); room1 = new Room(); room2 = new Room(); room3 = new Room(); room1.setId((long) 1); room1.setName("57"); room1.setNumberOfBeds(3); room1.setPrice(new BigDecimal("80.00")); room1.setHotel(hotel1); room2.setId((long) 2); room2.setName("120"); room2.setNumberOfBeds(1); room2.setPrice(new BigDecimal("150.00")); room2.setHotel(hotel2); room3.setId((long) 3); room3.setName("58"); room3.setNumberOfBeds(3); room3.setPrice(new BigDecimal("80.00")); hotel1 = new Hotel(); hotel2 = new Hotel(); hotel1.setName("Hotel 1"); hotel1.setAddress("Hotel address 1"); hotel2.setName("Hotel 2"); hotel2.setAddress("Hotel address 2"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, 1); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); nextMonthFirstDay = calendar.getTime(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); nextMonthLastDay = calendar.getTime(); reservation1 = new Reservation(); reservation2 = new Reservation(); reservation1.setStartOfReservation(nextMonthFirstDay); reservation1.setEndOfReservation(nextMonthLastDay); reservation1.setRoom(room1); reservation2.setStartOfReservation(nextMonthFirstDay); reservation2.setEndOfReservation(nextMonthLastDay); reservation2.setRoom(room2); }
/** * Ensures that the input date is valid * * @param dayOfMonth * @param month * @param year * @return true if date is valid, false if invalid */ public static boolean checkDate(int dayOfMonth, int month, int year) { // Calendar starts date and month at 0 int calMonth = month - 1; Calendar inputCal = Calendar.getInstance(); inputCal.set(year, calMonth, 1); Calendar cal = Calendar.getInstance(); // Can't have a future date if (!(year <= cal.get(Calendar.YEAR))) return false; // Month must be valid if (!(calMonth >= inputCal.getActualMinimum(Calendar.MONTH) && calMonth <= inputCal.getActualMaximum(Calendar.MONTH))) return false; // Day must be valid if (!(dayOfMonth >= inputCal.getActualMinimum(Calendar.DAY_OF_MONTH) && dayOfMonth <= inputCal.getActualMaximum(Calendar.DAY_OF_MONTH))) return false; return true; }
@Override public List<Transaction> getStatementByMonth(long branch, long accountNumber, int month, int year) throws BusinessException { // First Day Calendar firstDay = Calendar.getInstance(); firstDay.set(Calendar.DAY_OF_MONTH, 1); firstDay.set(Calendar.MONTH, month); firstDay.set(Calendar.YEAR, year); firstDay.set(Calendar.HOUR_OF_DAY, firstDay.getActualMinimum(Calendar.HOUR_OF_DAY)); firstDay.set(Calendar.MINUTE, firstDay.getActualMinimum(Calendar.MINUTE)); firstDay.set(Calendar.SECOND, firstDay.getActualMinimum(Calendar.SECOND)); firstDay.set(Calendar.MILLISECOND, firstDay.getActualMinimum(Calendar.MILLISECOND)); // Last Day Calendar lastDay = Calendar.getInstance(); lastDay.setTime(firstDay.getTime()); lastDay.add(Calendar.MONTH, 1); lastDay.add(Calendar.MILLISECOND, -1); return getStatementByDate( readCurrentAccount(branch, accountNumber), firstDay.getTime(), lastDay.getTime()); }
public List<String> queryFeedbackByMonth(Calendar date, String department) { Session session = sessionFactory.openSession(); session.beginTransaction(); Query query = session.getNamedQuery("Feedback.byMonth"); query.setInteger("dateMonthStart", date.getActualMinimum(Calendar.DAY_OF_MONTH)); query.setInteger("dateMonthEnd", date.getActualMaximum(Calendar.DAY_OF_MONTH)); query.setString("department", department); List<String> feedbackList = (List<String>) query.list(); System.out.println(Integer.toString(feedbackList.size())); session.getTransaction().commit(); session.close(); return feedbackList; }
/** @tests {@link java.util.Calendar#getActualMinimum(int)} */ @TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getActualMinimum", args = {int.class}), @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "Calendar", args = {}) }) public void test_getActualMinimum_I() { Calendar c = new MockCalendar(); assertEquals("should be equal to 0", 0, c.getActualMinimum(0)); }
/** * 获取一星期的最后一毫秒 * * @param timeInMillis * @param dayOfWeek 周的第一天。若为负数,则不设置,参照Calendar * @return */ public static long getLastSecondInWeek(long timeInMillis, int dayOfWeek) { if (dayOfWeek < 1 || dayOfWeek > 7) { // 从第一天开始计算,返回加7天之后的最后一秒 Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(dayOfWeek); calendar.setTimeInMillis(timeInMillis); calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK)); calendar.add(Calendar.DAY_OF_WEEK, 6); 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)); calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND)); return calendar.getTimeInMillis(); } else { // 无效参数以及dayOfWeek == Sunday时,返回星期六最后一毫秒 // Sunday == 1 return getLastSecondInWeek(timeInMillis); } }
/** * Replace l'itérateur sur la première graduation. La position de la première graduation sera * calculée et retenue pour un positionnement plus rapide à l'avenir. */ private void findFirstTick() { calendar.clear(); value = minimum; date.setTime(value); calendar.setTime(date); if (true) { // Arrondie la date de départ. Note: ce calcul exige que // tous les champs commencent à 0 plutôt que 1, y compris // les mois et le jour du mois. final int offset = calendar.getActualMinimum(tickField); int toRound = calendar.get(tickField) - offset; toRound = (toRound / tickAdd) * tickAdd; calendar.set(tickField, toRound + offset); } truncate(calendar, tickField); nextTick = calendar.getTime().getTime(); nextSubTick = nextTick; while (nextTick < minimum) { calendar.add(tickField, tickAdd); nextTick = calendar.getTime().getTime(); } date.setTime(nextSubTick); calendar.setTime(date); while (nextSubTick < minimum) { calendar.add(subTickField, subTickAdd); nextSubTick = calendar.getTime().getTime(); } /* 'calendar' a maintenant la valeur 'nextSubTick', comme le veut la spécification de * ce champ. On appelle maintenant 'next' pour transférer cette valeur 'nextSubTick' * vers 'value'. Notez que 'next' peut être appelée même si value>maximum. */ next(); // Retient les positions trouvées. this.value0 = this.value; this.nextTick0 = this.nextTick; this.nextSubTick0 = this.nextSubTick; this.isMajorTick0 = this.isMajorTick; assert calendar.getTime().getTime() == nextSubTick; }
/** * 根据日期月份,获取月份的开始和结束日期 * * @param date * @return */ public static Map<String, Date> getMonthDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); // 得到前一个月的第一天 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 end = calendar.getTime(); Map<String, Date> map = new HashMap<String, Date>(); map.put("start", start); map.put("end", end); return map; }
public static void clearCalendarValuesUnder(Calendar calendar, int calendarId) { switch (calendarId) { case Calendar.YEAR: calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH)); // no break intentional case Calendar.MONTH: calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); // no break intentional case Calendar.DATE: calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY)); // no break intentional case Calendar.HOUR_OF_DAY: case Calendar.HOUR: calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); // no break intentional case Calendar.MINUTE: calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); break; default: throw new IllegalStateException("What is " + calendarId); } }
public static Date getFirstDayOffMonth(Date date) { calendar.setTime(addMinimunHour(date)); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); return calendar.getTime(); }
public static Date getMonthBegining(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); setTimeToBeginningOfDay(calendar); return calendar.getTime(); }
public static Calendar getPrimeiroDiaMes(Calendar data) { Calendar calendario = data; calendario.set(Calendar.DAY_OF_MONTH, calendario.getActualMinimum(Calendar.DAY_OF_MONTH)); return calendario; }
@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 { 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"; }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.previous: if (month.get(Calendar.MONTH) == month.getActualMinimum(Calendar.MONTH)) { month.set((month.get(Calendar.YEAR) - 1), month.getActualMaximum(Calendar.MONTH), 1); } else { month.set(Calendar.MONTH, month.get(Calendar.MONTH) - 1); } refreshCalendar(); break; case R.id.wall: if (menu != null) { menu.toggle(); } Intent i = new Intent(Calender.this, Home.class); Calender.this.finish(); startActivity(i); break; case R.id.servicelist: if (menu != null) { menu.toggle(); } Intent service = new Intent(Calender.this, Servicelist.class); Calender.this.finish(); startActivity(service); break; case R.id.next: if (month.get(Calendar.MONTH) == month.getActualMaximum(Calendar.MONTH)) { month.set((month.get(Calendar.YEAR) + 1), month.getActualMinimum(Calendar.MONTH), 1); } else { month.set(Calendar.MONTH, month.get(Calendar.MONTH) + 1); } refreshCalendar(); break; case R.id.backButton: break; case R.id.rightButton: if (menu1 == null) { System.out.println("inside view null"); view1 = Calender.this.getLayoutInflater().inflate(R.layout.addanappointment, null); menu1 = new SlidingMenu(this); menu1.setMode(SlidingMenu.RIGHT); menu1.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE); menu1.setBehindOffsetRes(R.dimen.sliding_limit); menu1.setMenu(view1); menu1.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); menu1.toggle(); intiliazeright(view1); } else { System.out.println("inside view not null"); menu1.toggle(); try { fname.setText(""); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { lname.setText(""); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { adult_counter.setText("1"); child_counter.setText("0"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; case R.id.scheduletime: Calendar calender = Calendar.getInstance(); DatePickerDialog datePicker = new DatePickerDialog( Calender.this, new MyDateListener(), calender.get(Calendar.YEAR), calender.get(Calendar.MONTH), calender.get(Calendar.DAY_OF_MONTH)); datePicker.show(); break; case R.id.adult_plus: counter_adult = counter_adult + 1; Log.e("add counter", Integer.toString(counter_adult)); adult_counter.setText(Integer.toString(counter_adult)); break; case R.id.adult_minus: if (counter_adult == 0) { // adult_counter.setText(Integer.toString(counter_adult)); } else { counter_adult = counter_adult - 1; Log.e("add counter", Integer.toString(counter_adult)); adult_counter.setText(Integer.toString(counter_adult)); } break; case R.id.child_plus: counter_child = counter_child + 1; child_counter.setText(Integer.toString(counter_child)); break; case R.id.child_minus: if (counter_child == 0) { } else { counter_child = counter_child - 1; child_counter.setText(Integer.toString(counter_child)); } break; case R.id.edit_save: if (menu1 != null) { menu1.toggle(); } break; default: break; } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub RequestDispatcher parche; String seleccion = request.getParameter("rango"); String cuent = request.getParameter("cuenta"); String Error = ""; String fechaHoy = ""; String siete = ""; String fechaHasta = ""; String desde = request.getParameter("from"); String hasta = request.getParameter("to"); if ("reciente".equals(seleccion)) { Calendar c2 = new GregorianCalendar(); String dia, mes, annio; dia = Integer.toString(c2.get(Calendar.DATE)); mes = Integer.toString(c2.get(Calendar.MONTH) + 1); annio = Integer.toString(c2.get(Calendar.YEAR)); System.out.println(dia + "-" + mes + "-" + annio); fechaHoy = (annio + "-" + mes + "-" + dia); c2.add(Calendar.DATE, -7); dia = Integer.toString(c2.get(Calendar.DATE)); mes = Integer.toString(c2.get(Calendar.MONTH) + 1); annio = Integer.toString(c2.get(Calendar.YEAR)); System.out.println(dia + "-" + mes + "-" + annio); siete = (annio + "-" + mes + "-" + dia); System.out.println(fechaHoy); System.out.println(siete); } if ("mes".equals(seleccion)) { Calendar c2 = new GregorianCalendar(); String dia, mes, annio; mes = Integer.toString(c2.get(Calendar.MONTH) + 1); dia = Integer.toString(c2.getActualMinimum(Calendar.DAY_OF_MONTH)); annio = Integer.toString(c2.get(Calendar.YEAR)); System.out.println(dia + "-" + mes + "-" + annio); siete = (annio + "-" + mes + "-" + dia); dia = Integer.toString(c2.getActualMaximum(Calendar.DAY_OF_MONTH)); System.out.println(dia + "-" + mes + "-" + annio); fechaHoy = (annio + "-" + mes + "-" + dia); System.out.println(siete); System.out.println(fechaHoy); } if ("formatos".equals(seleccion)) { String dia, mes, annio; StringTokenizer tokens = new StringTokenizer(desde, "/"); dia = tokens.nextToken(); mes = tokens.nextToken(); annio = tokens.nextToken(); siete = (annio + "-" + mes + "-" + dia); System.out.println(siete); StringTokenizer tokenss = new StringTokenizer(hasta, "/"); dia = tokenss.nextToken(); mes = tokenss.nextToken(); annio = tokenss.nextToken(); fechaHoy = (annio + "-" + mes + "-" + dia); System.out.println(fechaHoy); } Usuario objeto = new Usuario(); objeto.setFechaDesde(siete); objeto.setFechaHasta(fechaHoy); objeto.setCuenta(cuent); LinkedList<Usuario> listaContactos = new LinkedList<Usuario>(); try { listaContactos = ListaCheques.UsuarioValido(objeto); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(listaContactos); parche = getServletContext().getRequestDispatcher("/Consulta_busqueda.jsp"); HttpSession sesion = request.getSession(true); sesion.setAttribute("Usuarios", objeto); parche.forward(request, response); }
private static void modify(Calendar val, int field, int modType) { if (val.get(1) > 280000000) { throw new ArithmeticException("Calendar value too large for accurate calculations"); } if (field == 14) { return; } Date date = val.getTime(); long time = date.getTime(); boolean done = false; int millisecs = val.get(14); if ((0 == modType) || (millisecs < 500)) { time -= millisecs; } if (field == 13) { done = true; } int seconds = val.get(13); if ((!done) && ((0 == modType) || (seconds < 30))) { time -= seconds * 1000L; } if (field == 12) { done = true; } int minutes = val.get(12); if ((!done) && ((0 == modType) || (minutes < 30))) { time -= minutes * 60000L; } if (date.getTime() != time) { date.setTime(time); val.setTime(date); } boolean roundUp = false; for (int i = 0; i < fields.length; i++) { for (int j = 0; j < fields[i].length; j++) { if (fields[i][j] == field) { if ((modType == 2) || ((modType == 1) && (roundUp))) { if (field == 1001) { if (val.get(5) == 1) { val.add(5, 15); } else { val.add(5, -15); val.add(2, 1); } } else if (field == 9) { if (val.get(11) == 0) { val.add(11, 12); } else { val.add(11, -12); val.add(5, 1); } } else { val.add(fields[i][0], 1); } } return; } } int offset = 0; boolean offsetSet = false; switch (field) { case 1001: if (fields[i][0] == 5) { offset = val.get(5) - 1; if (offset >= 15) { offset -= 15; } roundUp = offset > 7; offsetSet = true; } break; case 9: if (fields[i][0] == 11) { offset = val.get(11); if (offset >= 12) { offset -= 12; } roundUp = offset >= 6; offsetSet = true; } break; } if (!offsetSet) { int min = val.getActualMinimum(fields[i][0]); int max = val.getActualMaximum(fields[i][0]); offset = val.get(fields[i][0]) - min; roundUp = offset > (max - min) / 2; } if (offset != 0) { val.set(fields[i][0], val.get(fields[i][0]) - offset); } } throw new IllegalArgumentException("The field " + field + " is not supported"); }