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
    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















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
    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













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 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


















  • 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












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.






share|improve this answer























    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
































    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.






    share|improve this answer



























      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.






      share|improve this answer

























        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.






        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].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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 18 hours ago

























        answered 18 hours ago









        wdc

        9941719




        9941719






























             

            draft saved


            draft discarded



















































             


            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




















































































            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