Skip to content

Commit

Permalink
3 : 주말, 평일 계산 (수정필요)
Browse files Browse the repository at this point in the history
  • Loading branch information
onejuice98 committed Jan 16, 2023
1 parent ce48075 commit 2115984
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/components/dDay/Ddays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,51 @@ const DDays = () => {
const gapNum = dDay - toDay;
setDays(Math.ceil(gapNum / (1000 * 60 * 60 * 24)));
}, []);
return <div className="font-mono font-bold text-sm">전역까지 D-{days}</div>;
const dDay: any = new Date("2023-06-30 00:00:00");

const toDay = new Date();
const toDayMonth = toDay.getMonth();
const toDayYear = toDay.getFullYear();
const toDayDate = toDay.getDate();
const toDayDay = toDay.getDay();
const DAYS = ["일", "월", "화", "수", "목", "금", "토"];
/*
const weeks = Math.floor(days / 7);
if (toDay.getDay() > dDay.getDay()) {
if (dDay.getDay() === 0) {
console.log((weeks + 1) * 2 + 1);
} else {
console.log((weeks + 1) * 2);
}
} else {
if (dDay.getDay() === 0) {
console.log(weeks * 2 + 1);
} else {
console.log(weeks * 2);
}
}*/

let weekend = 0;
let weekday = 0;
while (true) {
let tempDate = toDay;
if (tempDate.getTime() > dDay.getTime()) {
break;
} else {
let tmp = tempDate.getDay();
if (tmp == 0 || tmp == 6) {
weekend++;
} else {
weekday++;
}
tempDate.setDate(toDay.getDate() + 1);
}
}
return (
<div className="font-mono font-bold text-sm">
전역까지 D-{days} 평일 : {weekday} 주말 : {weekend}
</div>
);
};

export default DDays;

0 comments on commit 2115984

Please sign in to comment.