Bootstrap DatePicker - 跳过范围内的日期数组 [英] Bootstrap DatePicker - Skip array of dates in range

查看:209
本文介绍了Bootstrap DatePicker - 跳过范围内的日期数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个禁用日历的日历 IMAGE 我禁用星期日,星期六和日期之前有这个属性:

I have a calendar with disabled days IMAGE I disable Sunday and saturday and dates before there with this properties:

//datesDisabled: datesForDisable, --> this is array
//daysOfWeekDisabled: [0, 6],

我想要哪里在 dateFrom 中选择第18个日期,在 dateTo 中选择第23个日期,以获取days lenght - > 2 我要跳过停用日期

I want where i choose 18th date in dateFrom and 23th date in dateTo get days lenght --> 2 I WANT TO SKIP DISABLED DATES

这里我使用函数

var enumerateDaysBetweenDates = function (startDate, endDate) {

        var disabledDates = ["13/01/2017", "19/01/2017", "20/01/2017"];
        var DisableDays = [0, 1];
        var dates = [];

        var currDate = startDate.clone().startOf('day');
        var lastDate = endDate.clone().startOf('day');

        dates.push(currDate.clone().toDate());

        while (currDate.add('days', 1).diff(lastDate) < 0) {
            if (disabledDates.indexOf(moment(currDate.format('DD/MM/YYYY'))) == -1 && DisableDays.indexOf(currDate.day()) == -1) {
                dates.push(currDate.clone().toDate());
            }
        }

        dates.push(currDate.clone().toDate());

        return dates;
    };

以前谢谢!

推荐答案

var DisableDays = [0,1];
定义一周中哪几天被禁用。

var DisableDays = [0, 1]; Defines which days of the week to be disabled.

对于禁用星期六和星期日,在禁用天数组中使用0,6。

For Disabling Saturday and Sunday use 0,6 in your disable days array.

Moment.js定义从星期日= 0到星期六= 6的工作日。

Moment.js defines weekdays from Sunday=0 to Saturday=6 .

更新

Update

类似于不工作日,比较循环中当前日期不工作的数组。

Similarly for not working days compare not working array with current date in the loop.

更新小提琴

 if(DisableDays.indexOf(currDate.day()) == -1 && notWorkingDays.indexOf(currDate.format('DD.MM.YYYY')) == -1 )

-Help:)

这篇关于Bootstrap DatePicker - 跳过范围内的日期数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