Bootstrap Daterangepicker时间减法

Bootstrap Daterangepicker time subtraction

我知道 daterangepicker 有禁用日期范围的功能。但是这次我需要禁用时间范围。具体来说 12:00 上午 - 1:00 下午。如果我选择 11:00 AM - 2:00 PM,计算的总小时数将为 2 小时,从禁用时间范围中剥离 1 小时。这可能是这个选择器吗?如果没有,是否有解决方法?作为初学者,我有 this

$(function() {
    $('input[name="Date2"]').daterangepicker({
        minDate: getCurrentDateToday()+" 8:30 AM",
        dateLimit: { "days": 1},
        timePicker: true,
        timePickerIncrement: 1,
        locale: {format: 'MM/DD/YYYY h:mm A'}
    },
    function(start, end, label)
    {
        var hd = end.diff(start, 'hours');
        var md = end.diff(start, 'minutes');
        var minutesDue = md - (hd*60);
        var hoursDue = hd +"."+minutesDue;
        $('#txtTotalHrs').val(hoursDue);
    });
});

EDITED

$(function() {
  $('input[name="Date2"]').daterangepicker({
      minDate: getCurrentDateToday() + " 8:30 AM",
      dateLimit: {
        "days": 1
      },
      timePicker: true,
      timePickerIncrement: 1,
      locale: {
        format: 'MM/DD/YYYY h:mm A'
      }
    },
    function(start, end, label) {

        var breakStart = "12:00 PM" , breakEnd = "12:30 PM";

      var start_end_diff = (new Date(end) - new Date(start)) / 1000 / 60;

      var break_diff = exclude_BreakTiming(start,end ,breakStart, breakEnd);

      var total_minutes = (start_end_diff - break_diff);

      $('#txtTotalHrs').val(getTimeFromMins(total_minutes));

    });
});

function getTimeFromMins(mins) {
    // do not include the first validation check if you want, for example,
    // getTimeFromMins(1530) to equal getTimeFromMins(90) (i.e. mins rollover)
    if (mins >= 24 * 60 || mins < 0) {
        throw new RangeError("Valid input should be greater than or equal to 0 and less than 1440.");
    }
    var h = mins / 60 | 0,
        m = mins % 60 | 0;
    return moment.utc().hours(h).minutes(m).format("hh:mm");
}

function getCurrentDateToday() {
  var currentDate = new Date();
  var day = currentDate.getDate()
  var month = currentDate.getMonth() + 1;
  var year = currentDate.getFullYear();
  var fullDate = month + "/" + day + "/" + year;
  return fullDate;
}

function exclude_BreakTiming (StartTime , EndTime, BreakStart, BreakEnd){
    StartTime = Date.parse('01/01/2011 ' +StartTime.format('h:mm A'));
  EndTime = Date.parse('01/01/2011 ' +EndTime.format('h:mm A'));

  var breakStart = Date.parse('01/01/2011 '+BreakStart);
  var breakEnd = Date.parse('01/01/2011 '+BreakEnd);

    if((StartTime <= breakEnd) || ((StartTime < breakStart) && (EndTime > breakEnd)))
  {
    return ((breakEnd - breakStart) /1000 /60);
  }else{
    return 0;
  }
}