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
18 hours ago
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.
17 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago
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 18 hours ago
asked 19 hours ago
Abhinav Srivastava
33
33
Are the 2-4 entries sorted chronologically?
– wdc
18 hours ago
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.
17 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago
add a comment |
Are the 2-4 entries sorted chronologically?
– wdc
18 hours ago
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.
17 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago
Are the 2-4 entries sorted chronologically?
– wdc
18 hours ago
Are the 2-4 entries sorted chronologically?
– wdc
18 hours ago
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.
17 hours ago
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.
17 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago
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].startDate){
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_before entry2.entryDate){
makeNewEntry(entry1.endDate, entry2.startDate);
}
}
}
Where arrayList2
is the system generated list.
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].startDate){
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_before entry2.entryDate){
makeNewEntry(entry1.endDate, entry2.startDate);
}
}
}
Where arrayList2
is the system generated list.
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].startDate){
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_before entry2.entryDate){
makeNewEntry(entry1.endDate, entry2.startDate);
}
}
}
Where arrayList2
is the system generated list.
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].startDate){
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_before entry2.entryDate){
makeNewEntry(entry1.endDate, entry2.startDate);
}
}
}
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].startDate){
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_before entry2.entryDate){
makeNewEntry(entry1.endDate, entry2.startDate);
}
}
}
Where arrayList2
is the system generated list.
edited 18 hours ago
answered 18 hours ago
wdc
9941719
9941719
add a comment |
add a comment |
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
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
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
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
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
Are the 2-4 entries sorted chronologically?
– wdc
18 hours ago
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.
17 hours ago
@wdc yes, i am sorting all the records based on their datetime.
– Abhinav Srivastava
10 hours ago