박지환

Implemented as a function & Add get today date

{
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
// 기존 특성에 대한 설명을 보려면 가리킵니다.
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js"
}
]
}
\ No newline at end of file
const today = new Date(); //오늘 날짜 입력
const holiday = new Date("2022-10-01"); //공휴일 날짜 입력
console.log(today.getMonth() + 1);
const diffDate = today.getTime() - holiday.getTime();
const dday = Math.abs(diffDate / (1000 * 3600 * 24));
console.log(dday);
......@@ -31,6 +31,41 @@ var tempArr = [];
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
// To get today date by using Date
function getTodayDate() {
var today = new Date();
var year = today.getFullYear();
var month = ("0" + (today.getMonth() + 1)).slice(-2);
var day = ("0" + today.getDate()).slice(-2);
var dateString = year + "-" + month + "-" + day;
return dateString;
}
// To get modified date from locdate
function getModifiedDate(locdate) {
return (
locdate.substr(0, 4) +
"-" +
locdate.substr(4, 2) +
"-" +
locdate.substr(6, 2)
);
}
// To get remaining days from locdate
function getDate(dateName, locdate) {
var today = new Date(getTodayDate()); // today date
var holiday = new Date(getModifiedDate(locdate)); // holiday date
var diffDate = today.getTime() - holiday.getTime();
var dday = Math.abs(diffDate / (1000 * 3600 * 24));
console.log(dateName + "까지 " + dday + "일 남았습니다.");
return dday;
}
// To initialize datas when calling webpage
function init() {
request.get(requestUrl, (err, res, body) => {
if (err) {
......@@ -74,27 +109,12 @@ function init() {
locdate.push(tempStr);
idx = text.indexOf("locdate", idx + 1);
}
let i = 0;
let length = dateName.length;
console.log(locdate);
// Get date through locdate
var holiArr = [];
while (i < length) {
var temptoday = dateName[i];
var tempdate = locdate[i];
var modifiedDate =
tempdate.substr(0, 4) +
"-" +
tempdate.substr(4, 2) +
"-" +
tempdate.substr(6, 2);
var today = new Date("2022-05-13"); //오늘 날짜 입력
var holiday = new Date(modifiedDate); //공휴일 날짜 입력
var diffDate = today.getTime() - holiday.getTime();
var dday = Math.abs(diffDate / (1000 * 3600 * 24));
console.log(temptoday + "까지 " + dday + "일 남았습니다.");
holiArr.push(dday);
i++;
for (var i = 0; i < dateName.length; i++) {
holiArr.push(getDate(dateName[i], locdate[i]));
}
console.log(locdate);
// Create tempArr to save dateName and locdate at once
tempArr = [];
tempArr.push(dateName);
......
<!-- data.ejs -->
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
......