Splitting Overlapping Hours and minutes through java









up vote
0
down vote

favorite












I have two ArrayList which has the date time which contains entry and exit say



EntryTime ExitTime




  1. '2018-10-04 07:00:00' '2018-10-04 11:00:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'

Entry-Exit data is in first ArrayList and data from 2 to 4 is another ArrayList.



Now, the entry-exit which you see at the top 1, I need to bifurcate that time because that is a manual entry made to the system which I am storing in the first array and the rests are system generated which are in the second array. so from 2 till 4, I cannot alter the data which is correct. I need to alter only the first record which is a manual entry. I need to make them distinct and non-overlap and my final result will be like this:



 EntryTime ExitTime



  1. '2018-10-04 07:00:00' '2018-10-04 07:59:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'


  5. '2018-10-04 08:31:00' '2018-10-04 08:59:00'


  6. '2018-10-04 09:41:00' '2018-10-04 09:59:00'

  7. '2018-10-04 10:31:00' '2018-10-04 11:00:00'

The bolded DateTime(5 to 7 i.e in the result section) is now made distinct and non-overlapped whereas the data in the first section is the same from 2 to 4. The changed values are from 5 to 7.
I am not able to think for should I loop through the ranges and cut the time.
Please help and tell me if you need any other information.
I searched enough but could not find the required answer or it could be I failed to understand.










share|improve this question























  • Are the 2-4 entries sorted chronologically?
    – wdc
    Nov 10 at 9:12






  • 1




    Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
    – Ole V.V.
    Nov 10 at 10:25











  • @wdc yes, i am sorting all the records based on their datetime.
    – Abhinav Srivastava
    Nov 10 at 17:33














up vote
0
down vote

favorite












I have two ArrayList which has the date time which contains entry and exit say



EntryTime ExitTime




  1. '2018-10-04 07:00:00' '2018-10-04 11:00:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'

Entry-Exit data is in first ArrayList and data from 2 to 4 is another ArrayList.



Now, the entry-exit which you see at the top 1, I need to bifurcate that time because that is a manual entry made to the system which I am storing in the first array and the rests are system generated which are in the second array. so from 2 till 4, I cannot alter the data which is correct. I need to alter only the first record which is a manual entry. I need to make them distinct and non-overlap and my final result will be like this:



 EntryTime ExitTime



  1. '2018-10-04 07:00:00' '2018-10-04 07:59:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'


  5. '2018-10-04 08:31:00' '2018-10-04 08:59:00'


  6. '2018-10-04 09:41:00' '2018-10-04 09:59:00'

  7. '2018-10-04 10:31:00' '2018-10-04 11:00:00'

The bolded DateTime(5 to 7 i.e in the result section) is now made distinct and non-overlapped whereas the data in the first section is the same from 2 to 4. The changed values are from 5 to 7.
I am not able to think for should I loop through the ranges and cut the time.
Please help and tell me if you need any other information.
I searched enough but could not find the required answer or it could be I failed to understand.










share|improve this question























  • Are the 2-4 entries sorted chronologically?
    – wdc
    Nov 10 at 9:12






  • 1




    Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
    – Ole V.V.
    Nov 10 at 10:25











  • @wdc yes, i am sorting all the records based on their datetime.
    – Abhinav Srivastava
    Nov 10 at 17:33












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have two ArrayList which has the date time which contains entry and exit say



EntryTime ExitTime




  1. '2018-10-04 07:00:00' '2018-10-04 11:00:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'

Entry-Exit data is in first ArrayList and data from 2 to 4 is another ArrayList.



Now, the entry-exit which you see at the top 1, I need to bifurcate that time because that is a manual entry made to the system which I am storing in the first array and the rests are system generated which are in the second array. so from 2 till 4, I cannot alter the data which is correct. I need to alter only the first record which is a manual entry. I need to make them distinct and non-overlap and my final result will be like this:



 EntryTime ExitTime



  1. '2018-10-04 07:00:00' '2018-10-04 07:59:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'


  5. '2018-10-04 08:31:00' '2018-10-04 08:59:00'


  6. '2018-10-04 09:41:00' '2018-10-04 09:59:00'

  7. '2018-10-04 10:31:00' '2018-10-04 11:00:00'

The bolded DateTime(5 to 7 i.e in the result section) is now made distinct and non-overlapped whereas the data in the first section is the same from 2 to 4. The changed values are from 5 to 7.
I am not able to think for should I loop through the ranges and cut the time.
Please help and tell me if you need any other information.
I searched enough but could not find the required answer or it could be I failed to understand.










share|improve this question















I have two ArrayList which has the date time which contains entry and exit say



EntryTime ExitTime




  1. '2018-10-04 07:00:00' '2018-10-04 11:00:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'

Entry-Exit data is in first ArrayList and data from 2 to 4 is another ArrayList.



