Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WhenMeet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem2023-2
WhenMeet
Commits
b6d43bbb
Commit
b6d43bbb
authored
1 year ago
by
이권민
Browse files
Options
Downloads
Patches
Plain Diff
[EDIT] 달력 로직 수정
parent
b926cf44
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
react-whenMeet/src/components/CalendarMonth.jsx
+355
-225
355 additions, 225 deletions
react-whenMeet/src/components/CalendarMonth.jsx
with
355 additions
and
225 deletions
react-whenMeet/src/components/CalendarMonth.jsx
+
355
−
225
View file @
b6d43bbb
import
React
,
{
useState
}
from
"
react
"
import
React
,
{
useState
}
from
"
react
"
;
import
MakeDay
from
"
./MakeDay
"
;
import
MakeHeader
from
"
./MakeHeader
"
;
import
TableCell
from
"
./TableCell
"
;
function
MakeCell
({
nowYear
,
nowMonth
,
usingDate
,
setUsingDate
,
startDate
,
endDate
,
setStartDate
,
setEndDate
}){
//주차 데이터를 담을 공간
const
calendarArr
=
[];
const
startDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
1
);
const
lastDay
=
new
Date
(
nowYear
,
nowMonth
,
0
);
const
lastMonthDate
=
new
Date
(
nowYear
,
nowMonth
-
1
,
0
).
getDate
();
let
nowDate
=
startDay
.
getDate
();
const
lastDate
=
lastDay
.
getDate
();
const
[
dragging
,
setDragging
]
=
useState
();
const
[
selectedDays
,
setSelectedDays
]
=
useState
([]);
//선택된 날짜
const
[
isDragging
,
setIsDragging
]
=
useState
(
false
);
//드래그 여부
const
[
dragStartDay
,
setDragStartDay
]
=
useState
(
null
);
//드래그 시작 날짜
const
[
dragEndDay
,
setDragEndDay
]
=
useState
();
const
[
finish
,
setFinish
]
=
useState
(
false
);
// 여기 달력 날짜 수정해야함
const
fDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
1
-
startDay
.
getDay
())
-
(
0
);
const
eDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
lastDate
+
6
-
lastDay
.
getDay
())
-
(
0
);
const
handleDragStart
=
(
newDate
,
idx
,
comp
)
=>
{
setIsDragging
(
!
isDragging
);
setDragStartDay
(
newDate
);
setFinish
(
false
);
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
};
const
handleDragWhile
=
(
newDate
,
idx
,
comp
)
=>
{
if
(
!
isDragging
)
return
;
setDragEndDay
(
newDate
);
setFinish
(
false
);
let
sd
=
dragStartDay
-
0
;
let
ed
=
newDate
-
0
;
if
(
sd
>
ed
){
let
tmp
=
sd
;
sd
=
ed
;
ed
=
tmp
;
}
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
const
elm2
=
document
.
getElementById
(
comp
);
// console.log(comp);
if
(
elm2
.
classList
.
contains
(
"
dragging
"
)){
for
(
let
day
=
ed
;
day
>=
comp
;
day
-=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
}
else
{
for
(
let
day
=
sd
;
day
<=
ed
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
add
(
"
dragging
"
)
}
}
function
MakeCell
({
nowYear
,
nowMonth
,
usingDate
,
setUsingDate
,
startDate
,
endDate
,
setStartDate
,
setEndDate
,
})
{
//주차 데이터를 담을 공간
const
calendarArr
=
[];
};
const
startDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
1
);
const
lastDay
=
new
Date
(
nowYear
,
nowMonth
,
0
);
const
lastMonthDate
=
new
Date
(
nowYear
,
nowMonth
-
1
,
0
).
getDate
();
// let startDate=""
;
// let end
Date
=""
;
let
nowDate
=
startDay
.
getDate
()
;
const
lastDate
=
lastDay
.
get
Date
()
;
const
[
dragging
,
setDragging
]
=
useState
();
const
[
selectedDays
,
setSelectedDays
]
=
useState
([]);
//선택된 날짜
const
[
isDragging
,
setIsDragging
]
=
useState
(
false
);
//드래그 여부
const
[
dragStartDay
,
setDragStartDay
]
=
useState
(
null
);
//드래그 시작 날짜
const
[
dragEndDay
,
setDragEndDay
]
=
useState
();
const
[
finish
,
setFinish
]
=
useState
(
false
);
const
handleDragEnd
=
(
newDate
,
idx
)
=>
{
setIsDragging
(
false
);
// setDragging("nope");
if
(
dragStartDay
-
0
<
dragEndDay
-
0
){
// startDate = dragStartDay.getFullYear() + '-' + (dragStartDay.getMonth()+1) + '-' + dragStartDay.getDate();
// endDate = dragEndDay.getFullYear() + '-' + (dragEndDay.getMonth()+1) + '-' + dragEndDay.getDate();
setStartDate
(
dragStartDay
.
getFullYear
()
+
'
-
'
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
))
setEndDate
(
dragEndDay
.
getFullYear
()
+
'
-
'
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
))
}
else
{
// endDate = dragStartDay.getFullYear() + '-' + (dragStartDay.getMonth()+1) + '-' + dragStartDay.getDate();
// startDate = dragEndDay.getFullYear() + '-' + (dragEndDay.getMonth()+1) + '-' + dragEndDay.getDate();
setStartDate
(
dragEndDay
.
getFullYear
()
+
'
-
'
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
))
setEndDate
(
dragStartDay
.
getFullYear
()
+
'
-
'
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
))
}
// console.log(startDate);
// console.log(endDate);
setUsingDate
({
startDate
:
startDate
,
endDate
:
endDate
})
setFinish
(
true
);
};
const
handleClick
=
(
newDate
,
idx
,
comp
)
=>
{
if
(
startDate
&&
!
finish
){
// endDate = newDate.getFullYear() + '-' + (newDate.getMonth()+1) + '-' + newDate.getDate();
setEndDate
(
newDate
.
getFullYear
()
+
'
-
'
+
String
(
newDate
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
newDate
.
getDate
()).
padStart
(
2
,
"
0
"
));
// console.log("e", endDate);
let
sd
=
new
Date
(
startDate
+
'
T00:00:00
'
)
-
0
;
let
ed
=
new
Date
(
newDate
)
-
0
;
// let sd = new Date(startDate) - 0;
// let ed = new Date(newDate) - 0;
// console.log(new Date(sd), new Date(ed), comp);
if
(
sd
>
ed
){
let
tmp
=
sd
;
sd
=
ed
;
ed
=
tmp
;
}
console
.
log
(
new
Date
(
sd
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
))
console
.
log
(
new
Date
(
ed
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
))
setStartDate
(
new
Date
(
sd
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
))
setEndDate
(
new
Date
(
ed
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
))
if
(
sd
<
fDay
)
sd
=
fDay
;
if
(
ed
>
eDay
)
ed
=
eDay
;
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
const
elm2
=
document
.
getElementById
(
comp
);
if
(
elm2
.
classList
.
contains
(
"
dragging
"
)){
for
(
let
day
=
ed
;
day
>=
comp
;
day
-=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
}
else
{
for
(
let
day
=
sd
;
day
<=
ed
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
// console.log(elm, day);
elm
.
classList
.
add
(
"
dragging
"
)
}
}
setUsingDate
({
startDate
:
new
Date
(
sd
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
),
endDate
:
new
Date
(
ed
).
getFullYear
()
+
'
-
'
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
)
})
setFinish
(
true
);
// 여기 달력 날짜 수정해야함
const
fDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
1
-
startDay
.
getDay
())
-
0
;
const
eDay
=
new
Date
(
nowYear
,
nowMonth
-
1
,
lastDate
+
6
-
lastDay
.
getDay
())
-
0
;
const
handleDragStart
=
(
newDate
,
idx
,
comp
)
=>
{
setIsDragging
(
!
isDragging
);
setDragStartDay
(
newDate
);
setFinish
(
false
);
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
};
const
handleDragWhile
=
(
newDate
,
idx
,
comp
)
=>
{
if
(
!
isDragging
)
return
;
setDragEndDay
(
newDate
);
setFinish
(
false
);
let
sd
=
dragStartDay
-
0
;
let
ed
=
newDate
-
0
;
if
(
sd
>
ed
)
{
let
tmp
=
sd
;
sd
=
ed
;
ed
=
tmp
;
}
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
const
elm2
=
document
.
getElementById
(
comp
);
// console.log(comp);
if
(
elm2
.
classList
.
contains
(
"
dragging
"
))
{
for
(
let
day
=
ed
;
day
>=
comp
;
day
-=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
}
else
{
for
(
let
day
=
sd
;
day
<=
ed
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
add
(
"
dragging
"
);
}
}
};
// let startDate="";
// let endDate="";
const
handleDragEnd
=
(
newDate
,
idx
)
=>
{
setIsDragging
(
false
);
// setDragging("nope");
if
(
dragStartDay
-
0
<
dragEndDay
-
0
)
{
// startDate = dragStartDay.getFullYear() + '-' + (dragStartDay.getMonth()+1) + '-' + dragStartDay.getDate();
// endDate = dragEndDay.getFullYear() + '-' + (dragEndDay.getMonth()+1) + '-' + dragEndDay.getDate();
setStartDate
(
dragStartDay
.
getFullYear
()
+
"
-
"
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
setEndDate
(
dragEndDay
.
getFullYear
()
+
"
-
"
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
setUsingDate
({
startDate
:
dragStartDay
.
getFullYear
()
+
"
-
"
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
),
endDate
:
dragEndDay
.
getFullYear
()
+
"
-
"
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
),
});
}
else
{
// endDate = dragStartDay.getFullYear() + '-' + (dragStartDay.getMonth()+1) + '-' + dragStartDay.getDate();
// startDate = dragEndDay.getFullYear() + '-' + (dragEndDay.getMonth()+1) + '-' + dragEndDay.getDate();
setStartDate
(
dragEndDay
.
getFullYear
()
+
"
-
"
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
setEndDate
(
dragStartDay
.
getFullYear
()
+
"
-
"
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
setUsingDate
({
startDate
:
dragEndDay
.
getFullYear
()
+
"
-
"
+
String
(
dragEndDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragEndDay
.
getDate
()).
padStart
(
2
,
"
0
"
),
endDate
:
dragStartDay
.
getFullYear
()
+
"
-
"
+
String
(
dragStartDay
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
dragStartDay
.
getDate
()).
padStart
(
2
,
"
0
"
),
});
}
// console.log(startDate);
// console.log(endDate);
setFinish
(
true
);
};
const
handleClick
=
(
newDate
,
idx
,
comp
)
=>
{
if
(
startDate
&&
!
finish
)
{
// endDate = newDate.getFullYear() + '-' + (newDate.getMonth()+1) + '-' + newDate.getDate();
setEndDate
(
newDate
.
getFullYear
()
+
"
-
"
+
String
(
newDate
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
newDate
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
// console.log("e", endDate);
let
sd
=
new
Date
(
startDate
+
"
T00:00:00
"
)
-
0
;
let
ed
=
new
Date
(
newDate
)
-
0
;
// let sd = new Date(startDate) - 0;
// let ed = new Date(newDate) - 0;
// console.log(new Date(sd), new Date(ed), comp);
if
(
sd
>
ed
)
{
let
tmp
=
sd
;
sd
=
ed
;
ed
=
tmp
;
}
console
.
log
(
new
Date
(
sd
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
)
);
console
.
log
(
new
Date
(
ed
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
)
);
setStartDate
(
new
Date
(
sd
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
)
);
setEndDate
(
new
Date
(
ed
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
)
);
if
(
sd
<
fDay
)
sd
=
fDay
;
if
(
ed
>
eDay
)
ed
=
eDay
;
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
const
elm2
=
document
.
getElementById
(
comp
);
if
(
elm2
.
classList
.
contains
(
"
dragging
"
))
{
for
(
let
day
=
ed
;
day
>=
comp
;
day
-=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
else
{
console
.
log
(
fDay
,
eDay
,
new
Date
(
fDay
),
new
Date
(
eDay
))
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
// startDate = newDate.getFullYear() + '-' + (newDate.getMonth()+1) + '-' + newDate.getDate();
setStartDate
(
newDate
.
getFullYear
()
+
'
-
'
+
String
(
newDate
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
'
-
'
+
String
(
newDate
.
getDate
()).
padStart
(
2
,
"
0
"
));
const
elm
=
document
.
getElementById
(
newDate
-
0
);
elm
.
classList
.
add
(
"
dragging
"
)
// console.log("s", startDate);
setFinish
(
false
);
}
else
{
for
(
let
day
=
sd
;
day
<=
ed
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
// console.log(elm, day);
elm
.
classList
.
add
(
"
dragging
"
);
}
}
setUsingDate
({
startDate
:
new
Date
(
sd
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
sd
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
sd
).
getDate
()).
padStart
(
2
,
"
0
"
),
endDate
:
new
Date
(
ed
).
getFullYear
()
+
"
-
"
+
String
(
new
Date
(
ed
).
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
new
Date
(
ed
).
getDate
()).
padStart
(
2
,
"
0
"
),
});
setFinish
(
true
);
}
else
{
console
.
log
(
fDay
,
eDay
,
new
Date
(
fDay
),
new
Date
(
eDay
));
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
// startDate = newDate.getFullYear() + '-' + (newDate.getMonth()+1) + '-' + newDate.getDate();
setStartDate
(
newDate
.
getFullYear
()
+
"
-
"
+
String
(
newDate
.
getMonth
()
+
1
).
padStart
(
2
,
"
0
"
)
+
"
-
"
+
String
(
newDate
.
getDate
()).
padStart
(
2
,
"
0
"
)
);
const
elm
=
document
.
getElementById
(
newDate
-
0
);
elm
.
classList
.
add
(
"
dragging
"
);
// console.log("s", startDate);
setFinish
(
false
);
}
};
const
removeDrag
=
(
newDate
)
=>
{
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
)
}
// const elm = document.getElementById(newDate - 0);
// elm.classList.add("dragging")
// console.log(`${newDate.getFullYear()}-${newDate.getMonth()+1}-${newDate.getDate()}`)
const
removeDrag
=
(
newDate
)
=>
{
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
elm
=
document
.
getElementById
(
day
);
elm
.
classList
.
remove
(
"
dragging
"
);
}
// const elm = document.getElementById(newDate - 0);
// elm.classList.add("dragging")
// console.log(`${newDate.getFullYear()}-${newDate.getMonth()+1}-${newDate.getDate()}`)
};
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
(
60
*
60
*
24
*
1000
)){
const
tmpArr
=
[];
for
(
let
i
=
0
;
i
<
7
;
i
++
){
let
cn
=
"
cella
"
;
const
newDate
=
new
Date
(
day
);
if
(
newDate
.
getMonth
()
+
1
!==
nowMonth
)
cn
=
"
cellb
"
;
// console.log(startDate, endDate);
// console.log(new Date(day), new Date(startDate+'T00:00:00'), new Date(endDate+'T00:00:00'))
if
(
day
>=
new
Date
(
startDate
+
'
T00:00:00
'
)
-
0
&&
day
<=
new
Date
(
endDate
+
'
T00:00:00
'
)
-
0
){
cn
+=
"
dragging
"
;
tmpArr
.
push
(
<
TableCell
k
=
{
day
}
cn
=
{
cn
}
handleClick
=
{
handleClick
}
newDate
=
{
newDate
}
hds
=
{
handleDragStart
}
hdw
=
{
handleDragWhile
}
hde
=
{
handleDragEnd
}
i
=
{
i
}
value
=
{
newDate
.
getDate
()
}
/>
);
}
else
{
tmpArr
.
push
(
<
TableCell
k
=
{
day
}
cn
=
{
cn
}
handleClick
=
{
handleClick
}
newDate
=
{
newDate
}
hds
=
{
handleDragStart
}
hdw
=
{
handleDragWhile
}
hde
=
{
handleDragEnd
}
i
=
{
i
}
value
=
{
newDate
.
getDate
()
}
/>
);
}
day
+=
(
60
*
60
*
24
*
1000
)
}
calendarArr
.
push
(
<
tr
>
{
tmpArr
}
</
tr
>
for
(
let
day
=
fDay
;
day
<=
eDay
;
day
+=
60
*
60
*
24
*
1000
)
{
const
tmpArr
=
[];
for
(
let
i
=
0
;
i
<
7
;
i
++
)
{
let
cn
=
"
cella
"
;
const
newDate
=
new
Date
(
day
);
if
(
newDate
.
getMonth
()
+
1
!==
nowMonth
)
cn
=
"
cellb
"
;
// console.log(startDate, endDate);
// console.log(new Date(day), new Date(startDate+'T00:00:00'), new Date(endDate+'T00:00:00'))
if
(
day
>=
new
Date
(
startDate
+
"
T00:00:00
"
)
-
0
&&
day
<=
new
Date
(
endDate
+
"
T00:00:00
"
)
-
0
)
{
cn
+=
"
dragging
"
;
tmpArr
.
push
(
<
TableCell
k
=
{
day
}
cn
=
{
cn
}
handleClick
=
{
handleClick
}
newDate
=
{
newDate
}
hds
=
{
handleDragStart
}
hdw
=
{
handleDragWhile
}
hde
=
{
handleDragEnd
}
i
=
{
i
}
value
=
{
newDate
.
getDate
()
}
/>
);
day
-=
(
60
*
60
*
24
*
1000
)
}
else
{
tmpArr
.
push
(
<
TableCell
k
=
{
day
}
cn
=
{
cn
}
handleClick
=
{
handleClick
}
newDate
=
{
newDate
}
hds
=
{
handleDragStart
}
hdw
=
{
handleDragWhile
}
hde
=
{
handleDragEnd
}
i
=
{
i
}
value
=
{
newDate
.
getDate
()
}
/>
);
}
day
+=
60
*
60
*
24
*
1000
;
}
calendarArr
.
push
(<
tr
>
{
tmpArr
}
</
tr
>);
return
(
<
tbody
>
{
calendarArr
}
</
tbody
>
);
day
-=
60
*
60
*
24
*
1000
;
}
return
<
tbody
>
{
calendarArr
}
</
tbody
>;
}
function
CalendarMonth
({
usingDate
,
setUsingDate
}){
const
[
currentDay
,
setCurrentDay
]
=
useState
(
new
Date
());
// 일요일 0 시작
const
nowDay
=
currentDay
.
getDay
();
const
[
nowDate
,
setNowDate
]
=
useState
(
currentDay
.
getDate
());
const
[
nowMonth
,
setNowMonth
]
=
useState
(
currentDay
.
getMonth
()
+
1
);
// zero-base
const
[
nowYear
,
setNowYear
]
=
useState
(
currentDay
.
getFullYear
());
const
[
startDate
,
setStartDate
]
=
useState
();
const
[
endDate
,
setEndDate
]
=
useState
();
const
prevMonth
=
()
=>
{
let
newMonth
=
nowMonth
-
1
;
if
(
newMonth
<
1
){
newMonth
=
nowMonth
+
11
;
setNowYear
(
nowYear
-
1
);
}
setNowMonth
(
newMonth
);
setCurrentDay
(
new
Date
(
nowYear
,
nowMonth
,
nowDate
));
function
CalendarMonth
({
usingDate
,
setUsingDate
})
{
const
[
currentDay
,
setCurrentDay
]
=
useState
(
new
Date
());
// 일요일 0 시작
const
nowDay
=
currentDay
.
getDay
();
const
[
nowDate
,
setNowDate
]
=
useState
(
currentDay
.
getDate
());
const
[
nowMonth
,
setNowMonth
]
=
useState
(
currentDay
.
getMonth
()
+
1
);
// zero-base
const
[
nowYear
,
setNowYear
]
=
useState
(
currentDay
.
getFullYear
());
const
[
startDate
,
setStartDate
]
=
useState
();
const
[
endDate
,
setEndDate
]
=
useState
();
const
prevMonth
=
()
=>
{
let
newMonth
=
nowMonth
-
1
;
if
(
newMonth
<
1
)
{
newMonth
=
nowMonth
+
11
;
setNowYear
(
nowYear
-
1
);
}
const
nextMonth
=
()
=>
{
let
newMonth
=
nowMonth
+
1
;
if
(
newMonth
>
12
){
ne
w
Month
=
nowMonth
-
11
;
setNowYear
(
nowYear
+
1
)
;
}
setNo
wMonth
(
ne
wMonth
)
;
set
CurrentDay
(
new
Date
(
nowYear
,
nowMonth
,
nowDate
)
);
setNowMonth
(
newMonth
);
setCurrentDay
(
new
Date
(
nowYear
,
nowMonth
,
nowDate
))
;
};
const
ne
xt
Month
=
()
=>
{
let
newMonth
=
nowMonth
+
1
;
if
(
newMonth
>
12
)
{
ne
wMonth
=
no
wMonth
-
11
;
set
NowYear
(
nowYear
+
1
);
}
setNowMonth
(
newMonth
);
setCurrentDay
(
new
Date
(
nowYear
,
nowMonth
,
nowDate
));
};
return
(
<
div
className
=
"calendar"
>
<
h1
>
달력
</
h1
>
<
MakeHeader
nowMonth
=
{
nowMonth
}
prevMonth
=
{
prevMonth
}
nextMonth
=
{
nextMonth
}
></
MakeHeader
>
<
h1
>
{
nowYear
}
</
h1
>
<
table
className
=
"calendarTable"
>
<
MakeDay
/>
<
MakeCell
nowYear
=
{
nowYear
}
nowMonth
=
{
nowMonth
}
usingDate
=
{
usingDate
}
setUsingDate
=
{
setUsingDate
}
startDate
=
{
startDate
}
endDate
=
{
endDate
}
setStartDate
=
{
setStartDate
}
setEndDate
=
{
setEndDate
}
></
MakeCell
>
</
table
>
</
div
>
);
return
(
<
div
className
=
"calendar"
>
<
h1
>
달력
</
h1
>
<
MakeHeader
nowMonth
=
{
nowMonth
}
prevMonth
=
{
prevMonth
}
nextMonth
=
{
nextMonth
}
></
MakeHeader
>
<
h1
>
{
nowYear
}
</
h1
>
<
table
className
=
"calendarTable"
>
<
MakeDay
/>
<
MakeCell
nowYear
=
{
nowYear
}
nowMonth
=
{
nowMonth
}
usingDate
=
{
usingDate
}
setUsingDate
=
{
setUsingDate
}
startDate
=
{
startDate
}
endDate
=
{
endDate
}
setStartDate
=
{
setStartDate
}
setEndDate
=
{
setEndDate
}
></
MakeCell
>
</
table
>
</
div
>
);
}
export
default
CalendarMonth
;
\ No newline at end of file
export
default
CalendarMonth
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment