Skip to content

Commit ee42ed6

Browse files
authored
[25.05.14 / TASK-190] Refactor - UTC -> KST 변환 반영 (#34)
1 parent 7ace24d commit ee42ed6

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

src/app/(auth-required)/main/Content.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Button, Dropdown, Check } from '@/components';
88
import { postList, postSummary } from '@/apis';
99
import { PATHS, SORT_TYPE } from '@/constants';
1010
import { SortKey, SortValue } from '@/types';
11+
import { convertDateToKST } from '@/utils';
1112
import { Section, Summary } from './components';
1213

1314
const sorts: Array<[SortKey, SortValue]> = Object.entries(SORT_TYPE) as Array<[SortKey, SortValue]>;
@@ -50,15 +51,17 @@ export const Content = () => {
5051
<div className="w-full flex flex-col gap-[30px] overflow-auto max-TBL:gap-[20px]">
5152
<div className="flex h-fit flex-col items-center p-[20px] bg-BG-SUB gap-5 rounded-[4px]">
5253
<span className="text-TEXT-ALT text-ST5 MBI:hidden">
53-
마지막 업데이트 : {summaries?.stats?.lastUpdatedDate || 'NULL'}
54+
마지막 업데이트 :{' '}
55+
{convertDateToKST(summaries?.stats?.lastUpdatedDate)?.iso || '업데이트 중..'}
5456
</span>
5557
<div className="w-full flex items-center justify-between flex-wrap max-MBI:justify-center max-MBI:gap-4">
5658
<div className="flex items-center gap-3">
5759
<Button size="SMALL" disabled>
5860
새로고침
5961
</Button>
6062
<span className="text-TEXT-ALT text-ST4 max-TBL:text-ST5 max-MBI:hidden">
61-
마지막 업데이트 : {summaries?.stats?.lastUpdatedDate || '업데이트 중..'}
63+
마지막 업데이트 :{' '}
64+
{convertDateToKST(summaries?.stats?.lastUpdatedDate)?.iso || '업데이트 중..'}
6265
</span>
6366
</div>
6467
<div className="flex items-center gap-3">

src/app/(auth-required)/main/components/Section/Graph.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Dropdown, Input } from '@/components';
1818
import { PostDetailValue } from '@/types';
1919
import { useResponsive } from '@/hooks';
2020
import { postDetail } from '@/apis';
21+
import { convertDateToKST } from '@/utils';
2122

2223
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);
2324

@@ -50,7 +51,7 @@ export const Graph = ({ id, releasedAt }: IProp) => {
5051
queryKey: [PATHS.DETAIL, type, id],
5152
queryFn: async () => await postDetail(id, type.start, type.end),
5253
select: ({ post }) => ({
53-
labels: post.map((i) => i.date.split('T')[0]),
54+
labels: post.map((i) => convertDateToKST(i.date)?.short),
5455
datasets: [
5556
{
5657
label: type.type,
@@ -87,7 +88,7 @@ export const Graph = ({ id, releasedAt }: IProp) => {
8788
size={isMBI ? 'SMALL' : 'MEDIUM'}
8889
form="SMALL"
8990
value={type.start}
90-
min={releasedAt.split('T')[0]}
91+
min={convertDateToKST(releasedAt)?.short}
9192
onChange={(e) => setType({ ...type, start: e.target.value })}
9293
placeholder="시작 날짜"
9394
type="date"
@@ -97,7 +98,7 @@ export const Graph = ({ id, releasedAt }: IProp) => {
9798
size={isMBI ? 'SMALL' : 'MEDIUM'}
9899
form="SMALL"
99100
value={type.end}
100-
min={type.start ? type.start : releasedAt.split('T')[0]}
101+
min={type.start ? type.start : convertDateToKST(releasedAt)?.short}
101102
onChange={(e) => setType({ ...type, end: e.target.value })}
102103
placeholder="종료 날짜"
103104
type="date"

src/app/(auth-required)/main/components/Section/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { COLORS, env, PATHS } from '@/constants';
66
import { PostType, UserDto } from '@/types';
77
import { Icon } from '@/components';
88
import { getQueryClient } from '@/utils/queryUtil';
9+
import { convertDateToKST } from '@/utils';
910
import { Graph } from './Graph';
1011

1112
export const Section = (p: PostType) => {
@@ -39,12 +40,12 @@ export const Section = (p: PostType) => {
3940
</div>
4041

4142
<span className="text-TEXT-ALT text-ST4 MBI:content-[attr(data-date)] max-MBI:hidden">
42-
{p.releasedAt.split('T')[0]}
43+
{convertDateToKST(p.releasedAt)?.short}
4344
</span>
4445
</div>
4546

4647
<div className="flex items-center text-ST4 justify-between text-TEXT-ALT gap-1 max-TBL:text-ST5 max-MBI:w-full">
47-
<span className="MBI:hidden">{p.releasedAt.split('T')[0]}</span>
48+
<span className="MBI:hidden">{convertDateToKST(p.releasedAt)?.short}</span>
4849
<div className="flex flex-wrap items-center gap-[6px]">
4950
<span className='after:content-["/"] after:ml-2'>{parseNumber(p.views)}</span>
5051
<span className="flex items-center before:text-PRIMARY-SUB before:content-['↑'] before:mr-1 after:ml-2 after:content-['/']">

src/utils/dateUtil.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const KST_DIFF = 9 * 60 * 60 * 1000;
2+
3+
/**
4+
* 주어진 날짜 문자열을 KST(한국 표준시) 기준으로 변환함.
5+
*
6+
* @param {string} [date] - 변환할 날짜 문자열 (예: "2025-05-15T08:00:00Z")
7+
* @returns {{
8+
* short: string; // "YYYY-MM-DD" 형식의 날짜 문자열
9+
* iso: string; // ISO 8601 형식 + KST 오프셋 포함 문자열
10+
* full: Date; // KST로 보정된 Date 객체
11+
* } | undefined} 날짜가 없으면 undefined 반환
12+
*/
13+
14+
export const convertDateToKST = (date?: string) => {
15+
if (!date) return;
16+
const converted = new Date(new Date(date).getTime() + KST_DIFF);
17+
18+
const year = converted.getFullYear();
19+
const month = (converted.getMonth() + 1).toString().padStart(2, '0');
20+
const day = converted.getDate().toString().padStart(2, '0');
21+
const hours = converted.getHours().toString().padStart(2, '0');
22+
const minutes = converted.getMinutes().toString().padStart(2, '0');
23+
const seconds = converted.getSeconds().toString().padStart(2, '0');
24+
25+
return {
26+
short: `${converted.getFullYear()}-${(converted.getMonth() + 1).toString().padStart(2, '0')}-${converted.getDate()}`,
27+
iso: `${year}-${month}-${day}T${hours}:${minutes}:${seconds}+09:00`,
28+
full: converted,
29+
};
30+
};

src/utils/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './componentUtil';
22
export * from './numberUtil';
3+
export * from './dateUtil';

0 commit comments

Comments
 (0)