订单截止计时器包括银行假日



请有人帮我处理这段代码好吗?我现在有一个倒计时计时器,从周一到周五下午3点。

到目前为止,它大部分都在工作,目前周五下午3点后增加了72小时,周六增加了48小时,周日增加了24小时。

这是这个的小提琴

我正试图让它检查当前一天还是下一个工作日是银行假日,然后再加上相关的小时数。理想情况下,我可以提供一份我们不会发货的日期列表。

if (document.getElementById('countdown-timer')) {
pad = function(n, len) { // leading 0's
var s = n.toString();
return (new Array((len - s.length + 1)).join('0')) + s;
};
var timerRunning = setInterval(
function countDown() {
var target = 15; // 14:00hrs is the cut-off point
var now = new Date();
//Put this in a variable for convenience
var weekday = now.getDay();
if (weekday == 5) { //It's Friday? Add 72hrs
target += 72;
}
if (weekday == 6) { //It's Saturday? Add 48hrs
target += 48;
}
if (weekday == 0) { //Sunday? Add 24hrs
target += 24;
}
//If between Monday and Friday, 
//check if we're past the target hours, 
//and if we are, abort.
var curhrs = now.getHours();
var hrs = (target - 1) - now.getHours();
if (hrs < 0) hrs = (23 - curhrs) + target;
var mins = 59 - now.getMinutes();
if (mins < 0) mins = 0;
var secs = 59 - now.getSeconds();
if (secs < 0) secs = 0;
var str_hrs = pad(hrs, 2);
var str_mins = pad(mins, 2);
var str_secs = pad(secs, 2);
document.getElementById('countdownhrs').innerHTML = str_hrs;
document.getElementById('countdownmins').innerHTML = str_mins;
document.getElementById('countdownsecs').innerHTML = str_secs;
}, 1000
);
}
<div id="countdown-timer" class="">
<div class="timer-container d-flex flex-row text-center text-nowrap">
<div class="hrs">
<span id="countdownhrs">00</span>
<small class="d-block">HOURS</small>
</div>
<div class="separator">:</div>
<div class="mins">
<span id="countdownmins">00</span>
<small class="d-block">MINS</small>
</div>
<div class="separator">:</div>
<div class="secs">
<span id="countdownsecs">00</span>
<small class="d-block">SECS</small>
</div>
</div>
</div>

假设您在英国,英国政府通过JSON API发布银行假日,网址为:https://www.gov.uk/bank-holidays.json

它有英格兰和威尔士、苏格兰和北爱尔兰的单独名单。

以下是一些示例代码,用于获取列表并仅用"0"的日期填充数组;英格兰和威尔士":

let holidayList = [];
fetch('https://www.gov.uk/bank-holidays.json')
.then((response) => response.json())
.then((divisions) => divisions['england-and-wales']['events'])
.then((holidays) => holidays.map((holiday) => holiday.date))
.then((days) => (holidayList = days));

可用的划分是:;英格兰和威尔士"北爱尔兰"苏格兰;

API文件如下:https://github.com/alphagov/calendars

最新更新