List of usage examples for org.joda.time DateMidnight plusDays
public DateMidnight plusDays(int days)
From source file:dk.teachus.backend.domain.impl.PeriodsImpl.java
License:Apache License
public List<DatePeriod> generateDatesForWeek(DateMidnight startDate) { List<DatePeriod> dates = new ArrayList<DatePeriod>(); DateMidnight sd = startDate.withDayOfWeek(DateTimeConstants.MONDAY); int week = sd.getWeekOfWeekyear(); while (week == sd.getWeekOfWeekyear()) { DatePeriod datePeriod = null;/*from ww w . j a v a 2 s . com*/ for (Period period : getValidPeriods()) { // Check if this period can handle the date at all if (period.dateIntervalContains(sd)) { DateMidnight date = period.generateDate(sd); if (date != null) { if (datePeriod == null) { datePeriod = new DatePeriodImpl(date); dates.add(datePeriod); } datePeriod.addPeriod(period); } } } sd = sd.plusDays(1); } Collections.sort(dates, new Comparator<DatePeriod>() { public int compare(DatePeriod o1, DatePeriod o2) { return o1.getDate().compareTo(o2.getDate()); } }); return dates; }
From source file:dk.teachus.frontend.components.calendar.CalendarPanel.java
License:Apache License
public CalendarPanel(String id, IModel<DateMidnight> weekDateModel) { super(id, weekDateModel); /*//from w w w . j av a2 s .c o m * Navigation */ Link<DateMidnight> previousWeekLink = new Link<DateMidnight>("previousWeek", weekDateModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void onClick() { setModelObject(getModelObject().minusWeeks(1)); } }; previousWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.previousWeek"))); //$NON-NLS-1$ //$NON-NLS-2$ add(previousWeekLink); Link<DateMidnight> thisWeekLink = new Link<DateMidnight>("thisWeek", weekDateModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void onClick() { setModelObject(new DateMidnight()); } }; thisWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.thisWeek"))); //$NON-NLS-1$ //$NON-NLS-2$ add(thisWeekLink); Link<DateMidnight> nextWeekLink = new Link<DateMidnight>("nextWeek", weekDateModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void onClick() { setModelObject(getModelObject().plusWeeks(1)); } }; nextWeekLink.add(new Label("label", TeachUsSession.get().getString("CalendarPanelV2.nextWeek"))); //$NON-NLS-1$ //$NON-NLS-2$ add(nextWeekLink); /* * Calendar */ IModel<List<DateMidnight>> daysModel = new LoadableDetachableModel<List<DateMidnight>>() { private static final long serialVersionUID = 1L; @Override protected List<DateMidnight> load() { DateMidnight thisMonday = CalendarPanel.this.getModelObject() .withDayOfWeek(DateTimeConstants.MONDAY); List<DateMidnight> days = new ArrayList<DateMidnight>(); for (int i = 0; i < 7; i++) { days.add(thisMonday); thisMonday = thisMonday.plusDays(1); } return days; } }; final IModel<List<LocalTime>> timesModel = new LoadableDetachableModel<List<LocalTime>>() { private static final long serialVersionUID = 1L; @Override protected List<LocalTime> load() { int minutesDivider = 30; LocalTime localTime = getCalendarStartTime(); final List<LocalTime> times = new ArrayList<LocalTime>(); for (int i = 0; i < calculateNumberOfCalendarHours() * (60 / minutesDivider); i++) { times.add(localTime); localTime = localTime.plusMinutes(minutesDivider); } return times; } }; // Headers add(new ListView<DateMidnight>("headers", daysModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<DateMidnight> item) { item.add(new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public String getObject() { return HEADER_FORMAT.withLocale(TeachUsSession.get().getLocale()) .print(item.getModelObject()); } }).setRenderBodyOnly(true)); } }); // Body // Times add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<LocalTime> item) { Label label = new Label("label", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public String getObject() { if (item.getModelObject().getMinuteOfHour() == 0) { return TIME_FORMAT.withLocale(TeachUsSession.get().getLocale()) .print(item.getModelObject()); } else { return null; } } }); item.add(label); IModel<String> appendModel = new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (item.getModelObject().getMinuteOfHour() == 0) { return "timehour"; //$NON-NLS-1$ } else { return null; } } }; item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$ } }); // Days add(new ListView<DateMidnight>("days", daysModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<DateMidnight> dayItem) { // Times dayItem.add(new ListView<LocalTime>("times", timesModel) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<LocalTime> item) { IModel<String> appendModel = new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (item.getModelObject().getMinuteOfHour() == 0) { return "daytimehour"; //$NON-NLS-1$ } else { return null; } } }; item.add(AttributeModifier.append("class", appendModel)); //$NON-NLS-1$ } }); /* * Entries */ dayItem.add(new ListView<TimeSlot<T>>("timeSlots", getTimeSlotModel(dayItem.getModelObject())) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<TimeSlot<T>> timeSlotItem) { timeSlotItem.setOutputMarkupId(true); final LocalTime startTime = timeSlotItem.getModelObject().getStartTime(); final LocalTime endTime = timeSlotItem.getModelObject().getEndTime(); int dividerPixelHeight = 25; double minutesPerDivider = calculateNumberOfCalendarHours() * 60 / timesModel.getObject().size(); // Calculate top/y (start time) double minutesStart = startTime.getHourOfDay() * 60 + startTime.getMinuteOfHour(); minutesStart -= getCalendarStartTime().getHourOfDay() * 60 + getCalendarStartTime().getMinuteOfHour(); double pixelStart = minutesStart / minutesPerDivider; long top = Math.round(pixelStart * dividerPixelHeight) - 1; // Calculate height (end time) final double minutesEnd = (endTime.getHourOfDay() * 60 + endTime.getMinuteOfHour()) - minutesStart - getCalendarStartTime().getHourOfDay() * 60 + getCalendarStartTime().getMinuteOfHour(); double pixelEnd = minutesEnd / minutesPerDivider; long height = Math.round(pixelEnd * dividerPixelHeight) - 1; timeSlotItem.add(AttributeModifier.replace("style", //$NON-NLS-1$ "left: 0; top: " + top + "px; height: " + height + "px;")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // Time slot content IModel<List<String>> timeSlotContentModel = new LoadableDetachableModel<List<String>>() { private static final long serialVersionUID = 1L; @Override protected List<String> load() { return getTimeSlotContent(dayItem.getModelObject(), timeSlotItem.getModelObject(), timeSlotItem); } }; timeSlotItem.add(new ListView<String>("timeSlotContent", timeSlotContentModel) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<String> item) { item.add(new Label("content", item.getModel())); item.add(AttributeModifier.replace("title", item.getModel())); } }); // Details final Component dayTimeLessonDetails = createTimeSlotDetailsComponent( "dayTimeLessonDetails", timeSlotItem.getModelObject()); dayTimeLessonDetails.setOutputMarkupId(true); timeSlotItem.add(dayTimeLessonDetails); timeSlotItem.add(AttributeModifier.append("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override public String getObject() { if (dayTimeLessonDetails.isVisible()) { return "popover-external"; } return null; } })); timeSlotItem.add( AttributeModifier.replace("data-content-id", new AbstractReadOnlyModel<String>() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public String getObject() { if (dayTimeLessonDetails.isVisible()) { return "#" + dayTimeLessonDetails.getMarkupId(); //$NON-NLS-1$ } else { return null; } } })); } }); } }); }
From source file:edu.wisc.hr.demo.RandomAbsenceHistoryDao.java
License:Apache License
@Override public List<AbsenceHistory> getAbsenceHistory(String emplId) { if (emplIdToAbsenceHistory.containsKey(emplId)) { return (List<AbsenceHistory>) emplIdToAbsenceHistory.get(emplId); }/*from ww w. j a v a 2 s . co m*/ int howManyAbsences = random.nextInt(20); List absenceHistories = new LinkedList<AbsenceHistory>(); for (int i = 0; i < howManyAbsences; i++) { AbsenceHistory absenceHistory = new AbsenceHistory(); random.nextLong(); // generate start date int year = 2013 - random.nextInt(10); // 2004-2013 int monthOfYear = random.nextInt(12) + 1; // 1-12 int dayOfMonth = random.nextInt(28) + 1; // 1-28 DateMidnight startDate = new DateMidnight(year, monthOfYear, dayOfMonth); int daysDuration = random.nextInt(100); DateMidnight endDate = startDate.plusDays(daysDuration); PersonInformation personInfo = this.contactInfoDao.getPersonalData(emplId); Job primaryJob = personInfo.getPrimaryJob(); absenceHistory.setStart(startDate); absenceHistory.setEnd(endDate); absenceHistory.setTotal(new BigDecimal(daysDuration)); absenceHistory.setName("WhatsAnAbsenceHistoryName?"); absenceHistory.setJob(primaryJob); absenceHistory.setStatus("WhatsAnAbsenceHistoryStatus?"); absenceHistories.add(absenceHistory); } this.emplIdToAbsenceHistory.put(emplId, absenceHistories); return absenceHistories; }
From source file:io.viewserver.core.BusinessDayCalculator.java
License:Apache License
public int getBusinessDay(ReadableDateTime start, ReadableDateTime end) { DateMidnight startMidnight = new DateMidnight(start); DateMidnight endMidnight = new DateMidnight(end); int weekdayStart = startMidnight.get(DateTimeFieldType.dayOfWeek()); int weekdayEnd = endMidnight.get(DateTimeFieldType.dayOfWeek()); if (weekdayStart == DateTimeConstants.SATURDAY) { startMidnight = startMidnight.plusDays(2); weekdayStart = DateTimeConstants.MONDAY; } else if (weekdayStart == DateTimeConstants.SUNDAY) { startMidnight = startMidnight.plusDays(1); weekdayStart = DateTimeConstants.MONDAY; }// ww w . jav a2s . co m if (weekdayEnd == DateTimeConstants.SATURDAY) { endMidnight = endMidnight.minusDays(1); weekdayEnd = DateTimeConstants.FRIDAY; } else if (weekdayEnd == DateTimeConstants.SUNDAY) { endMidnight = endMidnight.minusDays(2); weekdayEnd = DateTimeConstants.FRIDAY; } int days = Days.daysBetween(startMidnight, endMidnight).getDays(); startMidnight = startMidnight.plusDays(DateTimeConstants.SATURDAY - weekdayStart); endMidnight = endMidnight.plusDays(DateTimeConstants.SATURDAY - weekdayEnd); int daysBetweenWeekends = (int) ((endMidnight.getMillis() - startMidnight.getMillis()) / (24 * 60 * 60 * 1000)); int weekendDays = daysBetweenWeekends * 2 / 7; days -= weekendDays; return days; }
From source file:models.Propal.java
License:Open Source License
@PreUpdate @PrePersist//from w ww . j a v a 2 s.c o m private void calculateExpirationDate() { if (creationDate == null) { // Set the creation Date to today for existing propals in DB creationDate = new DateMidnight().toDate(); } DateMidnight dt = new DateMidnight(creationDate); this.expirationDate = dt.plusDays(nbDaysOfValidity).toDate(); }
From source file:net.naonedbus.manager.impl.HoraireManager.java
License:Open Source License
/** * Rcuprer les prochains horaires d'un arrt * //from w ww. j a v a 2 s . c om * @throws IOException */ public List<Horaire> getNextSchedules(final ContentResolver contentResolver, final Arret arret, DateMidnight date, final int limit, final int minuteDelay) throws IOException { if (DBG) Log.d(LOG_TAG, "getNextHoraires " + arret + " : " + date + "\t" + limit); List<Horaire> schedules; final DateTime now = new DateTime().minusMinutes(minuteDelay).withSecondOfMinute(0).withMillisOfSecond(0); final List<Horaire> nextSchedules = new ArrayList<Horaire>(); int schedulesCount = 0; // Juste renvoyer le bon nombre d'horaires int loopCount = 0; // Limiter le nombre d'itrations DateTime after = null; // Dernier horaire charg do { schedules = getSchedules(contentResolver, arret, date, after); for (final Horaire schedule : schedules) { if (schedule.getHoraire().isAfter(now) || schedule.getHoraire().isEqual(now)) { nextSchedules.add(schedule); if (++schedulesCount >= limit) { break; } } } if (schedules.size() > 0) after = new DateTime(schedules.get(schedules.size() - 1).getHoraire()); else after = null; date = date.plusDays(1); loopCount++; } while ((loopCount < 2) && (nextSchedules.size() < limit)); return nextSchedules; }
From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentForFirstTimeStudents.java
License:Open Source License
private DateMidnight getWhenStartToApplyPenalty(final Event event, final DateTime when) { final GratuityEvent gratuityEvent = (GratuityEvent) event; final DateMidnight startDate = gratuityEvent.getRegistration().getStartDate().toDateMidnight(); return startDate.plusDays(getNumberOfDaysToStartApplyingPenalty()).plusMonths(1).withDayOfMonth(1); }
From source file:org.apereo.portal.events.aggr.PortalEventDimensionPopulatorImpl.java
License:Apache License
final void doPopulateDateDimensions(final DateMidnight start, final DateMidnight end) { logger.info("Populating DateDimensions between {} and {}", start, end); final List<QuarterDetail> quartersDetails = this.eventAggregationManagementDao.getQuartersDetails(); final List<AcademicTermDetail> academicTermDetails = this.eventAggregationManagementDao .getAcademicTermDetails();//from w w w . j a v a 2 s. c o m final List<DateDimension> dateDimensions = this.dateDimensionDao.getDateDimensionsBetween(start, end); DateMidnight nextDate = start; for (final DateDimension dateDimension : dateDimensions) { DateMidnight dimensionDate = dateDimension.getDate(); if (nextDate.isBefore(dimensionDate)) { do { checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, nextDate); nextDate = nextDate.plusDays(1); } while (nextDate.isBefore(dimensionDate)); } else if (nextDate.isAfter(dimensionDate)) { do { checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, dimensionDate); dimensionDate = dimensionDate.plusDays(1); } while (nextDate.isAfter(dimensionDate)); } nextDate = dimensionDate.plusDays(1); } //Add any missing dates from the tail while (nextDate.isBefore(end)) { checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, nextDate); nextDate = nextDate.plusDays(1); } }
From source file:org.apereo.portal.portlets.statistics.BaseStatisticsReportController.java
License:Apache License
/** Build the aggregation {@link DataTable} */ protected final DataTable buildAggregationReport(F form) throws TypeMismatchException { //Pull data out of form for per-group fetching final AggregationInterval interval = form.getInterval(); final DateMidnight start = form.getStart(); final DateMidnight end = form.getEnd(); final DateTime startDateTime = start.toDateTime(); //Use a query end of the end date at 23:59:59 final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1); //Get the list of DateTimes used on the X axis in the report final List<DateTime> reportTimes = this.intervalHelper.getIntervalStartDateTimesBetween(interval, startDateTime, endDateTime, maxIntervals); final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form); //Determine the ValueType of the date/time column. Use the most specific column type possible final ValueType dateTimeColumnType; if (interval.isHasTimePart()) { //If start/end are the same day just display the time if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) { dateTimeColumnType = ValueType.TIMEOFDAY; }/*w w w . j a v a 2 s .c o m*/ //interval has time data and start/end are on different days, show full date time else { dateTimeColumnType = ValueType.DATETIME; } } //interval is date only else { dateTimeColumnType = ValueType.DATE; } //Setup the date/time column description final ColumnDescription dateTimeColumn; switch (dateTimeColumnType) { case TIMEOFDAY: { dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time"); break; } default: { dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date"); } } final DataTable table = new JsonDataTable(); table.addColumn(dateTimeColumn); //Setup columns in the DataTable final Set<D> columnGroups = groupedAggregations.keySet(); for (final D columnMapping : columnGroups) { final Collection<ColumnDescription> columnDescriptions = this.getColumnDescriptions(columnMapping, form); table.addColumns(columnDescriptions); } //Query for all aggregation data in the time range for all groups. Only the //interval and discriminator data is used from the keys. final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form); final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao(); final Collection<T> aggregations = baseAggregationDao.getAggregations(startDateTime, endDateTime, keys, extractGroupsArray(columnGroups)); //Organize the results by group and sort them chronologically by adding them to the sorted set for (final T aggregation : aggregations) { final D discriminator = aggregation.getAggregationDiscriminator(); final SortedSet<T> results = groupedAggregations.get(discriminator); results.add(aggregation); } //Build Map from discriminator column mapping to result iterator to allow putting results into //the correct column AND the correct time slot in the column Comparator<? super D> comparator = getDiscriminatorComparator(); final Map<D, PeekingIterator<T>> groupedAggregationIterators = new TreeMap<D, PeekingIterator<T>>( (comparator)); for (final Entry<D, SortedSet<T>> groupedAggregationEntry : groupedAggregations.entrySet()) { groupedAggregationIterators.put(groupedAggregationEntry.getKey(), Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator())); } /* * populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the * query range. Then the iterator */ for (final DateTime rowTime : reportTimes) { // create the row final TableRow row = new TableRow(); // add the date to the first cell final Value dateTimeValue; switch (dateTimeColumnType) { case DATE: { dateTimeValue = new DateValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth()); break; } case TIMEOFDAY: { dateTimeValue = new TimeOfDayValue(rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0); break; } default: { dateTimeValue = new DateTimeValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth(), rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0, 0); break; } } row.addCell(new TableCell(dateTimeValue)); for (final PeekingIterator<T> groupedAggregationIteratorEntry : groupedAggregationIterators.values()) { List<Value> values = null; if (groupedAggregationIteratorEntry.hasNext()) { final T aggr = groupedAggregationIteratorEntry.peek(); if (rowTime.equals(aggr.getDateTime())) { //Data is for the correct time slot, advance the iterator groupedAggregationIteratorEntry.next(); values = createRowValues(aggr, form); } } //Gap in the data, fill it in using a null aggregation if (values == null) { values = createRowValues(null, form); } //Add the values to the row for (final Value value : values) { row.addCell(value); } } table.addRow(row); } return table; }
From source file:org.apereo.portal.portlets.statistics.StatisticsPortletController.java
License:Apache License
@ResourceMapping("intervalCount") public ModelAndView getIntervalCount(@RequestParam("interval") AggregationInterval interval, @RequestParam("start") DateMidnight start, @RequestParam("end") DateMidnight end) throws TypeMismatchException { final int intervalsBetween = this.intervalHelper.intervalsBetween(interval, start.toDateTime(), end.plusDays(1).toDateTime().minusSeconds(1)); return new ModelAndView("json", "intervalsBetween", intervalsBetween); }