List of usage examples for org.joda.time DateMidnight plusWeeks
public DateMidnight plusWeeks(int weeks)
From source file:com.manydesigns.portofino.calendar.AbstractMonthView.java
License:Open Source License
public AbstractMonthView(DateTime referenceDateTime, int firstDayOfWeek) { logger.debug("Initializing month"); this.referenceDateTime = referenceDateTime; logger.debug("Reference date time: {}", referenceDateTime); this.firstDayOfWeek = firstDayOfWeek; logger.debug("First day of week: {}", firstDayOfWeek); referenceDateMidnight = new DateMidnight(referenceDateTime); referenceYear = referenceDateTime.getYear(); referenceMonth = referenceDateTime.getMonthOfYear(); monthStart = referenceDateMidnight.withDayOfMonth(1); monthEnd = monthStart.plusMonths(1); monthInterval = new Interval(monthStart, monthEnd); monthViewStart = monthStart.withDayOfWeek(firstDayOfWeek); monthViewEnd = monthViewStart.plusWeeks(6); monthViewInterval = new Interval(monthViewStart, monthViewEnd); logger.debug("Month view start: {}", monthViewStart); logger.debug("Initializing weeks"); weeks = createWeeksArray(6);/*from ww w.ja v a2 s. c o m*/ DateMidnight weekStart = monthViewStart; for (int i = 0; i < weeks.length; i++) { DateMidnight weekEnd = weekStart.plusWeeks(1); weeks[i] = createWeek(weekStart, weekEnd); weekStart = weekEnd; } }
From source file:dk.teachus.backend.domain.impl.PeriodsImpl.java
License:Apache License
public List<DatePeriod> generateDates(DateMidnight weekDate, int numberOfDays, boolean explicitNumberOfDays) { weekDate = weekDate.withDayOfWeek(DateTimeConstants.MONDAY); List<DatePeriod> dates = new ArrayList<DatePeriod>(); List<DatePeriod> weekDates = generateDatesForWeek(weekDate); if (numberOfDays > 0) { do {/*from w w w. j av a 2 s. c o m*/ for (DatePeriod datePeriod : weekDates) { dates.add(datePeriod); if (explicitNumberOfDays) { if (dates.size() >= numberOfDays) { break; } } } weekDate = weekDate.plusWeeks(1); weekDates = generateDatesForWeek(weekDate); } while (dates.size() + weekDates.size() <= numberOfDays && hasPeriodAfter(weekDate)); } return dates; }
From source file:dk.teachus.backend.testdatagenerator.DynamicDataImport.java
License:Apache License
private void createBookings(Teacher teacher, DateMidnight startDate, DateMidnight endDate) { Session session = sessionFactory.openSession(); session.beginTransaction();/* ww w . jav a2 s.c o m*/ Set<DateTime> bookedDates = new HashSet<DateTime>(); List<Pupil> pupils = getPupils(teacher, session); List<Period> periods = getPeriods(teacher, session); DateTime now = new DateTime(); for (Pupil pupil : pupils) { DateMidnight date = startDate; while (date.isBefore(endDate)) { // First see if the pupil should have a booking here at all long shouldBook = Math.round(Math.random()); if (shouldBook == 1) { // Then find out which period to book in int periodIndex = (int) (Math.random() * periods.size()); Period period = periods.get(periodIndex); log.debug("Booking lesson for period: " + period.getName()); // Then find out which day in the period to book in int weekDayIndex = (int) (Math.random() * period.getWeekDays().size()); WeekDay weekDay = period.getWeekDays().get(weekDayIndex); DateMidnight weekDayDate = date.withDayOfWeek(weekDay.getYodaWeekDay()); // Now find out which time of day to use // We do that by listing the possible booking time entries. A lesson doesn't have to start at a whole number. List<DateTime> avaiableLessonsStart = new ArrayList<DateTime>(); DateTime bookTime = period.getStartTime().toDateTime(weekDayDate); DateTime et = period.getEndTime().toDateTime(weekDayDate); while (bookTime.isBefore(et)) { if (period.mayBook(bookTime)) { avaiableLessonsStart.add(bookTime); } bookTime = bookTime.plusMinutes(period.getIntervalBetweenLessonStart()); } int selectedIndex = (int) Math.round(Math.random() * (avaiableLessonsStart.size() - 1)); log.debug("Selected lesson number " + selectedIndex + " out of " + avaiableLessonsStart.size()); bookTime = avaiableLessonsStart.get(selectedIndex); if (bookedDates.contains(bookTime) == false) { bookedDates.add(bookTime); // Create booking PupilBooking booking = new PupilBookingImpl(); booking.setCreateDate(new DateTime()); booking.setDate(bookTime); booking.setPeriod(period); booking.setTeacher(teacher); booking.setPupil(pupil); booking.setNotificationSent(true); booking.setPupilNotificationSent(true); // Set the paid based on the booking time is in the past if (now.isAfter(bookTime)) { // If it's within a month, then give it a 40% change of not have been paid if (now.minusMonths(1).isBefore(bookTime)) { int pct = (int) (Math.random() * 100.0); if (pct >= 40) { booking.setPaid(true); } } else { booking.setPaid(true); } } // Book session.save(booking); } } date = date.plusWeeks(1); } } session.getTransaction().commit(); session.close(); }
From source file:net.sourceforge.fenixedu.domain.Attends.java
License:Open Source License
public Interval getCurrentWeek() { final DateMidnight beginningOfSemester = new DateMidnight(getBegginingOfLessonPeriod()); final DateMidnight firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final int currentWeek = calculateCurrentWeekOffset(); final DateMidnight start = firstMonday.plusWeeks(currentWeek); return new Interval(start, start.plusWeeks(1)); }
From source file:net.sourceforge.fenixedu.domain.Attends.java
License:Open Source License
public Interval getResponseWeek() { final DateMidnight beginningOfSemester = new DateMidnight(getBegginingOfLessonPeriod()); final DateMidnight firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight secondMonday = firstMonday.plusWeeks(1); final DateMidnight endOfSemester = new DateMidnight(getEndOfExamsPeriod()); final DateMidnight lastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight endOfResponsePeriod = lastMonday.plusWeeks(2); return (secondMonday.isEqualNow() || secondMonday.isBeforeNow()) && endOfResponsePeriod.isAfterNow() ? getPreviousWeek()//from w w w.jav a 2s. c o m : null; }
From source file:net.sourceforge.fenixedu.domain.ExecutionSemester.java
License:Open Source License
public Interval getCurrentWeek() { final DateMidnight thisMonday = getThisMonday(); return thisMonday == null ? null : new Interval(thisMonday, thisMonday.plusWeeks(1)); }
From source file:se.streamsource.streamflow.client.ui.workspace.table.PerspectivePeriodModel.java
License:Apache License
private String getSearchPeriod(Date fromDate, int direction, String periodName, String datePattern, String separator) {// ww w.java2s . c o m DateMidnight from = new DateMidnight(fromDate); DateMidnight to = null; DateTimeFormatter format = DateTimeFormat.forPattern(datePattern); switch (Period.valueOf(periodName)) { case one_day: return format.print(from); case three_days: to = (direction == 1) ? from.plusDays(2) : from.minusDays(2); break; case one_week: to = (direction == 1) ? from.plusWeeks(1).minusDays(1) : from.minusWeeks(1).plusDays(1); break; case two_weeks: to = (direction == 1) ? from.plusWeeks(2).minusDays(1) : from.minusWeeks(2).plusDays(1); break; case one_month: to = (direction == 1) ? from.plusMonths(1).minusDays(1) : from.minusMonths(1).plusDays(1); break; case six_months: to = (direction == 1) ? from.plusMonths(6).minusDays(1) : from.minusMonths(6).plusDays(1); break; case one_year: to = (direction == 1) ? from.plusYears(1).minusDays(1) : from.minusYears(1).plusDays(1); break; } return (direction == 1) ? format.print(from) + separator + format.print(to) : format.print(to) + separator + format.print(from); }