Why does this jQuery function work partially on some browsers?
by englishsound
HTML
<span class="valMixBeatVoce">6</span>
<br>
<body class="page-id-5749">
<span id="DateMixBeatVoce"></span>
<br>
<span id="DateMixBeatVoce2"></span>
<br>
</body>
JavaScript
jQuery(function($) {
if ($('body.page-id-5749').length > 0) {
var monthNames = ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"];
var dayNames = ["domenica", "lunedì", "martedì", "mercoledì", "giovedì", "venerdì", "sabato"];
var holidays = ["2019, 12, 8", // 8 DICEMBRE 2019
"2019, 12, 25", // 25 DICEMBRE 2019
"2019, 12, 26", // 26 DICEMBRE 2019
"2020, 1, 1", // CAPODANNO 2020
"2020, 1, 6", // EPIFANIA 2020
"2020, 4, 13", // PASQUETTA 2020
"2020, 4, 25", // 25 APRILE 2020
"2020, 5, 1", // 1 MAGGIO 2020
"2020, 6, 2", // 2 GIUGNO 2020
"2020, 8, 15", // 15 AGOSTO 2020
"2020, 11, 1", // 1 NOVEMBRE 2020
"2020, 12, 8", // 8 DICEMBRE 2020
"2020, 12, 25", // 25 DICEMBRE 2020
"2020, 12, 26", // 26 DICEMBRE 2020
"2021, 1, 1"
]; // 1 GENNAIO 2021
var endDate = "",
noOfDaysToAdd = $(".valMixBeatVoce").html(),
count = 0;
var someDate = new Date(new Date().toDateString());
var numberOfDaysToAdd = noOfDaysToAdd;
someDate.setDate(someDate.getDate());
while (count < noOfDaysToAdd) {
endDate = new Date(someDate.setDate(someDate.getDate() + 1));
var isHoliday = holidays.find(holiday => endDate.getTime() == new Date(holiday).getTime());
if (isHoliday) {
console.log('holiday, skipping');
} else if (endDate.getDay() != 0 && endDate.getDay() != 6) {
count++;
}
}
$('#DateMixBeatVoce').html(dayNames[endDate.getDay()] + ' ' + endDate.getDate() + ' ' + monthNames[endDate.getMonth()]);
$('#DateMixBeatVoce2').html(dayNames[endDate.getDay()] + ' ' + endDate.getDate() + ' ' + monthNames[endDate.getMonth()]);
}
});