-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdateParser.js
More file actions
103 lines (88 loc) · 2.08 KB
/
Copy pathdateParser.js
File metadata and controls
103 lines (88 loc) · 2.08 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function parseDate(stringDate) {
const regNotNumber = /[^0-9]/g;
const regYear = /[0-9]*년/;
const regMonth = /[0-9]*월/;
const regDaily = /매./;
const regDay = /[0-9]*일/;
const regHour = /[0-9]*시/;
const regMinute = /[0-9]*분/;
const regSecond = /[0-9]*초/;
const regWeek = /.요일/;
const regAM = /오전/;
const regTomorrow = /내일/;
function isRegExist(reg, stringDate) {
return reg.test(stringDate);
}
function stringDateSplit(reg, stringDate) {
return parseInt(stringDate.match(reg)[0].replace(regNotNumber, ""));
}
function parsing(reg, stringDate, defaultValue) {
return isRegExist(reg, stringDate)
? stringDateSplit(reg, stringDate)
: defaultValue;
}
function regDailyAndWeekSplit(reg, stringDate) {
return stringDate.match(reg)[0];
}
const year = parsing(regYear, stringDate, new Date().getFullYear());
const month = parsing(regMonth, stringDate, new Date().getMonth() + 1);
const minute = parsing(regMinute, stringDate, 0);
const seconds = parsing(regSecond, stringDate, 0);
let date = parsing(regDay, stringDate, new Date().getDate());
let hour = parsing(regHour, stringDate, 0);
if (!isRegExist(regAM, stringDate)) {
hour += 12;
}
if (isRegExist(regDaily, stringDate)) {
const repeat = regDailyAndWeekSplit(regDaily, stringDate);
if (repeat === "매일") {
return {
repeat,
hour,
minute,
seconds,
};
}
if (repeat === "매주") {
const week = regDailyAndWeekSplit(regWeek, stringDate)[0];
return {
repeat,
week,
hour,
minute,
seconds,
};
}
if (repeat === "매달") {
return {
repeat,
date,
hour,
minute,
seconds,
};
}
}
if (isRegExist(regTomorrow, stringDate)) {
date = new Date().getDate() + 1;
return {
year,
month,
date,
hour,
minute,
seconds,
};
}
return {
year,
month,
date,
hour,
minute,
seconds,
};
}
module.exports = {
parseDate,
};