Skip to content

Commit acb13ab

Browse files
committed
refactor: 날짜 포맷팅 함수 이동 및 중복 제거
1 parent af659ad commit acb13ab

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/components/PostCard/PostCard.vue

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<script setup lang="ts">
3131
import { getCategoryColor } from "@/constants/colors";
32+
import { formatDate } from "@/utils/date";
3233
import type { Post } from "@/models/PostModel";
3334
import "./PostCard.css";
3435
@@ -38,19 +39,6 @@ interface Props {
3839
3940
defineProps<Props>();
4041
41-
// 날짜 포맷팅 함수 (yyyy-mm-dd 형식)
42-
function formatDate(dateString: string) {
43-
const date = new Date(dateString);
44-
return date
45-
.toLocaleDateString("ko-KR", {
46-
year: "numeric",
47-
month: "2-digit",
48-
day: "2-digit",
49-
})
50-
.replace(/\. /g, "-")
51-
.replace(/\.$/, "");
52-
}
53-
5442
function navigateToPost(url: string) {
5543
window.location.href = url;
5644
}

src/utils/date.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function formatDate(dateString: string): string {
2+
const options: Intl.DateTimeFormatOptions = {
3+
year: "numeric",
4+
month: "long",
5+
day: "numeric",
6+
};
7+
const date = new Date(dateString);
8+
return date.toLocaleDateString(undefined, options);
9+
}

0 commit comments

Comments
 (0)