I want to check if my events dose overlap. I have saved start time and end time in date format. My attempt is to check whether dates overlap or not by compare to. But it fails sometimes.

Most it fails at 11pm to 12 am values and 12 :00 am to 1:00 am values. Sometimes fails in between also for another time periods.

As I have a time period stored as ,

datefrom -- Mon mar 14 23:00:00
dateto -- Mon mar 14 00:00:00

and now I tried to add time period as :

checkFromDate -- Mon mar 14 12:14:00
checkToDate -- Mon mar 14 11:14:00

and it returns true. Shows event exists though it dose not. 

Date format is:

```
        df = new SimpleDateFormat("E MMM dd HH:mm:ss zzzz yyyy");

```

Is anything wrong in date format??

checkOverlapping function

```
public void checkOverlappingEvents()
{

    List<EventData> checkOverlappingEvents = new ArrayList<>();

    EventTableHelper eventTableHelper = new EventTableHelper(AddEventActivity.this);

    switch (dayOfWeek)
    {
        case "Mon":

    checkOverlappingEvents = eventTableHelper.getAllEvents("Mon");

    for (EventData e : checkOverlappingEvents)
    {

        df = new SimpleDateFormat("E MMM dd HH:mm:ss zzzz yyyy");

        Date checkFromDate = new Date();
        Date checkToDate = new Date();

        try {

            checkFromDate = df.parse(e.getFromDate());
            checkToDate = df.parse(e.getToDate());

        } catch (ParseException ex) {

        }

    //    int startHours = datefrom.getHours();
    //    int endHours = dateto.getMinutes();

    //    String startTime = checkFromDate.getHours() + ":" + checkFromDate.getMinutes();
    //    String endTime = checkToDate.getHours() + ":" + checkToDate.getMinutes();

     //   String startDate = datefrom.getHours() + ":" + datefrom.getMinutes();
      //  String endDate = dateto.getHours() + ":" + dateto.getMinutes();

        if(datefrom.compareTo(checkToDate) == checkFromDate.compareTo(dateto))
        {
            overlapEvents = true;
            count ++;
            Log.d("count",String.valueOf(count));

        }

    }

```

This dose not help so I thought to only compare hours and minutes of date. My attempt was getting hours and minutes from date and compare them , it's in comments. But it needs some other logic.

Can anyone help me with this please?

EDIT :

As I did test again, I found that if once the condition returns true, then second time for another time period also it shows true though its not true. 

Like now, I have a event of 12:50pm - 1:50pm and I tried to add another event 
of time 12:00pm - 1:00 pm and that returned true,, count is 1. This is right. 

But again if I try to change the time without going back , without refreshing an activity, I tried to change time as 12:00pm to 12:30pm for this also it returned true, count is 1 as this should not be true there is no event of this time period. 

Again if I go back and again If I try to add event of 12:00pm to 12:30pm it returned false, it get added successfully. Now this I don't know what's going wrong about?

I think I need to refresh the list where I am storing the compared events. How can I do this and where should I do this?

Thank you.