title: Need help calculating time difference between a 4 instance clockout in 24 hour time
body: <p>Alright, there are 4 instances of a clock in/out occuring. There's a clock in, a clock out for lunch, clock in from lunch, and a final clock out. It's a 24 hour clock, and the time needs to be rounded to the nearest .25 (15 minutes) at the very end. </p>
  
  <pre><code>   *For reference, a is the first clock in hour, b is the clock out for lunch hour
      c is the clock in hour from lunch, and d is the final clock out hour
  
     *e is the first clock in minute, f is the clock out for lunch minute
      g is the clock in from lunch minute, and h is the final clock out minute
  
     *So for example, if somebody clocked in at 5:30, a=5 and f=30
      a clock out for lunch at 12:00 gives b=12 and g=0, etc.
  
     *The way this code works in a nutshell is to find the total time elapsed and then
      subtract the lunch break time from it. 
  
  
     //Find total time
      a=d-a;
      e=h-e;
  
      //Find lunch break time
      y=c-b;
      z=g-f;
  
      if(e&gt;=0 &amp;&amp; z&gt;=0){
          hours=a-y;
          minutes=e-z;
          if(minutes&lt;0){minutes=minutes*(-1);}
      }else if(e&lt;0 &amp;&amp; z&lt;0){
          e=e*(-1);
          z=z*(-1);
          hours=a-y;
          minutes=e-z;
          if(minutes&lt;0){minutes=minutes*(-1);}
      }else{
          if(e&lt;0){e=e*(-1);}
          if(z&lt;0){z=z*(-1);}
          if(e&lt;=z){hours=a-y-1;}
          else{hours=a-y;}
          minutes=e-z;
          if(minutes&lt;0){minutes=minutes*(-1);}
      }
  
      a=hours;
      e=minutes;
  
      //This rounds to the nearest 15 minutes/quarter hour        
      if(e&lt;15){
          if(e&gt;=8){e=15;}
          else if(e&lt;8){e=0;}}
      if(e&lt;=30 &amp;&amp; e&gt;=15){
          if(e&gt;=23){e=30;}
          else if(e&lt;23){e=15;}}
      if(e&lt;=45 &amp;&amp; e&gt;30){
          if(e&gt;=38){e=45;}
          else if(e&lt;38){e=30;}}
      if(e&lt;=60 &amp;&amp; e&gt;45){
          if(e&gt;=53){e=0;}
          else if(e&lt;53){e=45;}}
  
      e=e/60;
      a=a+e;
  }
  
  if(a&lt;0){a=a+24;}
  
  $(totaltime).attr('value',a);   
  </code></pre>
  
  <p>}</p>
  
  <p>The code is very close to working, there are just random cases where it won't work, and it'll be off by an hour or .5 of an hour or so. Also, this is written in javascript on an HTML page hosted on a highly restricted server, so I can't really add any new libraries or anything. </p>
  
  <p>DEFINITELY feel free to scrap my code if you have a better idea, those three if/else statements are a little confusing to explain, and it's why the code isn't working anyways. I mostly showed the code to show I've been putting some effort into this and am not just trying to take advantage of your help haha.</p>
  
  <p>I also apologize but I have to step away from the computer for a while, so if you have some suggestions or ways to solve this problem toss them out there please and I'll take a look at them when I get back. </p>