回答編集履歴

2

調整

2021/12/06 08:30

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -10,12 +10,26 @@
10
10
 
11
11
  const today="2021-12-06";
12
12
 
13
+ // (1)今日の日付
14
+
13
15
  const interval=50;
16
+
17
+ // (2)求めたいn日後
14
18
 
15
19
  const holiday=["2022-01-01","2022-01-10","2022-02-11","2022-02-23"].map(x=>new Date(x).getTime());
16
20
 
17
- const d=new Array(interval*2).fill(null).map((_,x)=>new Date(today).getTime()+60*60*24*1000*(x+1)).filter(x=>!holiday.includes(x)&&new Date(x).getDay()>0).map(x=>new Date(x));
21
+ // (3)祝日のリスト作成
18
22
 
23
+ const d1=new Array(interval*2).fill(null).map((_,x)=>new Date(today).getTime()+60*60*24*1000*(x+1));
24
+
25
+ // (4)余裕をもって求めたいn日後の2倍の日付を配列に保持
26
+
27
+ const d2=d1.filter(x=>!holiday.includes(x)&&new Date(x).getDay()>0).map(x=>new Date(x));
28
+
29
+ // (5)祝日に含まれるか、日曜日を除く
30
+
19
- console.log(d[interval-1]);
31
+ console.log(d2[interval-1]);
32
+
33
+ // (6)n日後を取り出すため1引いて参照
20
34
 
21
35
  ```

1

chousei

2021/12/06 08:29

投稿

yambejp
yambejp

スコア114843

test CHANGED
@@ -1,3 +1,21 @@
1
1
  営業日カレンダーを作っておくしかありません
2
2
 
3
3
  祝日はコロコロ変わるものなので計算で導くことは混乱の元にしかなりません
4
+
5
+
6
+
7
+ # sample
8
+
9
+ ```javascript
10
+
11
+ const today="2021-12-06";
12
+
13
+ const interval=50;
14
+
15
+ const holiday=["2022-01-01","2022-01-10","2022-02-11","2022-02-23"].map(x=>new Date(x).getTime());
16
+
17
+ const d=new Array(interval*2).fill(null).map((_,x)=>new Date(today).getTime()+60*60*24*1000*(x+1)).filter(x=>!holiday.includes(x)&&new Date(x).getDay()>0).map(x=>new Date(x));
18
+
19
+ console.log(d[interval-1]);
20
+
21
+ ```