Skip to content

Commit 9225b4b

Browse files
committed
fix:convert startDate and endDate time when make a new event
1 parent de1b611 commit 9225b4b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pages/new.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import styled from "@emotion/styled";
99
import type { Event } from "@eventsTypes";
1010
import { addEvent } from "@firebase/clientApp";
11+
import { subtractDateAndTime } from "@lib/days";
1112
import type { NewEvent } from "@newTypes";
1213
import { Timestamp } from "firebase/firestore";
1314
import { useRouter } from "next/router";
@@ -17,12 +18,27 @@ import { SubmitHandler, useForm } from "react-hook-form";
1718
import type { NextPageWithLayout } from "./_app";
1819

1920
const 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

Comments
 (0)