Closed ketankokane94 closed 5 years ago
DateTimeFormatter format = DateTimeFormatter.ofPattern("HH:mm"); LocalTime from = LocalTime.parse("13:00",format); LocalTime to = LocalTime.parse("13:30",format); long ans = MINUTES.between(from,to);
code snipset to find the interval between two task is more than 55 minutes
Code snippet to add and substract minutes to create new interval from = from.plusMinutes(10); to = to.minusMinutes(10);
Name= 'wake up ' From = 00:00 to = 09:30 Duration= 570 Name= 'Leet code' From = 09:40 to = 11:40 Duration= 120 Name= 'Lunch' From = 12:00 to = 12:45 Duration= 45 Name= 'Shopping for ROC' From = 12:55 to = 14:50 Duration= 115
the time 1190 makes no sense, as the next task is at 1200, the scheduler tries to give 10 mins break between two tasks. hence it does 1200 - 10 and gets 1190, which is incorrect, whereas for 1130 - 10, being 11 20 AM is correct.
handled the case by using LocalTime
Name= 'wake up ' From= 0 AM To= 930 AM Duration= 930 Name= 'Leet code' From= 940 AM To= 1140 AM Duration= 200 Name= 'Shopping for ROC' From= 1140 AM To= 1190 AM Duration= 50
the time 1190 makes no sense, as the next task is at 1200, the scheduler tries to give 10 mins break between two tasks. hence it does 1200 - 10 and gets 1190, which is incorrect, whereas for 1130 - 10, being 11 20 AM is correct.
So need a better mechanism to handle time.