Skip to content

Commit 7b24368

Browse files
authored
Merge pull request #157 from imaginer-dev/73----날짜-및-시간-포맷
73 날짜 및 시간 포맷
2 parents d54a436 + 92cd7f5 commit 7b24368

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Calendar from './components/common/Calendar';
22

3-
43
function App() {
54
return (
65
<div>

src/components/common/Calendar.tsx

Lines changed: 5 additions & 3 deletions
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;
@@ -18,7 +19,6 @@ type Event = {
1819
};
1920
*/
2021

21-
2222
interface EventInfo {
2323
timeText: string;
2424
event: {
@@ -214,7 +214,6 @@ export default function Calendar() {
214214
<div className="mt-10">{selectedDate && <EventCards events={selectedEvents} date={selectedDate} />}</div>
215215
</div>
216216
);
217-
218217
}
219218

220219
function renderEventContent(eventInfo: EventInfo) {
@@ -246,10 +245,13 @@ function EventCards({ events, date }: EventCardsProps) {
246245
<h2 className="ml-2">{date}</h2>
247246
<div className="flex gap-5 overflow-x-auto">
248247
{events.map((event, index) => {
248+
const eventDateRange = formatDateRange(event.start, event.end);
249+
const eventTime = formatTime(event.start);
249250
return (
250251
<div key={index} className="relative min-h-[150px] min-w-[240px] bg-white p-4 text-black">
251252
<h3>{event.title}</h3>
252-
<p className="mt-1 text-xs">{event.start === event.end ? event.start : `${event.start}~${event.end}`}</p>
253+
<p className="mt-1 text-xs">{eventDateRange}</p>
254+
<p className="mt-1 text-xs">{eventTime}</p>
253255
{/* 메뉴 버튼 */}
254256
<div
255257
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)