Skip to content

Commit 804b546

Browse files
authored
Merge pull request #299 from Coffect/fix/jun-coffeechat-Card
fix: combine date in patch schedule
2 parents 478ac9e + 46f1b1f commit 804b546

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

src/coffeeChat/coffeeChat.Model.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,57 @@ export class HomeModel {
838838
location : string,
839839
time : Date
840840
):Promise<void> {
841-
const combineDate = new Date(coffeeChat.getTime() + time.getTime());
841+
// 날짜와 시간 입력을 안전하게 결합 (문자열/Date 모두 허용)
842+
// 1) 날짜 파싱: YYYY-MM-DD 문자열 또는 Date 지원
843+
let year: number; let monthIndex: number; let day: number;
844+
if (typeof (coffeeChat as any) === 'string') {
845+
const dateStr = (coffeeChat as unknown as string).trim();
846+
const md = dateStr.match(/^(\d{4})-(\d{2})-(\d{2})/);
847+
if (!md) {
848+
const d = new Date(dateStr);
849+
if (isNaN(d.getTime())) {
850+
throw new Error('Invalid coffeeDate format');
851+
}
852+
year = d.getFullYear(); monthIndex = d.getMonth(); day = d.getDate();
853+
} else {
854+
year = parseInt(md[1], 10);
855+
monthIndex = parseInt(md[2], 10) - 1;
856+
day = parseInt(md[3], 10);
857+
}
858+
} else {
859+
const d = new Date(coffeeChat as any);
860+
if (isNaN(d.getTime())) {
861+
throw new Error('Invalid coffeeDate value');
862+
}
863+
year = d.getFullYear(); monthIndex = d.getMonth(); day = d.getDate();
864+
}
865+
866+
// 2) 시간 파싱: 'HH:mm' / 'HH:mm:ss' 문자열 또는 Date 지원
867+
let hours = 0; let minutes = 0; let seconds = 0; let ms = 0;
868+
if (typeof (time as any) === 'string') {
869+
const timeStr = (time as unknown as string).trim();
870+
const mt = timeStr.match(/^(\d{2}):(\d{2})(?::(\d{2}))?$/);
871+
if (!mt) {
872+
const td = new Date(timeStr);
873+
if (isNaN(td.getTime())) {
874+
throw new Error('Invalid time format');
875+
}
876+
hours = td.getHours(); minutes = td.getMinutes(); seconds = td.getSeconds(); ms = td.getMilliseconds();
877+
} else {
878+
hours = parseInt(mt[1], 10);
879+
minutes = parseInt(mt[2], 10);
880+
seconds = mt[3] ? parseInt(mt[3], 10) : 0;
881+
}
882+
} else {
883+
const td = new Date(time as any);
884+
if (isNaN(td.getTime())) {
885+
throw new Error('Invalid time value');
886+
}
887+
hours = td.getHours(); minutes = td.getMinutes(); seconds = td.getSeconds(); ms = td.getMilliseconds();
888+
}
889+
890+
// 로컬 타임존 기준으로 조합 (연/월/일 유지, 시/분/초만 설정)
891+
const combined = new Date(year, monthIndex, day, hours, minutes, seconds, ms);
842892

843893
// 먼저 레코드가 존재하는지 확인
844894
const existingRecord = await prisma.coffeeChat.findFirst({
@@ -858,7 +908,7 @@ export class HomeModel {
858908
OR : [{firstUserId : userId}, {secondUserId : userId}]
859909
},
860910
data : {
861-
coffectDate : combineDate,
911+
coffectDate : combined,
862912
location : location
863913
}
864914
});

0 commit comments

Comments
 (0)