class TimelineUtilities {

    static List<DateDurationKey> createWeekDateEntries(TimeSpan span, Map<Duration, List<DateDurationKey>> toChange,
            Duration timeBarDuration)
    {
        Calendar startTimeCal = getStartCalendar(span);
        Calendar endTimeCal = getEndCalendar(span);

        startTimeCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

        int endTimeDay = endTimeCal.get(Calendar.DAY_OF_WEEK);
        if (endTimeDay > Calendar.SUNDAY)
        {
            endTimeCal.add(Calendar.DAY_OF_YEAR, 8 - endTimeDay);
        }

        int totalDaysInDateDurationKey = countDays(startTimeCal, endTimeCal);

        GregorianCalendar nextStart = new GregorianCalendar();
        nextStart.setTime(startTimeCal.getTime());
        List<DateDurationKey> weekDates = new ArrayList<>();
        while (totalDaysInDateDurationKey > 0)
        {
            Set<DateDurationKey> dayDates = new HashSet<>();
            GregorianCalendar currentStart = new GregorianCalendar();
            currentStart.setTime(nextStart.getTime());
            int daysToNextWeek = 7;
            if (daysToNextWeek < totalDaysInDateDurationKey)
            {
                nextStart.add(Calendar.DATE, daysToNextWeek);
            }
            else
            {
                nextStart.add(Calendar.DATE, totalDaysInDateDurationKey);
            }

            dayDates.addAll(createDayDateEntries(TimeSpan.get(currentStart.getTime(), nextStart.getTime()), toChange));

            GregorianCalendar actualEndDay = (GregorianCalendar)nextStart.clone();

            weekDates.add(new DateDurationKey(currentStart.getTime(), actualEndDay.getTime(), Weeks.ONE, dayDates));

            totalDaysInDateDurationKey -= daysToNextWeek;
        }
        List<DateDurationKey> weeks = toChange.get(Weeks.ONE);
        if (weeks == null)
        {
            toChange.put(Weeks.ONE, weekDates);
        }
        else
        {
            weeks.addAll(weekDates);
        }
        return weekDates;
    }

    private  TimelineUtilities();

}