generated from pricelees/issue-pr-template
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
export const formatDate = (dateStr: string) => {
|
|
const date = new Date(dateStr);
|
|
const currentYear = new Date().getFullYear();
|
|
const reservationYear = date.getFullYear();
|
|
|
|
const days = ['일', '월', '화', '수', '목', '금', '토'];
|
|
const dayOfWeek = days[date.getDay()];
|
|
const month = date.getMonth() + 1;
|
|
const day = date.getDate();
|
|
|
|
let datePart = '';
|
|
if (currentYear === reservationYear) {
|
|
datePart = `${month}월 ${day}일(${dayOfWeek})`;
|
|
} else {
|
|
datePart = `${reservationYear}년 ${month}월 ${day}일(${dayOfWeek})`;
|
|
}
|
|
|
|
return datePart;
|
|
};
|
|
|
|
export const formatTime = (timeStr: string) => {
|
|
const [hourStr, minuteStr] = timeStr.split(':');
|
|
let hours = parseInt(hourStr, 10);
|
|
const minutes = parseInt(minuteStr, 10);
|
|
const ampm = hours >= 12 ? '오후' : '오전';
|
|
hours = hours % 12;
|
|
hours = hours ? hours : 12;
|
|
|
|
let timePart = `${ampm} ${hours}시`;
|
|
if (minutes !== 0) {
|
|
timePart += ` ${minutes}분`;
|
|
}
|
|
|
|
return timePart;
|
|
} |