Interval dayBeforeWorkTimeInterval = new Interval(beginDayBeforeWorkTime, endDayBeforeWorkTime); if (!dayBeforeWorkTimeInterval.contains(clocking)) { return false; } } else if (thisDaySchedule != null && dayBeforeSchedule != null) { DateTime beginThisDayWorkTime = clocking.toYearMonthDay().toDateTime( thisDaySchedule.getWorkScheduleType().getWorkTime()); DateTime endThisDayWorkTime = clocking.toYearMonthDay().toDateTime( thisDaySchedule.getWorkScheduleType().getWorkEndTime()); if (thisDaySchedule.getWorkScheduleType().isWorkTimeNextDay()) { endThisDayWorkTime = endThisDayWorkTime.plusDays(1); } Interval thisDayWorkTimeInterval = new Interval(beginThisDayWorkTime, endThisDayWorkTime);  DateTime beginDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime( dayBeforeSchedule.getWorkScheduleType().getWorkTime()).minusDays(1); DateTime endDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime( dayBeforeSchedule.getWorkScheduleType().getWorkEndTime()).minusDays(1); if (dayBeforeSchedule.getWorkScheduleType().isWorkTimeNextDay()) { endDayBeforeWorkTime = endDayBeforeWorkTime.plusDays(1); }  Interval nextDayWorkTimeInterval = new Interval(beginDayBeforeWorkTime, endDayBeforeWorkTime);  if (!thisDayWorkTimeInterval.overlaps(nextDayWorkTimeInterval)) { return false; }
dayBeforeWorkTimeInterval = new Interval(beginDayBeforeWorkTime, endDayBeforeWorkTime); } Interval overlapResult = thisDayWorkTimeInterval.overlap(dayBeforeWorkTimeInterval); if (overlapResult == null || (!overlapResult.contains(clocking) && clocking.isAfter(overlapResult.getStart()))) { return false;
    private boolean overlapsSchedule(DateTime clocking,            HashMap<YearMonthDay, WorkSchedule> workScheduleMap) {        WorkSchedule thisDaySchedule = workScheduleMap.get(clocking.toYearMonthDay());        WorkSchedule dayBeforeSchedule = workScheduleMap.get(clocking.toYearMonthDay().minusDays(1));        if (thisDaySchedule == null && dayBeforeSchedule != null) {            DateTime beginDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime(                    dayBeforeSchedule.getWorkScheduleType().getWorkTime()).minusDays(1);            DateTime endDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime(                    dayBeforeSchedule.getWorkScheduleType().getWorkEndTime()).minusDays(1);            if (dayBeforeSchedule.getWorkScheduleType().isWorkTimeNextDay()) {                endDayBeforeWorkTime = endDayBeforeWorkTime.plusDays(1);            }            Interval dayBeforeWorkTimeInterval = new Interval(beginDayBeforeWorkTime,                    endDayBeforeWorkTime);            if (!dayBeforeWorkTimeInterval.contains(clocking)) {                return false;            }        } else if (thisDaySchedule != null && dayBeforeSchedule != null) {            DateTime beginThisDayWorkTime = clocking.toYearMonthDay().toDateTime(                    thisDaySchedule.getWorkScheduleType().getWorkTime());            DateTime endThisDayWorkTime = clocking.toYearMonthDay().toDateTime(                    thisDaySchedule.getWorkScheduleType().getWorkEndTime());            if (thisDaySchedule.getWorkScheduleType().isWorkTimeNextDay()) {                endThisDayWorkTime = endThisDayWorkTime.plusDays(1);            }            Interval thisDayWorkTimeInterval = new Interval(beginThisDayWorkTime, endThisDayWorkTime);            DateTime beginDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime(                    dayBeforeSchedule.getWorkScheduleType().getWorkTime()).minusDays(1);            DateTime endDayBeforeWorkTime = clocking.toYearMonthDay().toDateTime(                    dayBeforeSchedule.getWorkScheduleType().getWorkEndTime()).minusDays(1);            if (dayBeforeSchedule.getWorkScheduleType().isWorkTimeNextDay()) {                endDayBeforeWorkTime = endDayBeforeWorkTime.plusDays(1);            }            Interval nextDayWorkTimeInterval = new Interval(beginDayBeforeWorkTime, endDayBeforeWorkTime);            if (!thisDayWorkTimeInterval.overlaps(nextDayWorkTimeInterval)) {                return false;            }        }        return true;    }