JSFiddle - React, Tailwind, and code Playground

by 1eddy87

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<span></span>

JavaScript

var timeFormat = "HH:mm";

function isAvailable(starting, ending, now) {
  var startingTime = moment(starting, timeFormat).date(1);
  var endingTime = moment(ending, timeFormat).date(1);
  var nowTime = moment(now, timeFormat).date(1);
  if (endingTime.isBefore(startingTime)) {
    endingTime.date(2);
  }
  return nowTime.isBetween(startingTime, endingTime);
}

$('span').text(isAvailable("10:00", "16:00", moment()));