Showing
4 changed files
with
40 additions
and
47 deletions
1 | -{ | ||
2 | - // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요. | ||
3 | - // 기존 특성에 대한 설명을 보려면 가리킵니다. | ||
4 | - // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요. | ||
5 | - "version": "0.2.0", | ||
6 | - "configurations": [ | ||
7 | - { | ||
8 | - "type": "pwa-node", | ||
9 | - "request": "launch", | ||
10 | - "name": "Launch Program", | ||
11 | - "skipFiles": [ | ||
12 | - "<node_internals>/**" | ||
13 | - ], | ||
14 | - "program": "${workspaceFolder}\\app.js" | ||
15 | - } | ||
16 | - ] | ||
17 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
feature-holiday-counter/app.js
deleted
100644 → 0
... | @@ -31,6 +31,41 @@ var tempArr = []; | ... | @@ -31,6 +31,41 @@ var tempArr = []; |
31 | app.set("views", __dirname + "/views"); | 31 | app.set("views", __dirname + "/views"); |
32 | app.set("view engine", "ejs"); | 32 | app.set("view engine", "ejs"); |
33 | 33 | ||
34 | +// To get today date by using Date | ||
35 | +function getTodayDate() { | ||
36 | + var today = new Date(); | ||
37 | + | ||
38 | + var year = today.getFullYear(); | ||
39 | + var month = ("0" + (today.getMonth() + 1)).slice(-2); | ||
40 | + var day = ("0" + today.getDate()).slice(-2); | ||
41 | + | ||
42 | + var dateString = year + "-" + month + "-" + day; | ||
43 | + | ||
44 | + return dateString; | ||
45 | +} | ||
46 | + | ||
47 | +// To get modified date from locdate | ||
48 | +function getModifiedDate(locdate) { | ||
49 | + return ( | ||
50 | + locdate.substr(0, 4) + | ||
51 | + "-" + | ||
52 | + locdate.substr(4, 2) + | ||
53 | + "-" + | ||
54 | + locdate.substr(6, 2) | ||
55 | + ); | ||
56 | +} | ||
57 | + | ||
58 | +// To get remaining days from locdate | ||
59 | +function getDate(dateName, locdate) { | ||
60 | + var today = new Date(getTodayDate()); // today date | ||
61 | + var holiday = new Date(getModifiedDate(locdate)); // holiday date | ||
62 | + var diffDate = today.getTime() - holiday.getTime(); | ||
63 | + var dday = Math.abs(diffDate / (1000 * 3600 * 24)); | ||
64 | + console.log(dateName + "까지 " + dday + "일 남았습니다."); | ||
65 | + return dday; | ||
66 | +} | ||
67 | + | ||
68 | +// To initialize datas when calling webpage | ||
34 | function init() { | 69 | function init() { |
35 | request.get(requestUrl, (err, res, body) => { | 70 | request.get(requestUrl, (err, res, body) => { |
36 | if (err) { | 71 | if (err) { |
... | @@ -74,27 +109,12 @@ function init() { | ... | @@ -74,27 +109,12 @@ function init() { |
74 | locdate.push(tempStr); | 109 | locdate.push(tempStr); |
75 | idx = text.indexOf("locdate", idx + 1); | 110 | idx = text.indexOf("locdate", idx + 1); |
76 | } | 111 | } |
77 | - let i = 0; | 112 | + console.log(locdate); |
78 | - let length = dateName.length; | 113 | + // Get date through locdate |
79 | var holiArr = []; | 114 | var holiArr = []; |
80 | - while (i < length) { | 115 | + for (var i = 0; i < dateName.length; i++) { |
81 | - var temptoday = dateName[i]; | 116 | + holiArr.push(getDate(dateName[i], locdate[i])); |
82 | - var tempdate = locdate[i]; | ||
83 | - var modifiedDate = | ||
84 | - tempdate.substr(0, 4) + | ||
85 | - "-" + | ||
86 | - tempdate.substr(4, 2) + | ||
87 | - "-" + | ||
88 | - tempdate.substr(6, 2); | ||
89 | - var today = new Date("2022-05-13"); //오늘 날짜 입력 | ||
90 | - var holiday = new Date(modifiedDate); //공휴일 날짜 입력 | ||
91 | - var diffDate = today.getTime() - holiday.getTime(); | ||
92 | - var dday = Math.abs(diffDate / (1000 * 3600 * 24)); | ||
93 | - console.log(temptoday + "까지 " + dday + "일 남았습니다."); | ||
94 | - holiArr.push(dday); | ||
95 | - i++; | ||
96 | } | 117 | } |
97 | - console.log(locdate); | ||
98 | // Create tempArr to save dateName and locdate at once | 118 | // Create tempArr to save dateName and locdate at once |
99 | tempArr = []; | 119 | tempArr = []; |
100 | tempArr.push(dateName); | 120 | tempArr.push(dateName); | ... | ... |
-
Please register or login to post a comment