title: calculate SLA remaining days / time
body: <p>I need help trying to work out how to display SLA's based on some rules.
  My API comes back with integer values for minutes, for example -1491 and 5836. My logic is incorrect. Can someone help me please.</p>
  <p>The rules are as follows:</p>
  <ol>
  <li>If SLA minutes is &gt;= 24 hrs show days like e.g. &quot;3 days&quot;</li>
  <li>If SLA minutes is less than 24 hrs show hours and minutes e.g. &quot;3hrs 4mins&quot;</li>
  <li>If SLA minutes is less than 1 hr show minutes &quot;33 mins&quot;</li>
  <li>If SLA minutes is -1441 it should return 1 day overdue and if the minutes was a postive number 1441 it should return 1 day</li>
  </ol>
  <p>What I have so far is:</p>
  <pre><code>const items = [{slaMinutesRemaining: 5836}, {slaMinutesRemaining : -1441}]
  </code></pre>
  <p>I loop through items and pass item as prop:</p>
  <pre><code>const SLA = ({item}) =&gt; {
  
      const returnDays = (mins) =&gt; {
        const calc = Math.floor(mins / 1440);
        return calc &gt; 1 ? `${calc} days` : `${calc} day`;
      };
      
      const returnHoursAndMinutes = (mins) =&gt; {
        const hrs = Math.floor(mins / 60);
        const minutes = mins % 60;
        if (mins &lt; 1440) return `${hrs}hrs ${minutes} mins`;
        return mins;
      };
      
      const slaRemaining = (mins) =&gt; {
        console.log('minssss', mins);
        const hrs = Math.floor(mins / 60);
        // if null
        if (!mins) return 'N/A';
        let m = mins;
        const isNegative = m &lt; 0;
        if (isNegative) m = Math.abs(isNegative);
        if (m &gt;= 1440) return returnDays(m);
        if (hrs &lt; 1) return m;
        return returnHoursAndMinutes(m);
      };
  
          return (
            &lt;&gt;
              {item.slaMinutesRemaining &amp;&amp; item.slaMinutesRemaining &lt; 0 ? (
                &lt;SlaAlert&gt;
                  {slaRemaining(item.slaMinutesRemaining)}{' '}
                  &lt;OverDueTag&gt;Overdue&lt;/OverDueTag&gt;
                &lt;/SlaAlert&gt;
              ) : (
                &lt;&gt;{slaRemaining(item.slaMinutesRemaining)}&lt;/&gt;
              )}
            &lt;/&gt;
          );
      }
  </code></pre>