박지환

Implemented as a function & Add get today date

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
1 -const today = new Date(); //오늘 날짜 입력
2 -const holiday = new Date("2022-10-01"); //공휴일 날짜 입력
3 -
4 -console.log(today.getMonth() + 1);
5 -
6 -const diffDate = today.getTime() - holiday.getTime();
7 -
8 -const dday = Math.abs(diffDate / (1000 * 3600 * 24));
9 -
10 -console.log(dday);
...@@ -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);
......
1 <!-- data.ejs --> 1 <!-- data.ejs -->
2 2
3 <!DOCTYPE html> 3 <!DOCTYPE html>
4 -<html lang="en"> 4 +<html>
5 <head> 5 <head>
6 <meta charset="UTF-8"> 6 <meta charset="UTF-8">
7 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta http-equiv="X-UA-Compatible" content="IE=edge">
......