김유현

Add 출근날 체크

...@@ -9,13 +9,16 @@ ...@@ -9,13 +9,16 @@
9 <br> 9 <br>
10 <div id = "payPerDay" class="in"></div> 10 <div id = "payPerDay" class="in"></div>
11 <br> 11 <br>
12 - <div style="font-weight: bold;" id = "moneyPerSec" class="in"></div> 12 + <div style="font-weight: bold; font-size: large;" id = "moneyPerSec" class="in"></div>
13 <br> 13 <br>
14 + <div id = "workDay" class="in"></div>
15 +
14 </div> 16 </div>
15 <div class="progress-bar"></div> 17 <div class="progress-bar"></div>
16 <h1 class="count"></h1> 18 <h1 class="count"></h1>
17 </body> 19 </body>
18 <script charset="utf-8"> 20 <script charset="utf-8">
21 + //url에서 변수 받아오는 함수
19 function getParam(sname) { 22 function getParam(sname) {
20 var params = location.search.substr(location.search.indexOf("?") + 1); 23 var params = location.search.substr(location.search.indexOf("?") + 1);
21 var sval = ""; 24 var sval = "";
...@@ -27,6 +30,7 @@ ...@@ -27,6 +30,7 @@
27 return sval; 30 return sval;
28 } 31 }
29 32
33 + //strig format 함수 (e.g. "{0}")
30 String.format = function() { 34 String.format = function() {
31 // The string containing the format items (e.g. "{0}") 35 // The string containing the format items (e.g. "{0}")
32 // will and always has to be the first argument. 36 // will and always has to be the first argument.
...@@ -43,19 +47,80 @@ ...@@ -43,19 +47,80 @@
43 return theString; 47 return theString;
44 } 48 }
45 49
46 - //document.getElementById("payDay").innerHTML = "pay day : " + getParam("payDay"); 50 + //출근날 체크 함수
51 + function isTodayWork(workDay, workDayStr){
52 +
53 + var Mon = "%EC%9B%94";
54 + var Tue = "%ED%99%94";
55 + var Wed = "%EC%88%98";
56 + var Thu = "%EB%AA%A9";
57 + var Fri = "%EA%B8%88";
58 + var Sat = "%ED%86%A0";
59 + var Sun = "%EC%9D%BC%0A";
60 +
61 + if (workDay == 0){
62 + if (workDayStr.indexOf(Sun) != -1){
63 + return true;}
64 + else {
65 + return false;
66 + }
67 + }
68 + else if (workDay == 1){
69 + if (workDayStr.indexOf(Mon) != -1){
70 + return true;}
71 + else {
72 + return false;
73 +
74 + }
75 + }
76 + else if (workDay == 2){
77 + if (workDayStr.indexOf(Thu) != -1){
78 + return true;}
79 + else {
80 + return false;
81 +
82 + }
83 + }
84 + else if (workDay == 3){
85 + if (workDayStr.indexOf(Wed) != -1){
86 + return true;}
87 + else {
88 + return false;
89 +
90 + }
91 + }
92 + else if (workDay == 4){
93 + if (workDayStr.indexOf(Thu) != -1){
94 + return true;}
95 + else {
96 + return false;
97 + }
98 + }
99 + else if (workDay == 5){
100 + if (workDayStr.indexOf(Fri) != -1){
101 + return true;}
102 + else {
103 + return false;
104 + }
105 + }
106 + else if (workDay == 6){
107 + if (workDayStr.indexOf(Sat) != -1){
108 + return true;}
109 + else {
110 + return false;
111 + }
112 + }
113 + }
114 +
115 + //변수 정의
47 var salary = Number(getParam("salary")); 116 var salary = Number(getParam("salary"));
48 var workTime = Number(getParam("workTime")); 117 var workTime = Number(getParam("workTime"));
49 var offWork = Number(getParam("offWork")); 118 var offWork = Number(getParam("offWork"));
119 + var workingDay = getParam("workDay");
50 var workingDayNum = getParam("workDay").length / 9; 120 var workingDayNum = getParam("workDay").length / 9;
51 var payPerDay = salary/(4*workingDayNum); 121 var payPerDay = salary/(4*workingDayNum);
52 - //document.getElementById("salary").innerHTML = "salary : " + salary;
53 - document.getElementById("payPerDay").innerHTML = "The daily wage is " + payPerDay + "won";
54 -
55 - //document.getElementById("workDay").innerHTML = "working day : " + getParam("workDay");
56 - //document.getElementById("offWork").innerHTML = "time of work : " + offWork;
57 - //document.getElementById("workedHour").innerHTML = "worked hour : " + String(offWork - workTime);
58 122
123 + // moneyPerSec 초기값 계산
59 var nowTime = new Date(); 124 var nowTime = new Date();
60 var strWorkTime = workTime 125 var strWorkTime = workTime
61 if (strWorkTime < 10){ 126 if (strWorkTime < 10){
...@@ -65,19 +130,16 @@ ...@@ -65,19 +130,16 @@
65 var workStart = new Date(dayStr); 130 var workStart = new Date(dayStr);
66 var diff = (nowTime.getTime() - workStart.getTime()); 131 var diff = (nowTime.getTime() - workStart.getTime());
67 var moneyPerSec = diff*(payPerDay/(1000*60*60*(offWork - workTime))); 132 var moneyPerSec = diff*(payPerDay/(1000*60*60*(offWork - workTime)));
133 +
134 +
135 + //일정 시간동안 반복 호출 함수
68 setInterval("dpTime()",1); 136 setInterval("dpTime()",1);
69 function dpTime(){ 137 function dpTime(){
70 var now = new Date(); 138 var now = new Date();
139 + day = now.getDay();
71 hours = now.getHours(); 140 hours = now.getHours();
72 minutes = now.getMinutes(); 141 minutes = now.getMinutes();
73 seconds = now.getSeconds(); 142 seconds = now.getSeconds();
74 -
75 - //if (hours > 12)
76 - //{ hours -= 12;
77 - // ampm = "오후 ";
78 - //}else
79 - //{ ampm = "오전 ";
80 - //}
81 if (hours < 10){ 143 if (hours < 10){
82 hours = "0" + hours; 144 hours = "0" + hours;
83 } if (minutes < 10){ 145 } if (minutes < 10){
...@@ -86,6 +148,10 @@ ...@@ -86,6 +148,10 @@
86 seconds = "0" + seconds; 148 seconds = "0" + seconds;
87 } 149 }
88 document.getElementById("dpTime").innerHTML = "The current time is "+ hours + ":" + minutes + ":" + seconds; 150 document.getElementById("dpTime").innerHTML = "The current time is "+ hours + ":" + minutes + ":" + seconds;
151 +
152 + if(isTodayWork(day, workingDay)){
153 + document.getElementById("payPerDay").innerHTML = "The daily wage is " + payPerDay + "won";
154 +
89 if (hours < workTime){ 155 if (hours < workTime){
90 var diff2 = (workStart.getTime() - now.getTime()); 156 var diff2 = (workStart.getTime() - now.getTime());
91 var hour2 = (diff2/(1000*60*60))%24 - ((diff2/(1000*60*60))%24)%1; 157 var hour2 = (diff2/(1000*60*60))%24 - ((diff2/(1000*60*60))%24)%1;
...@@ -100,11 +166,7 @@ ...@@ -100,11 +166,7 @@
100 } 166 }
101 } 167 }
102 168
103 - 169 +}
104 - //document.getElementById("workedHour").innerHTML = "Hours worked : " + parseInt(Number(getParam("offWork")))-parseInt(Number(getParam("workTime")));
105 -
106 - //document.getElementById("workTime").innerHTML = "working time : " + escape(getParam("workTime"));
107 - //document.getElementById("offWork").innerHTML = "time of work : " + getParam("offWork");
108 170
109 var body = document.querySelector('body'), 171 var body = document.querySelector('body'),
110 bar = document.querySelector('.progress-bar'), 172 bar = document.querySelector('.progress-bar'),
...@@ -112,10 +174,16 @@ ...@@ -112,10 +174,16 @@
112 i = 0, 174 i = 0,
113 throttle = 0.4; // 0-1 175 throttle = 0.4; // 0-1
114 (function draw() { 176 (function draw() {
115 - if(i <= 100) { 177 + var now = new Date();
116 - //var r = Math.random(); 178 + day = now.getDay();
117 179
180 + if(i <= 100) {
118 requestAnimationFrame(draw); 181 requestAnimationFrame(draw);
182 + if(isTodayWork(day, workingDay) != true){
183 + bar.style.width = 0 + '%';
184 + counter.innerHTML = '오늘 쉬는날';
185 + }
186 + else {
119 if(hours < workTime){ 187 if(hours < workTime){
120 bar.style.width = 0 + '%'; 188 bar.style.width = 0 + '%';
121 counter.innerHTML = '출근 안했당'; 189 counter.innerHTML = '출근 안했당';
...@@ -130,6 +198,8 @@ ...@@ -130,6 +198,8 @@
130 //if(r < throttle) { // Simulate d/l speed and uneven bitrate 198 //if(r < throttle) { // Simulate d/l speed and uneven bitrate
131 // i = i + r; 199 // i = i + r;
132 //} 200 //}
201 + }
202 +
133 } else {; 203 } else {;
134 bar.className += " done"; 204 bar.className += " done";
135 } 205 }
......