How to check a timeperiod is overlapping another time period in java

前端 未结 5 1382
温柔的废话
温柔的废话 2020-11-27 06:14

How to check a time period is overlapping another time period in the same day.

For example,

  1. 7:00AM to 10:30AM is overlapping 10:00AM to 11:30AM
5条回答
  •  一向
    一向 (楼主)
    2020-11-27 06:42

    If interval is opened (for example, some process is not finished yet) and end date might be null:

    public static boolean isOverlapping(Date start1, Date end1, Date start2, Date end2)
    {
        return
                ((null == end2) || start1.before(end2)) &&
                ((null == end1) || start2.before(end1)) ;
    }
    

提交回复
热议问题