final DateTime input = new DateTime(); System.out.println(input); final DateMidnight startOfLastWeek = new DateMidnight(input.minusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY)); System.out.println(startOfLastWeek); final DateMidnight endOfLastWeek = startOfLastWeek.plusDays(6); System.out.println(endOfLastWeek);
final DateTime input = new DateTime(); System.out.println(input); final DateMidnight startOfLastWeek = new DateMidnight(input.minusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY)); System.out.println(startOfLastWeek); final DateMidnight endOfLastWeek = startOfLastWeek.plusDays(6); System.out.println(endOfLastWeek);
private String calculateGenericDate(String value1, String value2) { DateMidnight dm = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime()); DateTimeFormatter fmt = ISODateTimeFormat.date(); switch (op) { case PLUS: { dm = dm.plusDays(Double.valueOf(value2).intValue()); return fmt.print(dm); } case MINUS: { dm = dm.minusDays(Double.valueOf(value2).intValue()); return fmt.print(dm); } default: return null; // Bad operator! } }
@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); } }
private void addCalendarHead() { WebMarkupContainer calendarHead = new WebMarkupContainer("calendarHead"); calendar.add(calendarHead); RepeatingView dayHeads = new RepeatingView("dayHead"); calendarHead.add(dayHeads); final DateTimeFormatter dayOfWeekFormatter = DateTimeFormat.forPattern("E"); for(int i=0; i<7; i++) dayHeads.add(new Label(""+i, dayOfWeekFormatter.print(model.getWeek().getFirstDay().plusDays(i)))); }
public Absence(Person person, Period period, EventType eventType, AbsenceTimeConfiguration absenceTimeConfiguration) { Assert.notNull(person, "Person must be given"); Assert.notNull(period, "Period must be given"); Assert.notNull(eventType, "Type of absence must be given"); Assert.notNull(absenceTimeConfiguration, "Time configuration must be given"); this.person = person; this.eventType = eventType; long startDateInMilliseconds = period.getStartDate().toDateTime(DateTimeZone.UTC).getMillis(); long endDateInMilliseconds = period.getEndDate().toDateTime(DateTimeZone.UTC).getMillis(); switch (period.getDayLength()) { case FULL: this.startDate = new Date(startDateInMilliseconds); this.endDate = new Date(period.getEndDate().plusDays(1).toDateTime(DateTimeZone.UTC).getMillis()); this.isAllDay = true; break; case MORNING: this.startDate = new Date(startDateInMilliseconds + absenceTimeConfiguration.getMorningStartAsMillis()); this.endDate = new Date(endDateInMilliseconds + absenceTimeConfiguration.getMorningEndAsMillis()); this.isAllDay = false; break; case NOON: this.startDate = new Date(startDateInMilliseconds + absenceTimeConfiguration.getNoonStartAsMillis()); this.endDate = new Date(endDateInMilliseconds + absenceTimeConfiguration.getNoonEndAsMillis()); this.isAllDay = false; break; default: throw new IllegalArgumentException("Invalid day length!"); } }
/** * Fetch an {@link AvailabilityList} for the given person on all days in the given period of time. */ public AvailabilityList getPersonsAvailabilities(DateMidnight startDate, DateMidnight endDate, Person person) { List<DayAvailability> availabilities = new ArrayList<>(); DateMidnight currentDay = startDate; while (!currentDay.isAfter(endDate)) { TimedAbsenceSpans absences = freeTimeAbsenceProvider.checkForAbsence(person, currentDay); BigDecimal presenceRatio = absences.calculatePresenceRatio(); availabilities.add(new DayAvailability(presenceRatio, currentDay.toString("yyyy-MM-dd"), absences)); currentDay = currentDay.plusDays(1); } return new AvailabilityList(availabilities, person); } }
private List<DayAbsence> getSickNotes(DateMidnight start, DateMidnight end, Person person) { List<DayAbsence> absences = new ArrayList<>(); List<SickNote> sickNotes = sickNoteService.getByPersonAndPeriod(person, start, end) .stream() .filter(SickNote::isActive) .collect(Collectors.toList()); for (SickNote sickNote : sickNotes) { DateMidnight startDate = sickNote.getStartDate(); DateMidnight endDate = sickNote.getEndDate(); DateMidnight day = startDate; while (!day.isAfter(endDate)) { if (!day.isBefore(start) && !day.isAfter(end)) { absences.add(new DayAbsence(day, sickNote.getDayLength(), DayAbsence.Type.SICK_NOTE, "ACTIVE", sickNote.getId())); } day = day.plusDays(1); } } return absences; } }
@Test public void isOccurrence() { long startTime = System.currentTimeMillis(); assertTrue(isOccurrence(new DateMidnight(2010, 1, 10), 3, new DateTime(2010, 1, 19, 0, 0))); assertFalse(isOccurrence(new DateMidnight(2010, 1, 10), 3, new DateTime(2010, 1, 18, 0, 0))); assertTrue(isOccurrence(new DateMidnight(2010, 1, 10), 3, new DateTime(2310, 1, 19, 0, 0))); assertFalse(isOccurrence(new DateMidnight(2010, 1, 10), 3, new DateTime(2310, 1, 20, 0, 0))); assertTrue(isOccurrence(new DateMidnight(2010, 1, 10), 3, new DateTime(2010, 1, 10, 0, 0))); System.out.println("elapsed=" + (System.currentTimeMillis() - startTime)); } public boolean isOccurrence(DateMidnight startDate, int dayIncrement, DateTime testTime) { DateMidnight testDateMidnight = testTime.toDateMidnight(); while (startDate.isBefore(testDateMidnight)) { startDate = startDate.plusDays(dayIncrement); } return startDate.equals(testDateMidnight); }
checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, nextDate); nextDate = nextDate.plusDays(1); } while (nextDate.isBefore(dimensionDate)); } else if (nextDate.isAfter(dimensionDate)) { checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, dimensionDate); dimensionDate = dimensionDate.plusDays(1); } while (nextDate.isAfter(dimensionDate)); nextDate = dimensionDate.plusDays(1); checkShutdown(); createDateDimension(quartersDetails, academicTermDetails, nextDate); nextDate = nextDate.plusDays(1);
private List<DayAbsence> getVacations(DateMidnight start, DateMidnight end, Person person) { List<DayAbsence> absences = new ArrayList<>(); List<Application> applications = applicationService.getApplicationsForACertainPeriodAndPerson(start, end, person) .stream() .filter(application -> application.hasStatus(ApplicationStatus.WAITING) || application.hasStatus(ApplicationStatus.TEMPORARY_ALLOWED) || application.hasStatus(ApplicationStatus.ALLOWED)) .collect(Collectors.toList()); for (Application application : applications) { DateMidnight startDate = application.getStartDate(); DateMidnight endDate = application.getEndDate(); DateMidnight day = startDate; while (!day.isAfter(endDate)) { if (!day.isBefore(start) && !day.isAfter(end)) { absences.add(new DayAbsence(day, application.getDayLength(), DayAbsence.Type.VACATION, application.getStatus().name(), application.getId())); } day = day.plusDays(1); } } return absences; }
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); }
/** * Note: the start date must be before or equal the end date; this is validated prior to that method * * <p>This method calculates how many weekdays are between declared start date and end date (official holidays are * ignored here)</p> * * @param startDate * @param endDate * * @return number of weekdays */ public double getWeekDays(DateMidnight startDate, DateMidnight endDate) { double workDays = 0.0; if (!startDate.equals(endDate)) { DateMidnight day = startDate; while (!day.isAfter(endDate)) { if (DateUtil.isWorkDay(day)) { workDays++; } day = day.plusDays(1); } } else { if (DateUtil.isWorkDay(startDate)) { workDays++; } } return workDays; }
@Override protected List<Predicate> getPredicates(Root<T> root, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(createLikePredicate("bwmetaId", query.getBwmetaId(), root, cb)); predicates.add(createLikePredicate("doi", query.getDoi(), root, cb)); predicates.add(createLikePredicate("eissn", query.getEissn(), root, cb)); predicates.add(createLikePredicate("issn", query.getIssn(), root, cb)); predicates.add(createLikePredicate("isbn", query.getIsbn(), root, cb)); predicates.add(createLikePredicate("eisbn", query.getEisbn(), root, cb)); predicates.add(createEqualsPredicate("contentType", query.getContentType(), root, cb)); AccessType accessType = query.getOpenAccess() != null ? (query.getOpenAccess() ? AccessType.OPEN_ACCESS : AccessType.LICENSED) : null; predicates.add(createEqualsPredicate("accessType", accessType, root, cb)); predicates.add(createEqualsPredicate("ip", query.getIp(), root, cb)); predicates.add(createEqualsPredicate("sessionId", query.getSessionId(), root, cb)); predicates.add(createGreaterThanPredicate("downloadDate", query.getDateFrom(), root, cb)); if(query.getDateTo() != null){ DateMidnight date = new DateMidnight(query.getDateTo()); date = date.plusDays(1); predicates.add(createLessThanPredicate("downloadDate", date.toDate(), root, cb)); } predicates.add(createInPredicate("collection.id", query.getCollectionIds(), root, cb)); predicates.add(createInPredicate("organisation.id", query.getOrganisationIds(), root, cb)); predicates.add(createInPredicate("organisationGroup.id", query.getOrganisationGroupIds(), root, cb)); return predicates; }
@Override public List<SickNote> getSickNotesReachingEndOfSickPay() { Settings settings = settingsService.getSettings(); AbsenceSettings absenceSettings = settings.getAbsenceSettings(); DateMidnight endDate = DateMidnight.now().plusDays(absenceSettings.getDaysBeforeEndOfSickPayNotification()); return sickNoteDAO.findSickNotesByMinimumLengthAndEndDate(absenceSettings.getMaximumSickPayDays(), endDate.toDate()); } }
/** * Check if the two given intervals have a gap or if they abut. * * <p>Some examples:</p> * * <p>(1) period 16.-18. and period 19.-20. --> they abut</p> * * <p>(2) period 16.-18. and period 20.-22. --> they have a gap</p> * * @param firstInterval * @param secondInterval * * @return {@code true} if they have a gap between or {@code false} if they have no gap */ private boolean intervalsHaveGap(Interval firstInterval, Interval secondInterval) { // test if end of interval is equals resp. one day plus of start of other interval DateMidnight endOfFirstInterval = firstInterval.getEnd().toDateMidnight(); DateMidnight startOfSecondInterval = secondInterval.getStart().toDateMidnight(); return !(endOfFirstInterval.equals(startOfSecondInterval) || endOfFirstInterval.plusDays(1).equals(startOfSecondInterval)); } }
private Predicate<Application> isLongWaitingApplications() { return application -> { DateMidnight remindDate = application.getRemindDate(); if (remindDate == null) { Integer daysBeforeRemindForWaitingApplications = settingsService.getSettings().getAbsenceSettings().getDaysBeforeRemindForWaitingApplications(); // never reminded before DateMidnight minDateForNotification = application.getApplicationDate() .plusDays(daysBeforeRemindForWaitingApplications); // true -> remind! // false -> to early for notification return minDateForNotification.isBeforeNow(); } else { // true -> not reminded today // false -> already reminded today return !remindDate.isEqual(DateMidnight.now()); } }; } }
@Override public Application remind(Application application) throws RemindAlreadySentException, ImpatientAboutApplicationForLeaveProcessException { DateMidnight remindDate = application.getRemindDate(); if (remindDate == null) { DateMidnight minDateForNotification = application.getApplicationDate() .plusDays(MIN_DAYS_LEFT_BEFORE_REMINDING_IS_POSSIBLE); if (minDateForNotification.isAfterNow()) { throw new ImpatientAboutApplicationForLeaveProcessException("It's too early to remind the bosses!"); } } if (remindDate != null && remindDate.isEqual(DateMidnight.now())) { throw new RemindAlreadySentException("Reminding is possible maximum one time per day!"); } mailService.sendRemindBossNotification(application); application.setRemindDate(DateMidnight.now()); applicationService.save(application); return application; }
Date to = new DateMidnight(dateValue).plusDays(1).toDate();
private void validateAUPeriod(SickNote sickNote, Errors errors) { DayLength dayLength = sickNote.getDayLength(); DateMidnight aubStartDate = sickNote.getAubStartDate(); DateMidnight aubEndDate = sickNote.getAubEndDate(); validateNotNull(aubStartDate, ATTRIBUTE_AUB_START_DATE, errors); validateNotNull(aubEndDate, ATTRIBUTE_AUB_END_DATE, errors); if (aubStartDate != null && aubEndDate != null) { validatePeriod(aubStartDate, aubEndDate, dayLength, ATTRIBUTE_AUB_END_DATE, errors); DateMidnight startDate = sickNote.getStartDate(); DateMidnight endDate = sickNote.getEndDate(); if (startDate != null && endDate != null && endDate.isAfter(startDate)) { // Intervals are inclusive of the start instant and exclusive of the end, i.e. add one day at the end Interval interval = new Interval(startDate, endDate.plusDays(1)); if (!interval.contains(aubStartDate)) { errors.rejectValue(ATTRIBUTE_AUB_START_DATE, ERROR_PERIOD_SICK_NOTE); } if (!interval.contains(aubEndDate)) { errors.rejectValue(ATTRIBUTE_AUB_END_DATE, ERROR_PERIOD_SICK_NOTE); } } } }