JavaScript DatePicker disable national days + 48h + weekend jquery datepicker disable national holidays

I know, the title isn't really specific, but I have a problem with DatePicker. I try to disable the national days, weekend and 48 hours after today. For the moment I did this :

  • Hide today + 48hours, I use minDate: 3
  • Hide weekend
  • Hide national days, they are saved in an array
  • Hide (today + 48h) + weekend (5 days to disable), code in beforeShow attribute

My code look like this for the moment :

function noWeekendsOrHolidays(date) {
    var dateTime = new Date();
    var dayOfWeek = dateTime.getDay();
    var noWeekend = $.datepicker.noWeekends(date);

    if (noWeekend[0]) {
        natDays = [
            [1, 1, 'au'], [5, 1, 'ar'], [5, 8, 'ar'], [7, 14, 'us'], [8, 15, 'id'], [11, 1, 'lb'], [11, 11, 'lb'], [12, 25, 'ke']
        ];

        for (i = 0; i < natDays.length; i++) {
            if (date.getMonth() == natDays[i][0] - 1 && date.getDate() == natDays[i][1]) {
                return [false, ''];
            }
        }
        return [true, ''];
    } else {
        return noWeekend;
    }
}

function addDatePicker(pSelname)
{
    $(pSelname).datepicker({
        stepMonths: 1,
        firstDay: 1,
        regional:'fr',
        dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
        dayNamesMin:  ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
        dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
        monthNames: ['Janvier','Fevrier','Mars','Avril','Mai','Juin','Juillet','Aout','Septembre','Octobre','Novembre','D├ęcembre'],
        monthNamesShort: ['Jan','Fev','Mai','Avr','Mai','Juin','Juil','Aou','Sep','Oct','Nov','Dec'],
        dateFormat: 'dd-mm-yy',
        beforeShowDay: noWeekendsOrHolidays,
        minDate: 3,
        beforeShow : function() {
            var dateTime = new Date();
            var dayOfWeek = dateTime.getDay();
            if(dayOfWeek == 4 || dayOfWeek == 5) {
                $(this).datepicker( "option", "minDate", "5" );
            }
        }
    });
}

So, I don't know how to handle the case : (today + 48hours) + weekend + national day in the week. I wrote several cases that I need to reproduce on the DatePicker :

  • If the current day is monday 14 September, and if there is a national day (2015-09-14 or 2015-09-15 or 2015-09-16 or 2015-09-17), the next day selectable will be friday 2015-09-18.
    ((today + 48h) + 1 national day = 4 days disable)
  • If the current day is Thuesday 15 September, and if there is a national day (2015-09-15 or 2015-09-16 or 2015-09-17 or 2015-09-18), the next day selectable will be monday 2015-09-21.
    ((today + 48h) + 1 national day + weekend = 6 days disable)
  • If the current day is Wednesday 16 September, and if there is a national day (2015-09-16 or 2015-09-17 or 2015-09-18 or 2015-09-21), the next day selectable will be Thuesday 2015-09-22.
    ((today + 48h) + 1 national day + weekend = 6 days disable)
  • If the current day is Thursday 17 September, and if there is a national day (2015-09-17 or 2015-09-18 or 2015-09-21 or 2015-09-22), the next day selectable will be wednesday 2015-09-23.
    ((today + 48h) + 1 national day + weekend = 6 days disable)
  • If the current day is friday 18 September, and if there is a national day (2015-09-18 or 2015-09-21 or 2015-09-22 or 2015-09-23), the next day selectable will be thursday 2015-09-24.
    ((today + 48h) + 1 national day + weekend = 6 days disable)

I don't count if there is a national days in the weekend.

The function noWeekendsOrHolidays is executed for each day in the month, so I need to check day by day if there is a national day.

JS FIDDLE

So my first question is : This is really possible to do? Which algorithm can I make to resolve that problem?

Thanks

Answer:1

I have written this script that shows a div when a checkbox is ticked: <cfinput type="Checkbox" name="Agency" value="Agency" id="Agency">Agency Team<br> <div id="agcyTeam" style="...

I have written this script that shows a div when a checkbox is ticked: <cfinput type="Checkbox" name="Agency" value="Agency" id="Agency">Agency Team<br> <div id="agcyTeam" style="...

For my scatter chart in highcharts I would like different series to have different marker radius. Is this possible? "plotOptions": {"series": {"marker": {"enabled": true ...

For my scatter chart in highcharts I would like different series to have different marker radius. Is this possible? "plotOptions": {"series": {"marker": {"enabled": true ...

  1. matplotlib different marker sizes
  2. matlab different marker sizes

I am trying to serve a file manually for a specific URL. When I user the res.sendFile function I get the following error in my logs. Object [object Object] has no method 'sendFile' Express ...

I am trying to serve a file manually for a specific URL. When I user the res.sendFile function I get the following error in my logs. Object [object Object] has no method 'sendFile' Express ...

  1. serve files from s3
  2. serve files over http
  3. serve file nodejs
  4. serve file express
  5. serve files flask
  6. serve file golang
  7. serve files via http
  8. serve files from nginx
  9. serve files from github
  10. serve files
  11. serve file django
  12. serve file python
  13. serve files using nginx
  14. serve files from directory flask
  15. serve files with node js

I have a website that has an input form that submits to a php page and adds a players username to a database and counts the views of that player's name to a top 10 list. My friend tried out ...

I have a website that has an input form that submits to a php page and adds a players username to a database and counts the views of that player's name to a top 10 list. My friend tried out ...