if (!clockings.isEmpty()) { dailyBalance = workSchedule.calculateWorkingPeriods(day, timeline, getLeavesByType(leaves, JustificationType.TIME));
List<Leave> timeLeaves = getLeavesByType(leaves, JustificationType.TIME); if (!clockings.isEmpty() || !timeLeaves.isEmpty()) { dailyBalance = workSchedule.calculateWorkingPeriods(day, timeline, timeLeaves);
    public DailyBalance calculateDailyBalance(YearMonthDay day) {        Schedule schedule = getSchedule(day);        DailyBalance dailyBalance = null;        List<Leave> leaves = getLeaves(day);        Collections.sort(leaves, new BeanComparator("date"));        Iterator<AttributeType> attributesIt = DomainConstants.WORKED_ATTRIBUTES.getAttributes()                .iterator();        if (schedule != null) {            WorkSchedule workSchedule = schedule.workScheduleWithDate(day);            boolean isDayHoliday = isHoliday(day);            if (workSchedule != null && !isDayHoliday) {                Timeline timeline = new Timeline(workSchedule.getWorkScheduleType());                DateTime init = day.toDateTime(workSchedule.getWorkScheduleType().getWorkTime());                DateTime end = day.toDateTime(workSchedule.getWorkScheduleType().getWorkEndTime());                if (workSchedule.getWorkScheduleType().isWorkTimeNextDay()) {                    end = end.plusDays(1);                }                List<AssiduousnessRecord> clockings = getClockingsAndMissingClockings(init, end);                Collections.sort(clockings, new BeanComparator("date"));                List<Leave> dayOccurrences = getLeavesByType(leaves, JustificationType.OCCURRENCE);                if (!dayOccurrences.isEmpty()) {                    dailyBalance = new DailyBalance(day, workSchedule);                    dailyBalance.setWorkedOnNormalWorkPeriod(workSchedule.getWorkScheduleType()                            .getNormalWorkPeriod().getWorkPeriodDuration());                    dailyBalance.setJustification(true); // ver o tipo de justificacao                    dailyBalance.setComment(dayOccurrences.get(0).getJustificationMotive().getAcronym());                } else {                    timeline.plotListInTimeline(clockings, leaves, attributesIt, day);                    if (!clockings.isEmpty()) {                        dailyBalance = workSchedule.calculateWorkingPeriods(day, timeline,                                getLeavesByType(leaves, JustificationType.TIME));                    }                    if (dailyBalance == null) {                        dailyBalance = new DailyBalance(day, workSchedule);                    }                    dailyBalance.discountBalanceLeaveInFixedPeriod(getLeavesByType(leaves,                            JustificationType.BALANCE));                }            } else {                dailyBalance = new DailyBalance(day, null);                Duration worked = new Duration(0);                day.toDateMidnight().getDayOfWeek();                WeekDay dayOfWeek = WeekDay.fromJodaTimeToWeekDay(day.toDateTimeAtMidnight());                EnumSet<WeekDay> enumSetWeekDay = EnumSet.range(WeekDay.MONDAY, WeekDay.FRIDAY);                List<AssiduousnessRecord> clockings = getClockingsAndMissingClockings(day                        .toDateTimeAtMidnight(), day.toDateTimeAtMidnight().plusDays(1));                if (enumSetWeekDay.contains(dayOfWeek) && !isDayHoliday && !clockings.isEmpty()) {                    Collections.sort(clockings, new BeanComparator("date"));                    Timeline timeline = new Timeline(day);                    timeline.plotListInTimeline(clockings, leaves, attributesIt, day);                    worked = timeline.calculateDurationAllIntervalsByAttributes(                            DomainConstants.WORKED_ATTRIBUTES, new TimePoint(new TimeOfDay(7, 30, 0, 0),                                    AttributeType.NULL), new TimePoint(new TimeOfDay(23, 59, 59, 99),                                    AttributeType.NULL));                    dailyBalance.setTotalBalance(worked);                } else {                    dailyBalance.setTotalBalance(new Duration(0));                }            }        } else {            dailyBalance = new DailyBalance(day, null);            dailyBalance.setTotalBalance(new Duration(0));        }        return dailyBalance;    }