title: Calculate current time in percentage in relation to sunrise and sunset time?
body: <p>I think what I would like to achieve can best be described with the graph I've made below:</p>
  <p><a href="https://i.stack.imgur.com/EbkJl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EbkJl.png" alt="Day Night Cycle In Percentage" /></a></p>
  <p>I'm getting my sunrise and sunset data from an API that returns an object like this:</p>
  <pre><code>{
    sunrise: &quot;07:58:38&quot;,
    sunset: &quot;15:52:46&quot;,
    day_length: &quot;07:54:08&quot;,
  }
  </code></pre>
  <p>I'm currently calculating whether it's currently day or night time with this if statement:</p>
  <pre><code>const date = moment().format(&quot;YYYY-MM-DD&quot;)
  
  let dayOrNight = &quot;Day&quot;
  
  if (moment().isAfter(`${date} ${location.sunrise}`) &amp;&amp; moment().isBefore(`${date} ${location.sunset}`)) {
    dayOrNight = &quot;Day&quot;
  } else {
    dayOrNight = &quot;Night&quot;
  }
  </code></pre>
  <p>All I need is a percentage value based on the current time in relation to this sunrise and sunset data.</p>
  <p>For example, if this is my dataset:</p>
  <pre><code>{
    sunrise: &quot;00:00:00&quot;,
    sunset: &quot;10:00:00&quot;,
  }
  </code></pre>
  <p>and my current time is perfectly between of both sunrise and sunset times which in this case would be <code>05:00:00</code> or <code>17:00:00</code>, then my current time would equate to 100%. <code>02:30:00</code>, <code>07:30:00</code> would equate to 50%.</p>