Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/client/src/pages/myBookmark/MyBookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ const MyBookmark = () => {
return <div>Loading...</div>;
}

console.log(category);

return (
<div className="flex h-screen flex-col py-[5.2rem] pl-[8rem] pr-[5rem]">
<div className="flex items-center gap-[0.4rem]">
Expand Down Expand Up @@ -241,6 +239,7 @@ const MyBookmark = () => {
/>
<div className="absolute inset-0 flex items-center justify-center p-4">
<CardEditModal
key={articleDetail.id}
onClose={() => setIsEditOpen(false)}
prevData={articleDetail}
/>
Expand Down
1 change: 1 addition & 0 deletions apps/client/src/pages/remind/Remind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const Remind = () => {
/>
<div className="absolute inset-0 flex items-center justify-center p-4">
<CardEditModal
key={articleDetail.id}
onClose={() => setIsEditOpen(false)}
prevData={articleDetail}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/client/src/shared/apis/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const putCategory = async (id: number, categoryName: string) => {

export const getAcorns = async () => {
const now = formatLocalDateTime(new Date());
const { data } = await apiRequest.get('/api/v1/users/acorns?now=', {
const { data } = await apiRequest.get('/api/v1/users/acorns?', {
params: { now },
});
return data.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@shared/apis/queries';
import { usePageMeta } from '@shared/hooks/usePageMeta';
import { ArticleDetailResponse, EditArticleRequest } from '@shared/types/api';
import { buildUtcIso } from '@shared/utils/datetime';
import { combineDateTime } from '@shared/utils/datetime';
import { updateDate, updateTime } from '@shared/utils/formatDateTime';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function CardEditModal({
}

const remindTime =
isRemindOn && date && time ? buildUtcIso(date, time) : null;
isRemindOn && date && time ? combineDateTime(date, time) : null;

const editArticleData: EditArticleRequest = {
memo,
Expand Down
79 changes: 54 additions & 25 deletions apps/client/src/shared/utils/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
function parseDateString(d: string) {
const s = d.replace(/[^\d]/g, '');
if (s.length !== 8) return null;
const Y = Number(s.slice(0, 4));
const M = Number(s.slice(4, 6));
const D = Number(s.slice(6, 8));
return { Y, M, D };
}

function parseTimeString(t: string) {
const s = t.replace(/[^\d]/g, '');
if (s.length !== 4) return null;
const h = Number(s.slice(0, 2));
const m = Number(s.slice(2, 4));
return { h, m };
}

export function buildUtcIso(dateStr: string, timeStr: string) {
const d = parseDateString(dateStr);
const t = parseTimeString(timeStr);
if (!d || !t) return null;

const dt = new Date(d.Y, d.M - 1, d.D, t.h, t.m, 0, 0);
return dt.toISOString();
}
// YYYY-MM-DD → YYYY.MM.DD
export const updateDate = (date: string) => {
if (!date) return '';
return date.replace(/-/g, '.');
};

// HH:mm:ss → HH:mm
export const updateTime = (time: string) => {
if (!time) return '';
return time.slice(0, 5);
};

export const to24Hour = (time: string) => {
const match = time.match(/(오전|오후)\s(\d{1,2}):(\d{2})/);
if (!match) return time;

const [, period, hourStr, minute] = match;
let hour = parseInt(hourStr, 10);

if (period === '오전' && hour === 12) {
hour = 0;
} else if (period === '오후' && hour !== 12) {
hour += 12;
}

return `${hour.toString().padStart(2, '0')}:${minute}`;
};

export const combineDateTime = (date: string, time: string) => {
if (!date || !time) return null;

// date가 YYYYMMDD 형태라면 가공 필요
let formattedDate = date;
if (/^\d{8}$/.test(date)) {
const year = date.slice(0, 4);
const month = date.slice(4, 6);
const day = date.slice(6, 8);
formattedDate = `${year}-${month}-${day}`;
} else {
formattedDate = date.replace(/\./g, '-'); // YYYY.MM.DD → YYYY-MM-DD
}

// time이 HHmm 형태라면 HH:mm으로 변환
let normalizedTime = time;
if (/^\d{4}$/.test(time)) {
normalizedTime = `${time.slice(0, 2)}:${time.slice(2, 4)}`;
}

// 24시간 포맷 변환 함수가 있다면 적용
const to24 = to24Hour ? to24Hour(normalizedTime) : normalizedTime;
const formattedTime = to24.length === 5 ? `${to24}:00` : to24;

return `${formattedDate}T${formattedTime}`;
};
Loading