/** * 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)); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof AcademicTermDetail)) return false; AcademicTermDetail other = (AcademicTermDetail) obj; if (getEnd() == null) { if (other.getEnd() != null) return false; } else if (!getEnd().equals(other.getEnd())) return false; if (getStart() == null) { if (other.getStart() != null) return false; } else if (!getStart().equals(other.getStart())) return false; return true; }
public DateMidnight getDateDay() { final DateTime start = interval.getStart(); final DateTime end = interval.getEnd(); final DateMidnight dateMidnight = start.toDateMidnight(); if (dateMidnight.equals(end.toDateMidnight())) { return dateMidnight; } return null; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof DateDimension)) return false; DateDimension other = (DateDimension) obj; if (getDate() == null) { if (other.getDate() != null) return false; } else if (!getDate().equals(other.getDate())) return false; return true; }
@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); }
public String getPresentationInterval() { final DateTime start = interval.getStart(); final DateTime end = interval.getEnd(); final DateMidnight dateMidnight = start.toDateMidnight(); if (dateMidnight.equals(end.toDateMidnight())) { return String.format("%s : %s as %s", dateMidnight.toString(DATE_FORMAT), getTime(start), getTime(end)); } return interval.toString(); }
/** * 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(); ) { 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); } } };
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); } } }
if (interval.isHasTimePart()) { if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) { dateTimeColumnType = ValueType.TIMEOFDAY;
if (hasTimeComponent(date) || !stripTimeComponent(date).equals(stripTimeComponent(previousDate))) { session.getContext().setPreviousEncounterDate( new Date(session.getSubmissionActions().getCurrentEncounter().getEncounterDatetime().getTime()));