Now, the entry-exit which you see at the top 1, I need to bifurcate that time because that is a manual entry made to the system which I am storing in the first array and the rests are system generated which are in the second array. so from 2 till 4, I cannot alter the data which is correct. I need to alter only the first record which is a manual entry. I need to make them distinct and non-overlap and my final result will be like this:



 EntryTime ExitTime



  1. '2018-10-04 07:00:00' '2018-10-04 07:59:00'

  2. '2018-10-04 08:00:00' '2018-10-04 08:30:00'

  3. '2018-10-04 09:00:00' '2018-10-04 09:40:00'

  4. '2018-10-04 10:00:00' '2018-10-04 10:30:00'


  5. '2018-10-04 08:31:00' '2018-10-04 08:59:00'


  6. '2018-10-04 09:41:00' '2018-10-04 09:59:00'

  7. '2018-10-04 10:31:00' '2018-10-04 11:00:00'

The bolded DateTime(5 to 7 i.e in the result section) is now made distinct and non-overlapped whereas the data in the first section is the same from 2 to 4. The changed values are from 5 to 7.
I am not able to think for should I loop through the ranges and cut the time.
Please help and tell me if you need any other information.
I searched enough but could not find the required answer or it could be I failed to understand.







java date datetime






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 9:08

























asked Nov 10 at 9:01









Abhinav Srivastava

34




34











  • Are the 2-4 entries sorted chronologically?
    – wdc
    Nov 10 at 9:12






  • 1




    Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
    – Ole V.V.
    Nov 10 at 10:25











  • @wdc yes, i am sorting all the records based on their datetime.
    – Abhinav Srivastava
    Nov 10 at 17:33
















  • Are the 2-4 entries sorted chronologically?
    – wdc
    Nov 10 at 9:12






  • 1




    Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
    – Ole V.V.
    Nov 10 at 10:25











  • @wdc yes, i am sorting all the records based on their datetime.
    – Abhinav Srivastava
    Nov 10 at 17:33















Are the 2-4 entries sorted chronologically?
– wdc
Nov 10 at 9:12




Are the 2-4 entries sorted chronologically?
– wdc
Nov 10 at 9:12




1




1




Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
– Ole V.V.
Nov 10 at 10:25





Use half-open intervals and avoid the :59. Let 07:00 to 08:00 mean from 07:00 inclusive to 08:00 exclusive so it doesn’t overlap with the next interval, from 08:00 to 08:30.
– Ole V.V.
Nov 10 at 10:25













@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
Nov 10 at 17:33




@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
Nov 10 at 17:33












1 Answer
1






active

oldest

votes

















up vote
1
down vote













If the 2-4 entries are sorted chronologically you could just loop through the system generated entries, and for the i-th position, you could check if there is a gap between the i-th (the current entry) exit date and the i+1-th (the next one) entry date, and if there is, then check the other ArrayList to see if there is an entry that begins before and ends after the "gap" you found in the system generated ArrayList.



Pseudocode:



for(int i=0; i<arrayList2.size()-1; i++)

if(arrayList2[i].exitDate is_before arrayList2[i+1].entryDate)

fillTheGapIfPossible(arrayList2[i], arrayList2[i+1]);





fillTheGapIfPossible(entry1, entry2)

for(int i=0; i<arrayList1.size(); i++)

if(arrayList1[i].entry is_before entry1.exitDate &&
arrayList1[i].exitDate is_after entry2.entryDate)

makeNewEntry(entry1.exitDate, entry2.entryDate);








Where arrayList2 is the system generated list.






share|improve this answer






















  • in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
    – Abhinav Srivastava
    Nov 12 at 18:19










  • @AbhinavSrivastava Yes, you are right. Edited.
    – wdc
    Nov 12 at 21:41










  • Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
    – Abhinav Srivastava
    Nov 19 at 17:51










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237453%2fsplitting-overlapping-hours-and-minutes-through-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













If the 2-4 entries are sorted chronologically you could just loop through the system generated entries, and for the i-th position, you could check if there is a gap between the i-th (the current entry) exit date and the i+1-th (the next one) entry date, and if there is, then check the other ArrayList to see if there is an entry that begins before and ends after the "gap" you found in the system generated ArrayList.



Pseudocode:



for(int i=0; i<arrayList2.size()-1; i++)

if(arrayList2[i].exitDate is_before arrayList2[i+1].entryDate)

fillTheGapIfPossible(arrayList2[i], arrayList2[i+1]);





fillTheGapIfPossible(entry1, entry2)

for(int i=0; i<arrayList1.size(); i++)

if(arrayList1[i].entry is_before entry1.exitDate &&
arrayList1[i].exitDate is_after entry2.entryDate)

makeNewEntry(entry1.exitDate, entry2.entryDate);








Where arrayList2 is the system generated list.






