Skip to content

Commit 931d273

Browse files
committed
feat: 73 날짜 및 시간 포맷
1 parent d54a436 commit 931d273

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/components/common/Calendar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useRef, useState, useEffect, useCallback } from 'react';
77
import { useEventState } from '@/stores/myEventsStore';
88
import { getPersonalSchedule } from '@/apis/personalScheduleApi';
99
import { Events } from '../../utils/index.ts';
10+
import { formatDateRange, formatTime } from '../../utils/dateUtils';
1011
/*
1112
type Event = {
1213
title: string;
@@ -246,10 +247,13 @@ function EventCards({ events, date }: EventCardsProps) {
246247
<h2 className="ml-2">{date}</h2>
247248
<div className="flex gap-5 overflow-x-auto">
248249
{events.map((event, index) => {
250+
const eventDateRange = formatDateRange(event.start, event.end);
251+
const eventTime = formatTime(event.start);
249252
return (
250253
<div key={index} className="relative min-h-[150px] min-w-[240px] bg-white p-4 text-black">
251254
<h3>{event.title}</h3>
252-
<p className="mt-1 text-xs">{event.start === event.end ? event.start : `${event.start}~${event.end}`}</p>
255+
<p className="mt-1 text-xs">{eventDateRange}</p>
256+
<p className="mt-1 text-xs">{eventTime}</p>
253257
{/* 메뉴 버튼 */}
254258
<div
255259
className="absolute right-2 top-2 flex cursor-pointer flex-col items-center justify-center"

src/utils/dateUtils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,26 @@ export const dateToYYMMDD = (date: Date) => {
44
const day = date.getDate();
55
return `${year}-${month < 10 ? `0${month}` : month}-${day < 10 ? `0${day}` : day}`;
66
};
7+
8+
export function formatDateRange(start: string, end: string): string {
9+
const startDate = new Date(start);
10+
const endDate = new Date(end);
11+
const startStr = startDate.toISOString().split('T')[0];
12+
const endStr = endDate.toISOString().split('T')[0];
13+
14+
return startStr === endStr ? startStr : `${startStr}~${endStr}`;
15+
}
16+
17+
export function formatTime(date: string): string {
18+
const newDate = new Date(date);
19+
const hoursUTC = newDate.getUTCHours();
20+
const minutesUTC = newDate.getUTCMinutes();
21+
22+
// 한국 시간대로 변환 (UTC+9)
23+
const hoursKST = (hoursUTC + 9) % 24;
24+
const isAM = hoursKST < 12;
25+
const formattedHours = isAM ? hoursKST : hoursKST - 12;
26+
const formattedMinutes = minutesUTC < 10 ? `0${minutesUTC}` : minutesUTC;
27+
28+
return isAM ? `오전${formattedHours}:${formattedMinutes}` : `오후${formattedHours}:${formattedMinutes}`;
29+
}

0 commit comments

Comments
 (0)