if (thisDaySchedule == null && dayBeforeSchedule != null) {
Interval thisDayWorkTimeInterval = WorkScheduleType .getDefaultWorkTime(clocking.toYearMonthDay()); if (thisDaySchedule != 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); } thisDayWorkTimeInterval = new Interval(beginThisDayWorkTime, endThisDayWorkTime); } Interval dayBeforeWorkTimeInterval = WorkScheduleType.getDefaultWorkTime(clocking .toYearMonthDay().minusDays(1)); if (dayBeforeSchedule != null) {
    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;    }