share|improve this answer






















  • in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
    – Abhinav Srivastava
    Nov 12 at 18:19










  • @AbhinavSrivastava Yes, you are right. Edited.
    – wdc
    Nov 12 at 21:41










  • Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
    – Abhinav Srivastava
    Nov 19 at 17:51














up vote
1
down vote













If the 2-4 entries are sorted chronologically you could just loop through the system generated entries, and for the i-th position, you could check if there is a gap between the i-th (the current entry) exit date and the i+1-th (the next one) entry date, and if there is, then check the other ArrayList to see if there is an entry that begins before and ends after the "gap" you found in the system generated ArrayList.



Pseudocode:



for(int i=0; i<arrayList2.size()-1; i++)

if(arrayList2[i].exitDate is_before arrayList2[i+1].entryDate)

fillTheGapIfPossible(arrayList2[i], arrayList2[i+1]);





fillTheGapIfPossible(entry1, entry2)

for(int i=0; i<arrayList1.size(); i++)

if(arrayList1[i].entry is_before entry1.exitDate &&
arrayList1[i].exitDate is_after entry2.entryDate)

makeNewEntry(entry1.exitDate, entry2.entryDate);








Where arrayList2 is the system generated list.






share|improve this answer






















  • in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
    – Abhinav Srivastava
    Nov 12 at 18:19










  • @AbhinavSrivastava Yes, you are right. Edited.
    – wdc
    Nov 12 at 21:41










  • Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
    – Abhinav Srivastava
    Nov 19 at 17:51












up vote
1
down vote










up vote
1
down vote









If the 2-4 entries are sorted chronologically you could just loop through the system generated entries, and for the i-th position, you could check if there is a gap between the i-th (the current entry) exit date and the i+1-th (the next one) entry date, and if there is, then check the other ArrayList to see if there is an entry that begins before and ends after the "gap" you found in the system generated ArrayList.



Pseudocode:



for(int i=0; i<arrayList2.size()-1; i++)

if(arrayList2[i].exitDate is_before arrayList2[i+1].entryDate)

fillTheGapIfPossible(arrayList2[i], arrayList2[i+1]);





fillTheGapIfPossible(entry1, entry2)

for(int i=0; i<arrayList1.size(); i++)

if(arrayList1[i].entry is_before entry1.exitDate &&
arrayList1[i].exitDate is_after entry2.entryDate)

makeNewEntry(entry1.exitDate, entry2.entryDate);








Where arrayList2 is the system generated list.






share|improve this answer














If the 2-4 entries are sorted chronologically you could just loop through the system generated entries, and for the i-th position, you could check if there is a gap between the i-th (the current entry) exit date and the i+1-th (the next one) entry date, and if there is, then check the other ArrayList to see if there is an entry that begins before and ends after the "gap" you found in the system generated ArrayList.



Pseudocode:



for(int i=0; i<arrayList2.size()-1; i++)

if(arrayList2[i].exitDate is_before arrayList2[i+1].entryDate)

fillTheGapIfPossible(arrayList2[i], arrayList2[i+1]);





fillTheGapIfPossible(entry1, entry2)

for(int i=0; i<arrayList1.size(); i++)

if(arrayList1[i].entry is_before entry1.exitDate &&
arrayList1[i].exitDate is_after entry2.entryDate)

makeNewEntry(entry1.exitDate, entry2.entryDate);








Where arrayList2 is the system generated list.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 21:39

























answered Nov 10 at 9:25









wdc

1,0041719




1,0041719











  • in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
    – Abhinav Srivastava
    Nov 12 at 18:19










  • @AbhinavSrivastava Yes, you are right. Edited.
    – wdc
    Nov 12 at 21:41










  • Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
    – Abhinav Srivastava
    Nov 19 at 17:51
















  • in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
    – Abhinav Srivastava
    Nov 12 at 18:19










  • @AbhinavSrivastava Yes, you are right. Edited.
    – wdc
    Nov 12 at 21:41










  • Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
    – Abhinav Srivastava
    Nov 19 at 17:51















in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
– Abhinav Srivastava
Nov 12 at 18:19




in loop check, should the if condition be if(arrayList1[i].entry is_before entry1.exitDate && arrayList1[i].exitDate is_after entry2.entryDate) instead of is_before in both the places.
– Abhinav Srivastava
Nov 12 at 18:19












@AbhinavSrivastava Yes, you are right. Edited.
– wdc
Nov 12 at 21:41




@AbhinavSrivastava Yes, you are right. Edited.
– wdc
Nov 12 at 21:41












Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
– Abhinav Srivastava
Nov 19 at 17:51




Hi buddy, I am using the same logic but I am failing to bifurcate the last time when system data ends like in the output number 7. Since I have kept two lists, it is taking the intermediate gaps but missing the last one. Can u dry run the list and see why this is happening. Thanks.
– Abhinav Srivastava
Nov 19 at 17:51

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237453%2fsplitting-overlapping-hours-and-minutes-through-java%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20