-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.ts
162 lines (142 loc) · 4 KB
/
helper.ts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import moment from "moment";
import "moment/locale/ko";
export const getLatestReleaseDate = (timeStr: string): string => {
const today = moment(timeStr);
const yesterday = moment(timeStr).add(-1, "days");
// ANCHOR: update articles every odd day of year
return today.dayOfYear() % 2
? today.format("YYYY-MM-DD")
: yesterday.format("YYYY-MM-DD");
};
const monthInKor = [
"일월",
"이월",
"삼월",
"사월",
"오월",
"유월",
"칠월",
"팔월",
"구월",
"시월",
"십일월",
"십이월",
];
export const getMonthInKor = (timeStr: string): string => {
return monthInKor[moment(timeStr).month()];
};
const weekNumInKor = [
"첫번째",
"두번째",
"세번째",
"네번째",
"다섯번째",
"마지막",
];
export const getWeekNumInKor = (timeStr: string): string => {
const today = moment(timeStr);
let firstWeekdayOfMonth = moment(timeStr).startOf("month").day(today.day());
if (firstWeekdayOfMonth.month() < today.month())
firstWeekdayOfMonth = firstWeekdayOfMonth.add(1, "week");
let weekNum = today.diff(firstWeekdayOfMonth, "weeks");
let lastWeekdayOfMonth = moment(timeStr).endOf("month").day(today.day());
if (lastWeekdayOfMonth.month() > today.month())
lastWeekdayOfMonth = lastWeekdayOfMonth.subtract(1, "week");
if (today.date() === lastWeekdayOfMonth.date())
weekNum = weekNumInKor.length - 1;
return weekNumInKor[weekNum];
};
export const getWeekdayInKor = (timeStr: string): string => {
return moment(timeStr).format("dddd");
};
export const getTimeMeridiem = (timeStr: string): string => {
return moment(timeStr).format("A");
};
export const getHourInKor = (timeStr: string): string => {
const hour = parseInt(moment(timeStr).format("h"));
switch (hour) {
case 1:
return "한시";
case 2:
return "두시";
case 3:
return "세시";
case 4:
return "네시";
case 5:
return "다섯시";
case 6:
return "여섯시";
case 7:
return "일곱시";
case 8:
return "여덟시";
case 9:
return "아홉시";
case 10:
return "열시";
case 11:
return "열한시";
case 12:
default:
return "열두시";
}
};
const numInKor = ["", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구"];
export const getMinuteInKor = (timeStr: string): string => {
const minute = moment(timeStr).format("mm");
const tensDigit = parseInt(minute[0]);
const onesDigit = parseInt(minute[1]);
if (tensDigit === 0 && onesDigit === 0) {
return "영";
}
let minuteInKor = "";
if (tensDigit >= 1) {
if (tensDigit !== 1) {
minuteInKor = numInKor[tensDigit];
}
minuteInKor += "십";
}
minuteInKor += numInKor[onesDigit];
return minuteInKor;
};
export const getWeatherInKor = (temperature: number, sky: string): string => {
if (sky === "Rain") {
return "나가는길에 우산 꼭 챙겨요";
} else if (sky === "Snow") {
return "우산 챙기구 걸을때 조심해요";
}
if (temperature < 0) {
return "덜덜덜 이가 떨리도록 추워요";
} else if (temperature < 7) {
return "덜덜덜 오늘은 패딩이 필수에요";
} else if (temperature < 14) {
return "방심하지 마요. 겉옷을 꼭 챙겨요";
} else if (temperature < 20) {
return "완벽하군. 산책하기 딱 좋아요";
} else if (temperature < 25) {
return "따뜻한 오늘, 피크닉을 부르는 날이에요";
} else {
return "에어컨아 살려줘";
}
};
// NOTE GA + GTM
declare global {
interface Window {
gtag: any;
}
}
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const pageview = (url) => {
window.gtag("config", process.env.NEXT_PUBLIC_GA_TRACKING_ID, {
page_path: url,
});
};
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = ({ action, category, label, value }) => {
window.gtag("event", action, {
event_category: category,
event_label: label,
value: value,
});
};