private static void addDays(Date date, int days) { CalendarUtil.addDaysToDate(date, days); // We might hit DST transition. Try reseting back so follow up days continue showing midnight. CalendarUtil.resetTime(date); }
/** * Gets the first day of the first week in the currently specified month. * * @return the first day */ public Date getCurrentFirstDayOfFirstWeek() { int wkDayOfMonth1st = currentMonth.getDay(); int start = CalendarUtil.getStartingDayOfWeek(); if (wkDayOfMonth1st == start) { // always return a copy to allow SimpleCalendarView to adjust first // display date return new Date(currentMonth.getTime()); } else { Date d = new Date(currentMonth.getTime()); int offset = wkDayOfMonth1st - start > 0 ? wkDayOfMonth1st - start : DAYS_IN_WEEK - (start - wkDayOfMonth1st); CalendarUtil.addDaysToDate(d, -offset); return d; } }
protected Date getPreviousDate(Date date) { Date prev = new Date(date.getTime()); CalendarUtil.addDaysToDate(prev, -1); return prev; } }
private static void addDays(Date date, int days) { CalendarUtil.addDaysToDate(date, days); // We might hit DST transition. Try reseting back so follow up days continue showing midnight. CalendarUtil.resetTime(date); }
@SuppressWarnings("deprecation") public static Date getSameOrClosestDateInPreviousMonth(Date date) { Date desiredDate = new Date(date.getTime()); CalendarUtil.addMonthsToDate(desiredDate, -1); if (desiredDate.getMonth() == date.getMonth()) { // did not go one month back // e.g. 31 May -> 1st May, because April does not have 31st and thus the day is set to 1st May CalendarUtil.setToFirstDayOfMonth(desiredDate); CalendarUtil.addDaysToDate(desiredDate, -1); } return desiredDate; }
@SuppressWarnings("deprecation") public static Date getSameOrClosestDateInNextMonth(Date date) { Date desiredDate = new Date(date.getTime()); CalendarUtil.addMonthsToDate(desiredDate, 1); if (desiredDate.getMonth() > date.getMonth() + 1) { // skipped one month, e.g. 30 January -> 2nd (or 1st for leap-year) March, because February does not have 30th // set the date to last day of previous month CalendarUtil.setToFirstDayOfMonth(desiredDate); CalendarUtil.addDaysToDate(desiredDate, -1); } return desiredDate; }
@SuppressWarnings("deprecation") private static DateRange getDateRangeStartingOnMonday(Date dateWithinTheWeek, int nrOfDaysTotal) { Date startDate = new Date(dateWithinTheWeek.getTime()); int day = startDate.getDay() - 1; int daysAfterMonday = day; if (day == -1) { // corner case when the date within the week in Sunday and thus getDay() == 0 (and day == -1), so we need Monday // from that week, which is 6 days back daysAfterMonday = 6; } CalendarUtil.addDaysToDate(startDate, -daysAfterMonday); Date endDate = new Date(startDate.getTime()); CalendarUtil.addDaysToDate(endDate, nrOfDaysTotal - 1); return new DateRange(startDate, endDate, CalendarUtil.getDaysBetween(startDate, endDate)); }
case DAY: if ( back ) { CalendarUtil.addDaysToDate( currentDate, -1 ); } else { CalendarUtil.addDaysToDate( currentDate, 1 ); CalendarUtil.addDaysToDate( currentDate, -7 ); } else { CalendarUtil.addDaysToDate( currentDate, 7 );
private void disableDaysNotInCurrentMonth(Date startDay, Date endDay) { List<Date> disableDates = new LinkedList<Date>(); Date firstDayOfMonth = firstDayOfMonth(calendarWidget .getCurrentMonth()); Date lastDayOfMonth = lastDayOfMonth(calendarWidget .getCurrentMonth()); Date dayAfterEnd = (Date) endDay.clone(); CalendarUtil.addDaysToDate(dayAfterEnd, 1); for (Date day = startDay; day.before(dayAfterEnd); CalendarUtil .addDaysToDate(day, 1)) { if (day.before(firstDayOfMonth) || day.after(lastDayOfMonth)) { disableDates.add((Date) day.clone()); } } if (!disableDates.isEmpty()) { calendarWidget.setTransientEnabledOnDates(false, disableDates); } }
/** * Gets the first day of the first week in the currently specified month. * * @return the first day */ public Date getCurrentFirstDayOfFirstWeek() { int wkDayOfMonth1st = currentMonth.getDay(); int start = CalendarUtil.getStartingDayOfWeek(); if (wkDayOfMonth1st == start) { // always return a copy to allow SimpleCalendarView to adjust first // display date return new Date(currentMonth.getTime()); } else { Date d = new Date(currentMonth.getTime()); int offset = wkDayOfMonth1st - start > 0 ? wkDayOfMonth1st - start : DAYS_IN_WEEK - (start - wkDayOfMonth1st); CalendarUtil.addDaysToDate(d, -offset); return d; } }
/** * Gets the first day of the first week in the currently specified month. * * @return the first day */ public Date getCurrentFirstDayOfFirstWeek() { int wkDayOfMonth1st = currentMonth.getDay(); int start = CalendarUtil.getStartingDayOfWeek(); if (wkDayOfMonth1st == start) { // always return a copy to allow SimpleCalendarView to adjust first // display date return new Date(currentMonth.getTime()); } else { Date d = new Date(currentMonth.getTime()); int offset = wkDayOfMonth1st - start > 0 ? wkDayOfMonth1st - start : DAYS_IN_WEEK - (start - wkDayOfMonth1st); CalendarUtil.addDaysToDate(d, -offset); return d; } }
private static void addDays(Date date, int days) { CalendarUtil.addDaysToDate(date, days); if (date.getHours() != 0) { // We hit DST transition, try reseting back so follow up days continue showing midnight: date.setHours(0); } }
private Date lastDayOfMonth(Date month) { Date lastDay = (Date) month.clone(); CalendarUtil.addMonthsToDate(lastDay, 1); CalendarUtil.setToFirstDayOfMonth(lastDay); CalendarUtil.addDaysToDate(lastDay, -1); return justDay(lastDay); }
switch (keyCode) { case KeyCodes.KEY_LEFT: CalendarUtil.addDaysToDate(this.cursor, -1); handleKey = true; break; case KeyCodes.KEY_RIGHT: CalendarUtil.addDaysToDate(this.cursor, 1); handleKey = true; break; case KeyCodes.KEY_UP: CalendarUtil.addDaysToDate(this.cursor, -7); handleKey = true; break; case KeyCodes.KEY_DOWN: CalendarUtil.addDaysToDate(this.cursor, 7); handleKey = true; break;
/** * Returns a {@link DateRange} starting on first day of month in which the specified date is and ending on last day of that * month. * * @param date date from which to get the month date range * @return {@link DateRange} representing the month in which the specified date is */ @SuppressWarnings("deprecation") public static DateRange getMonthDateRange(Date date) { Date startDate = new Date(date.getTime()); CalendarUtil.setToFirstDayOfMonth(startDate); // the above method will set hours to 12 startDate.setHours(0); Date endDate = new Date(date.getTime()); CalendarUtil.setToFirstDayOfMonth(endDate); CalendarUtil.addMonthsToDate(endDate, 1); CalendarUtil.addDaysToDate(endDate, -1); endDate.setHours(0); return new DateRange(startDate, endDate, CalendarUtil.getDaysBetween(startDate, endDate)); }
switch (keyCode) { case KeyCodes.KEY_LEFT: CalendarUtil.addDaysToDate(this.cursor, -1); handleKey = true; break; case KeyCodes.KEY_RIGHT: CalendarUtil.addDaysToDate(this.cursor, 1); handleKey = true; break; case KeyCodes.KEY_UP: CalendarUtil.addDaysToDate(this.cursor, -7); handleKey = true; break; case KeyCodes.KEY_DOWN: CalendarUtil.addDaysToDate(this.cursor, 7); handleKey = true; break;
int lastMonthToDisplay = (selectedMonth + 13) % 12; do { CalendarUtil.addDaysToDate(dateToDrow, -1); } while (firstMonthToDisplay != dateToDrow.getMonth() || dateToDrow.getDay() != firstDayOfWeek); CalendarUtil.addDaysToDate(dateToDrow, 1);
int lastMonthToDisplay = (selectedMonth + 13) % 12; do { CalendarUtil.addDaysToDate(dateToDrow, -1); } while (firstMonthToDisplay != dateToDrow.getMonth() || dateToDrow.getDay() != firstDayOfWeek); CalendarUtil.addDaysToDate(dateToDrow, 1);