0

I want to develop an application in which user can allocate time schedule to their group members, the issue is suppose I have already schedule two different time and now again want to schedule time for the same day then how I will check that the same time schedule is not already allocated or not

Date    Start Time  End Time    status 

15-09-2017  10:05   13:10   TRUE
15-09-2017  10:00   14:00   FALSE  because 10:00-13:10 is already scheduled
15-09-2017  08:20   09:00   TRUe
15-09-2017  09:30   10:05   TRUE
15-09-2017  09:40   10:05   false  `

1 Answers1

-1

I suggest to you The EPOCH time format .

You can convert your date+start time and date+endtime as follow for example :

Start date : "15-09-2017 10:05" 
End date : "15-09-2017 13:10"

After that you convert this string to EPOCH format as follow :

String str = "15-09-2017 10:05";
SimpleDateFormat df = new SimpleDateFormat("DD-mm-yyyy HH:mm");
Date date = df.parse(str);
long epoch = date.getTime();

You do it for both end and start date. You will have at the end 3 long variables :

long epochStartDate , epochEndDate, epochToBeInserted.

And before inserting you schedule, you compare

if(epochToBeInserted in [epochStartDate,epochEndDate]) => insert false else true.

  • 15-09-2017 10:00 14:00 FALSE because 10:00-13:10 is already scheduled. how to check this condition using your example? if(epochToBeInserted in [epochStartDate,epochEndDate]) – Chiranjib Pahari Sep 15 '17 at 06:26
  • ah ok , look , you need to convert 15-09-2017 10:00 14:00 into epoch in 2 dates (start and end) you will have 2 variables (long1, long2) after that you convert 10:00-13:10, you will have 2 new ones (var1, var2) , then you check if (var2-var1) between (long1,long2) so its false –  Sep 15 '17 at 06:39