-
Notifications
You must be signed in to change notification settings - Fork 0
/
diautil.js
56 lines (52 loc) · 3.65 KB
/
diautil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var holidays = {};
holidays["2015"]=["2015-01-01","2015-01-25","2015-02-16","2015-02-17","2015-04-03","2015-04-21","2015-05-01","2015-06-04","2015-07-09","2015-09-07","2015-10-12","2015-11-02","2015-11-15","2015-11-20","2015-12-24","2015-12-25","2015-12-31"];
holidays["2016"]=["2016-01-01","2016-01-25","2016-02-08","2016-02-09","2016-03-25","2016-04-21","2016-05-01","2016-05-26","2016-07-09","2016-09-07","2016-10-12","2016-11-02","2016-11-15","2016-11-20","2016-12-24","2016-12-25","2016-12-31"];
holidays["2017"]=["2017-01-01","2017-01-25","2017-02-27","2017-02-28","2017-04-14","2017-04-21","2017-05-01","2017-06-15","2017-07-09","2017-09-07","2017-10-12","2017-11-02","2017-11-15","2017-11-20","2017-12-24","2017-12-25","2017-12-31"];
holidays["2018"]=["2018-01-01","2018-01-25","2018-02-12","2018-02-13","2018-03-30","2018-04-21","2018-05-01","2018-05-31","2018-07-09","2018-09-07","2018-10-12","2018-11-02","2018-11-15","2018-11-20","2018-12-24","2018-12-25","2018-12-31"];
holidays["2019"]=["2019-01-01","2019-01-25","2019-03-04","2019-03-05","2019-04-19","2019-04-21","2019-05-01","2019-06-20","2019-07-09","2019-09-07","2019-10-12","2019-11-02","2019-11-15","2019-11-20","2019-12-24","2019-12-25","2019-12-31"];
holidays["2020"]=["2020-01-01","2020-01-25","2020-02-24","2020-02-25","2020-04-10","2020-04-21","2020-05-01","2020-06-11","2020-07-09","2020-09-07","2020-10-12","2020-11-02","2020-11-15","2020-11-20","2020-12-24","2020-12-25","2020-12-31"];
holidays["2021"]=["2021-01-01","2021-01-25","2021-02-15","2021-02-16","2021-04-02","2021-04-21","2021-05-01","2021-06-03","2021-07-09","2021-09-07","2021-10-12","2021-11-02","2021-11-15","2021-11-20","2021-12-24","2021-12-25","2021-12-31"];
holidays["2022"]=["2022-01-01","2022-01-25","2022-02-28","2022-03-01","2022-04-15","2022-04-21","2022-05-01","2022-06-16","2022-07-09","2022-09-07","2022-10-12","2022-11-02","2022-11-15","2022-11-20","2022-12-24","2022-12-25","2022-12-31"];
holidays["2023"]=["2023-01-01","2023-01-25","2023-02-20","2023-02-21","2023-04-07","2023-04-21","2023-05-01","2023-06-08","2023-07-09","2023-09-07","2023-10-12","2023-11-02","2023-11-15","2023-11-20","2023-12-24","2023-12-25","2023-12-31"];
holidays["2024"]=["2024-01-01","2024-01-25","2024-02-12","2024-02-13","2024-03-29","2024-04-21","2024-05-01","2024-05-30","2024-07-09","2024-09-07","2024-10-12","2024-11-02","2024-11-15","2024-11-20","2024-12-24","2024-12-25","2024-12-31"];
holidays["2025"]=["2025-01-01","2025-01-25","2025-03-03","2025-03-04","2025-04-18","2025-04-21","2025-05-01","2025-06-19","2025-07-09","2025-09-07","2025-10-12","2025-11-02","2025-11-15","2025-11-20","2025-12-24","2025-12-25","2025-12-31"];
var increment = function(d){
d.setDate(d.getDate() + 1);
return d;
}
var getWorkDay = function(year,month,day, n){
var wd = new Date(Date.UTC(year, month - 1, day, 0, 0, 0));
var i = 1;
while(i < (n+1)){
wd = increment(wd)
if(!( holiday(wd) || weekend(wd) )) i++;
}
return wd.getUTCFullYear() + "-" + (wd.getUTCMonth() + 1) + "-" + wd.getUTCDate();
}
var weekend = function(wd){
var d = wd;
var w = d.getUTCDay();
if((w==6) || (w==0)) {
return true;
}
return false;
}
var holiday = function(h){
var list = holidays[h.getUTCFullYear()];
var text = h.getUTCFullYear() + "-" + (h.getUTCMonth() + 1) + "-" + h.getUTCDate();
if(list.indexOf(text) > -1){
return true;
}
return false;
}
//15/11/2015
var diautil = function(d,n){
var c = d.split("/");
var r = getWorkDay(c[2],c[1],c[0],n).split("-");
return r[2]+"/"+r[1]+"/"+r[0];
}
//console.log(diautil("23/11//2015",2));
var dateutil = function(d,n){
var r = getWorkDay(d.getFullYear(),d.getMonth()+1,d.getDate(),n);
return new Date(r);
}