Skip to content

Commit

Permalink
Wedding day DateFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Jan 18, 2025
1 parent 41a3b98 commit beba123
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/component/template/component/weddingday/WeddingDayTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styled from "styled-components";
import WeddingSchedule from "@remote/value/WeddingSchedule";
import BaseInfo from "@remote/value/BaseInfo";
import DDay, {DDayStyle} from "@src/component/template/component/weddingday/DDay";
import {format, parse} from "date-fns";

interface WeddingDayProps {
baseInfo: BaseInfo;
Expand All @@ -22,9 +23,9 @@ function WeddingDayTemplate(
}: WeddingDayProps
) {
const weddingDate = weddingSchedule.weddingDate;
const date = weddingDate ? parseDate(weddingDate) : null; // 입력 날짜 파싱

const calendar = date ? getCalendar(date) : null;
const date = parse(weddingDate, 'yyyy-MM-dd', new Date());
const isValidDate = !isNaN(date.getTime());
const calendar = isValidDate ? getCalendar(date) : null;

if (!weddingSchedule.calendar && !weddingSchedule.dDay) {
return (
Expand All @@ -37,8 +38,8 @@ function WeddingDayTemplate(
height: '100vh'
}}
>
<Text size={36} weight={300} color={colors.g500}>{weddingSchedule.weddingDate}</Text>
<Text size={36} weight={300} color={colors.g500}>{weddingSchedule.weddingDate}</Text>
<Text size={36} weight={300} color={colors.g500}>{isValidDate && date.getFullYear()}</Text>
<Text size={36} weight={300} color={colors.g500}>{isValidDate && format(date, 'MMMM d')}</Text>
</Column>
)
}
Expand Down Expand Up @@ -200,9 +201,4 @@ function getCalendar(date: Date) {
);
}

function parseDate(dateString: string): Date {
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day); // month는 0부터 시작하므로 1을 빼줍니다.
}

export default WeddingDayTemplate;

0 comments on commit beba123

Please sign in to comment.