Select 只有 2 天的工作日?

Select only 2 days of Workdays?

我必须在今天之后 select 2 个工作日 在我的日期选择器上。

Ps:如果今天是周五,我不能select周六和周日,日期选择器必须跳到周一和周四

我正在使用 PHP、JS、Bootstrap。

我当前的代码:

$('.datepickerVencBoleto').datetimepicker({
    format: "DD/MM/YYYY",
    minDate: new Date(),
    daysOfWeekDisabled: [0, 6],
});

// DATEPICKER
$('.datepicker,.datepickerHojeMin').datetimepicker({
    format: "DD/MM/YYYY",
    showTodayButton: true,
    locale: moment.locale('pt-br'),
    showClear: true,
    showClose: true
});

红色圆圈表示我必须启用的日期。 (图片示例)

您可以使用 enabledDates 指定应启用的日期。

您可以根据星期几确定应启用哪些天(例如,参见 momentjs isoWeekday)。

这里是使用 clone() and add() 的实时示例:

function next2Workdays(){
  var today = moment().startOf('day');
  if( today.isoWeekday()>=1 && today.isoWeekday()<=4 ){ // Today is Monday - Wednesday
    return [ today.clone(), today.clone().add(1, 'd') ];
   } else if( today.isoWeekday() == 5 ){  // Today is Friday
    return [ today.clone(), today.clone().add(3, 'd') ];
  } else if( today.isoWeekday() > 5 ){ // Today is Saturday or Sunday
    var startWeek = today.clone().startOf('isoWeek');
    var newWeek = startWeek.clone().add(1, 'week');
    return [ newWeek.clone().isoWeekday(1), newWeek.clone().isoWeekday(2)];
  }
}

$('.datepickerVencBoleto').datetimepicker({
    format: "DD/MM/YYYY",
    minDate: moment().startOf('day'),
    enabledDates: next2Workdays(),
    locale: 'pt-br',
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

<div class='col-sm-6'>
  <div class="form-group">
    <div class='input-group date datepickerVencBoleto'>
      <input type='text' class="form-control" />
      <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
      </span>
    </div>
  </div>
</div>