88import styled from "@emotion/styled" ;
99import type { Event } from "@eventsTypes" ;
1010import { addEvent } from "@firebase/clientApp" ;
11+ import { subtractDateAndTime } from "@lib/days" ;
1112import type { NewEvent } from "@newTypes" ;
1213import { Timestamp } from "firebase/firestore" ;
1314import { useRouter } from "next/router" ;
@@ -17,12 +18,27 @@ import { SubmitHandler, useForm } from "react-hook-form";
1718import type { NextPageWithLayout } from "./_app" ;
1819
1920const fromFormDataToEvent = ( data : NewEvent ) : Omit < Event , "id" > => {
21+ /**
22+ * startDate와 endDate는 html의 input type=date에서 제공 받습니다.
23+ * 이로인해 2022-12-21형식으로 받게 됩니다.
24+ * 이를 date로 변환할 경우 UTC기준 00시로 제공되기에
25+ * 한국의 00시로 맞추어주기 위해 9시간뺍니다.
26+ */
27+ const KOR_UTC_DIFFERENCE_HOUR = 9 ;
2028 const { name, maxCapacity, startDate, endDate } = data ;
2129 return {
2230 name,
2331 maxCapacity,
24- startDate : Timestamp . fromDate ( new Date ( startDate ) ) ,
25- endDate : Timestamp . fromDate ( new Date ( endDate ) ) ,
32+ startDate : Timestamp . fromDate (
33+ subtractDateAndTime ( new Date ( startDate ) , {
34+ hours : KOR_UTC_DIFFERENCE_HOUR ,
35+ } )
36+ ) ,
37+ endDate : Timestamp . fromDate (
38+ subtractDateAndTime ( new Date ( endDate ) , {
39+ hours : KOR_UTC_DIFFERENCE_HOUR ,
40+ } )
41+ ) ,
2642 attendees : [ ] ,
2743 } ;
2844} ;
0 commit comments