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
- '2018-10-04 07:00:00' '2018-10-04 11:00:00'
- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '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
'2018-10-04 07:00:00' '2018-10-04 07:59:00'- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '2018-10-04 10:00:00' '2018-10-04 10:30:00'
'2018-10-04 08:31:00' '2018-10-04 08:59:00'
'2018-10-04 09:41:00' '2018-10-04 09:59:00'- '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
add a comment |
up vote
0
down vote
favorite
I have two ArrayList which has the date time which contains entry and exit say
EntryTime ExitTime
- '2018-10-04 07:00:00' '2018-10-04 11:00:00'
- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '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
'2018-10-04 07:00:00' '2018-10-04 07:59:00'- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '2018-10-04 10:00:00' '2018-10-04 10:30:00'
'2018-10-04 08:31:00' '2018-10-04 08:59:00'
'2018-10-04 09:41:00' '2018-10-04 09:59:00'- '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
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
add a comment |
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
- '2018-10-04 07:00:00' '2018-10-04 11:00:00'
- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '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
'2018-10-04 07:00:00' '2018-10-04 07:59:00'- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '2018-10-04 10:00:00' '2018-10-04 10:30:00'
'2018-10-04 08:31:00' '2018-10-04 08:59:00'
'2018-10-04 09:41:00' '2018-10-04 09:59:00'- '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
I have two ArrayList which has the date time which contains entry and exit say
EntryTime ExitTime
- '2018-10-04 07:00:00' '2018-10-04 11:00:00'
- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '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
'2018-10-04 07:00:00' '2018-10-04 07:59:00'- '2018-10-04 08:00:00' '2018-10-04 08:30:00'
- '2018-10-04 09:00:00' '2018-10-04 09:40:00'
- '2018-10-04 10:00:00' '2018-10-04 10:30:00'
'2018-10-04 08:31:00' '2018-10-04 08:59:00'
'2018-10-04 09:41:00' '2018-10-04 09:59:00'- '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
java date datetime
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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