Skip to content

Commit

Permalink
feat: 날짜 포맷팅 util 함수의 정규표현식 상수로 관리
Browse files Browse the repository at this point in the history
  • Loading branch information
00kang committed Nov 8, 2024
1 parent b2f1c93 commit 37b9239
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/common/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as S from "./Calendar.style";
import useCalendar from "@/hooks/common/useCalendar";
import Icon from "@/components/common/icon/Icon";
import DAYS from "@/constants/days";
import { DAYS } from "@/constants/days";
import { areDatesEqual } from "@/utils/dateFormatter";

export interface CalendarProps {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/constants/days.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const DAYS = ["일", "월", "화", "수", "목", "금", "토"] as const;
export const DAYS = ["일", "월", "화", "수", "목", "금", "토"] as const;

export default DAYS;
export const DATE_FORMAT = {
PATTERN: /(\d{4})-(\d{2})(\d{2})T/,
REPLACEMENT: "$1-$2-$3T",
} as const;
4 changes: 3 additions & 1 deletion frontend/src/utils/dateFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DATE_FORMAT } from "@/constants/days";

// 공통 포맷팅 함수
const formatStringToDate = (
dateString: string,
Expand Down Expand Up @@ -126,7 +128,7 @@ export const convertDateToKorean = (dateString: string) => {

// 알람용 시간 표기
export const formatTimeAgo = (dateString: string): string => {
const formattedDateString = dateString.replace(/(\d{4})-(\d{2})(\d{2})T/, "$1-$2-$3T");
const formattedDateString = dateString.replace(DATE_FORMAT.PATTERN, DATE_FORMAT.REPLACEMENT);

const date = new Date(formattedDateString);
const now = new Date();
Expand Down

0 comments on commit 37b9239

Please sign in to comment.