public FilterPeriod(DateMidnight startDate, DateMidnight endDate) { Assert.notNull(startDate, "Start date must be given"); Assert.notNull(endDate, "End date must be given"); Assert.isTrue(endDate.isAfter(startDate) || endDate.isEqual(startDate), "Start date must be before end date"); this.startDate = startDate; this.endDate = endDate; }
public Period(DateMidnight startDate, DateMidnight endDate, DayLength dayLength) { Assert.notNull(startDate, "Start date must be given"); Assert.notNull(endDate, "End date must be given"); Assert.notNull(dayLength, "Day length must be given"); Assert.isTrue(!dayLength.equals(DayLength.ZERO), "Day length may not be zero"); boolean isFullDay = dayLength.equals(DayLength.FULL); if (isFullDay && startDate.isAfter(endDate)) { throw new IllegalArgumentException("Start date must be before end date"); } boolean isHalfDay = dayLength.equals(DayLength.MORNING) || dayLength.equals(DayLength.NOON); if (isHalfDay && !startDate.isEqual(endDate)) { throw new IllegalArgumentException("Start and end date must be same for half day length"); } this.startDate = startDate; this.endDate = endDate; this.dayLength = dayLength; }
public FilterPeriod(Optional<String> startDateAsString, Optional<String> endDateAsString) { Assert.notNull(startDateAsString, "Start date must be given"); Assert.notNull(endDateAsString, "End date must be given"); // Set default values for dates int currentYear = DateMidnight.now().getYear(); this.startDate = DateUtil.getFirstDayOfYear(currentYear); this.endDate = DateUtil.getLastDayOfYear(currentYear); // Override default values with parsed dates DateTimeFormatter formatter = DateTimeFormat.forPattern(DateFormat.PATTERN); if (startDateAsString.isPresent()) { this.startDate = DateMidnight.parse(startDateAsString.get(), formatter); } if (endDateAsString.isPresent()) { this.endDate = DateMidnight.parse(endDateAsString.get(), formatter); } Assert.isTrue(endDate.isAfter(startDate) || endDate.isEqual(startDate), "Start date must be before end date"); }
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; } }
private boolean shouldTriggerJobByTime(DateTime currentTime, BillingPeriod billingPeriod) { DateTime dateTimeToFromBillingPeriod = new DateTime(billingPeriod.getTo()).withZone(DateTimeZone.UTC); log.info("Comparing current time[{}, {}] and from scheduler info [{}, {}]", currentTime, currentTime.toDateMidnight(), dateTimeToFromBillingPeriod, dateTimeToFromBillingPeriod.toDateMidnight()); if (currentTime.toDateMidnight().isAfter(dateTimeToFromBillingPeriod.toDateMidnight()) || currentTime.toDateMidnight().isEqual(dateTimeToFromBillingPeriod.toDateMidnight())) { log.info("Should trigger the job by time"); return true; } log.info("Should not trigger the job by time"); return false; }
/** * 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); } }
/** * Validate that the given start date is not after the given end date. * * @param startDate * @param endDate * @param field * @param errors */ private void validatePeriod(DateMidnight startDate, DateMidnight endDate, DayLength dayLength, String field, Errors errors) { if (startDate.isAfter(endDate)) { errors.rejectValue(field, ERROR_PERIOD); } else { boolean isHalfDay = dayLength == DayLength.MORNING || dayLength == DayLength.NOON; if (isHalfDay && !startDate.isEqual(endDate)) { errors.rejectValue(field, ERROR_HALF_DAY_PERIOD_SICK_NOTE); } } }
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; }
DateMidnight endDate = DateMidnight.parse(endDateString); if (startDate.isAfter(endDate)) { throw new IllegalArgumentException("startdate " + startDateString + " must not be after endDate " + endDateString);
private void validatePeriod(DateMidnight startDate, DateMidnight endDate, DayLength dayLength, Settings settings, Errors errors) { // ensure that startDate < endDate if (startDate.isAfter(endDate)) { errors.reject(ERROR_PERIOD); } else { AbsenceSettings absenceSettings = settings.getAbsenceSettings(); validateNotTooFarInTheFuture(endDate, absenceSettings, errors); validateNotTooFarInThePast(startDate, absenceSettings, errors); validateSameDayIfHalfDayPeriod(startDate, endDate, dayLength, errors); } }
private void validateNotTooFarInTheFuture(DateMidnight date, AbsenceSettings settings, Errors errors) { Integer maximumMonths = settings.getMaximumMonthsToApplyForLeaveInAdvance(); DateMidnight future = DateMidnight.now().plusMonths(maximumMonths); if (date.isAfter(future)) { errors.reject(ERROR_TOO_LONG, new Object[] { settings.getMaximumMonthsToApplyForLeaveInAdvance() }, null); } }
public void mapEvent(Map<DateMidnight, List<IEvent>> map, IEvent event, BaseCalendarView calendar) { DateMidnight start = new DateMidnight(event.getStartTime()); DateMidnight end = start; if (event.getEndTime() != null && event.getEndTime().equals(event.getStartTime()) == false) { end = new DateMidnight(event.getEndTime()); } if (end.isAfter(start)) { for (Iterator<DateMidnight> it = new DateMidnightIterator(start.toDateTime(), end.toDateTime()); it.hasNext(); ) { RenderStrategyUtility.addEventToDate(map, it.next(), event); } } else { RenderStrategyUtility.addEventToDate(map, start, event); } } };
if (endDate.isAfter(lastMilestone)) { endDate = lastMilestone;
/** * 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; }
public void mapEvent(Map<DateMidnight, List<IEvent>> map, IEvent event, BaseCalendarView calendar) { DateMidnight start = new DateMidnight(event.getStartTime()); DateMidnight end = start; if (event.getEndTime() != null && event.getEndTime().equals(event.getStartTime()) == false) { end = new DateMidnight(event.getEndTime()); } if (end.isAfter(start)) { for (Iterator<DateMidnight> it = new DateMidnightIterator(start.toDateTime(), end.toDateTime()); it.hasNext();) { RenderStrategyUtility.addEventToDate(map, it.next(), event); } } else { RenderStrategyUtility.addEventToDate(map, start, event); } } };
public void mapEvent(Map<DateMidnight, List<IEvent>> map, IEvent event, BaseCalendarView calendar) { DateMidnight start = new DateMidnight(event.getStartTime()); DateMidnight end = start; if (event.getEndTime() != null && event.getEndTime().equals(event.getStartTime()) == false) { end = new DateMidnight(event.getEndTime()); } if (end.isAfter(start)) { for (Iterator<DateMidnight> it = new DateMidnightIterator(start.toDateTime(), end.toDateTime()); it.hasNext(); ) { DateMidnight date = it.next(); if (date.equals(start) || date.getDayOfWeek() == calendar.getFirstDayOfWeek()) { RenderStrategyUtility.addEventToDate(map, date, event); } } } else { RenderStrategyUtility.addEventToDate(map, start, event); } } };
public void mapEvent(Map<DateMidnight, List<IEvent>> map, IEvent event, BaseCalendarView calendar) { DateMidnight start = new DateMidnight(event.getStartTime()); DateMidnight end = start; if (event.getEndTime() != null && event.getEndTime().equals(event.getStartTime()) == false) { end = new DateMidnight(event.getEndTime()); } if (end.isAfter(start)) { for (Iterator<DateMidnight> it = new DateMidnightIterator(start.toDateTime(), end.toDateTime()); it.hasNext();) { DateMidnight date = it.next(); if (date.equals(start) || date.getDayOfWeek() == calendar.getFirstDayOfWeek()) { RenderStrategyUtility.addEventToDate(map, date, event); } } } else { RenderStrategyUtility.addEventToDate(map, start, event); } } };
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));
void validatePeriod(AccountForm form, Errors errors) { DateMidnight holidaysAccountValidFrom = form.getHolidaysAccountValidFrom(); DateMidnight holidaysAccountValidTo = form.getHolidaysAccountValidTo(); validateDateNotNull(holidaysAccountValidFrom, "holidaysAccountValidFrom", errors); validateDateNotNull(holidaysAccountValidTo, "holidaysAccountValidTo", errors); if (holidaysAccountValidFrom != null && holidaysAccountValidTo != null) { boolean periodIsNotWithinOneYear = holidaysAccountValidFrom.getYear() != form.getHolidaysAccountYear() || holidaysAccountValidTo.getYear() != form.getHolidaysAccountYear(); boolean periodIsOnlyOneDay = holidaysAccountValidFrom.equals(holidaysAccountValidTo); boolean beginOfPeriodIsAfterEndOfPeriod = holidaysAccountValidFrom.isAfter(holidaysAccountValidTo); if (periodIsNotWithinOneYear || periodIsOnlyOneDay || beginOfPeriodIsAfterEndOfPeriod) { errors.reject(ERROR_PERIOD); } } }
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); } } } }