public boolean addEvent(Date date, DayEvents dayEvents) {

        if (dayEvents.getStartHour() > dayEvents.getEndHour()) {
            return false;
        } //invalid format

        ArrayList<DayEvents> eventList;

        int[] dayEventsHours = new int[24];
        for (int i = 0; i < dayEventsHours.length; i++) {
            dayEventsHours[i] = -1;
        }
        for (int i = dayEvents.getStartHour(); i <= dayEvents.getEndHour(); i++) {
            dayEventsHours[i] = 1;
        }

        // if events for this date already exist, add to that arraylist.
        if (eventsList.containsKey(date)) {
            eventList = eventsList.get(date);
            for (DayEvents e : eventList) {
                for (int i = e.getStartHour(); i <= e.getEndHour(); i++) {
                    if (dayEventsHours[i] == 1) {
                        return false;
                    }
                }
            }
            eventList.add(dayEvents);
            updateAllListeners();
            return true;
        } else {
            eventList = new ArrayList();
            eventList.add(dayEvents);
            eventsList.put(date, eventList);
            updateAllListeners();
            return true;
        }
    }