-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstringToDate.ts
More file actions
32 lines (28 loc) · 966 Bytes
/
stringToDate.ts
File metadata and controls
32 lines (28 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export const stringToDate = (s: string): Date => {
const [datePart, timePart] = s.split(' ') as [string, string];
if (!datePart || !timePart) {
throw new Error(
'유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.',
);
}
const isoDate = datePart.replace(/\./g, '-');
const date = new Date(`${isoDate}T${timePart}:00`);
if (isNaN(date.getTime())) {
throw new Error(
'유효하지 않은 날짜 형식입니다. 형식은 "YYYY.MM.DD HH:mm" 이어야 합니다.',
);
}
return date;
};
export const parseRecruitmentPeriod = (
periodStr: string,
): { recruitmentStart: Date | null; recruitmentEnd: Date | null } => {
const parts = periodStr.split('~').map((s) => s.trim());
if (parts.length !== 2) {
return { recruitmentStart: null, recruitmentEnd: null };
}
return {
recruitmentStart: stringToDate(parts[0]),
recruitmentEnd: stringToDate(parts[1]),
};
};