@simplysm/core-common 13.0.0-beta.2 → 13.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.types.js +4 -4
- package/dist/errors/argument-error.js +1 -1
- package/dist/errors/not-implemented-error.js +1 -1
- package/dist/errors/timeout-error.js +1 -1
- package/dist/extensions/arr-ext.helpers.js +4 -4
- package/dist/extensions/arr-ext.js +9 -9
- package/dist/features/debounce-queue.js +2 -2
- package/dist/features/serial-queue.js +3 -3
- package/dist/index.js +30 -30
- package/dist/types/date-only.js +2 -2
- package/dist/types/date-time.js +2 -2
- package/dist/types/time.js +2 -2
- package/dist/types/uuid.js +1 -1
- package/dist/utils/bytes.js +1 -1
- package/dist/utils/json.js +8 -8
- package/dist/utils/obj.js +5 -5
- package/dist/utils/primitive.js +5 -5
- package/dist/utils/transferable.js +4 -4
- package/dist/utils/wait.js +1 -1
- package/package.json +7 -4
- package/.cache/typecheck-browser.tsbuildinfo +0 -1
- package/.cache/typecheck-node.tsbuildinfo +0 -1
- package/.cache/typecheck-tests-browser.tsbuildinfo +0 -1
- package/.cache/typecheck-tests-node.tsbuildinfo +0 -1
- package/src/common.types.ts +0 -91
- package/src/env.ts +0 -11
- package/src/errors/argument-error.ts +0 -40
- package/src/errors/not-implemented-error.ts +0 -32
- package/src/errors/sd-error.ts +0 -53
- package/src/errors/timeout-error.ts +0 -36
- package/src/extensions/arr-ext.helpers.ts +0 -53
- package/src/extensions/arr-ext.ts +0 -777
- package/src/extensions/arr-ext.types.ts +0 -258
- package/src/extensions/map-ext.ts +0 -86
- package/src/extensions/set-ext.ts +0 -68
- package/src/features/debounce-queue.ts +0 -116
- package/src/features/event-emitter.ts +0 -112
- package/src/features/serial-queue.ts +0 -94
- package/src/globals.ts +0 -12
- package/src/index.ts +0 -55
- package/src/types/date-only.ts +0 -329
- package/src/types/date-time.ts +0 -294
- package/src/types/lazy-gc-map.ts +0 -244
- package/src/types/time.ts +0 -210
- package/src/types/uuid.ts +0 -113
- package/src/utils/bytes.ts +0 -160
- package/src/utils/date-format.ts +0 -239
- package/src/utils/json.ts +0 -230
- package/src/utils/num.ts +0 -97
- package/src/utils/obj.ts +0 -956
- package/src/utils/path.ts +0 -40
- package/src/utils/primitive.ts +0 -33
- package/src/utils/str.ts +0 -252
- package/src/utils/template-strings.ts +0 -132
- package/src/utils/transferable.ts +0 -269
- package/src/utils/wait.ts +0 -40
- package/src/utils/xml.ts +0 -105
- package/src/zip/sd-zip.ts +0 -218
- package/tests/errors/errors.spec.ts +0 -196
- package/tests/extensions/array-extension.spec.ts +0 -790
- package/tests/extensions/map-extension.spec.ts +0 -147
- package/tests/extensions/set-extension.spec.ts +0 -74
- package/tests/types/date-only.spec.ts +0 -636
- package/tests/types/date-time.spec.ts +0 -391
- package/tests/types/lazy-gc-map.spec.ts +0 -692
- package/tests/types/time.spec.ts +0 -559
- package/tests/types/types.spec.ts +0 -55
- package/tests/types/uuid.spec.ts +0 -91
- package/tests/utils/bytes-utils.spec.ts +0 -230
- package/tests/utils/date-format.spec.ts +0 -371
- package/tests/utils/debounce-queue.spec.ts +0 -272
- package/tests/utils/json.spec.ts +0 -475
- package/tests/utils/number.spec.ts +0 -184
- package/tests/utils/object.spec.ts +0 -827
- package/tests/utils/path.spec.ts +0 -78
- package/tests/utils/primitive.spec.ts +0 -55
- package/tests/utils/sd-event-emitter.spec.ts +0 -216
- package/tests/utils/serial-queue.spec.ts +0 -365
- package/tests/utils/string.spec.ts +0 -294
- package/tests/utils/template-strings.spec.ts +0 -96
- package/tests/utils/transferable.spec.ts +0 -698
- package/tests/utils/wait.spec.ts +0 -145
- package/tests/utils/xml.spec.ts +0 -146
- package/tests/zip/sd-zip.spec.ts +0 -234
package/tests/types/time.spec.ts
DELETED
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { Time } from "@simplysm/core-common";
|
|
3
|
-
|
|
4
|
-
describe("Time", () => {
|
|
5
|
-
//#region 생성자
|
|
6
|
-
|
|
7
|
-
describe("constructor", () => {
|
|
8
|
-
it("인수 없이 생성하면 현재 시간을 반환한다", () => {
|
|
9
|
-
const time = new Time();
|
|
10
|
-
|
|
11
|
-
// 시간은 실시간으로 변하므로 범위 테스트
|
|
12
|
-
expect(time.hour).toBeGreaterThanOrEqual(0);
|
|
13
|
-
expect(time.hour).toBeLessThanOrEqual(23);
|
|
14
|
-
expect(time.minute).toBeGreaterThanOrEqual(0);
|
|
15
|
-
expect(time.minute).toBeLessThanOrEqual(59);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("시분초로 생성한다", () => {
|
|
19
|
-
const time = new Time(15, 30, 45);
|
|
20
|
-
|
|
21
|
-
expect(time.hour).toBe(15);
|
|
22
|
-
expect(time.minute).toBe(30);
|
|
23
|
-
expect(time.second).toBe(45);
|
|
24
|
-
expect(time.millisecond).toBe(0);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("시분초 밀리초로 생성한다", () => {
|
|
28
|
-
const time = new Time(15, 30, 45, 123);
|
|
29
|
-
|
|
30
|
-
expect(time.hour).toBe(15);
|
|
31
|
-
expect(time.minute).toBe(30);
|
|
32
|
-
expect(time.second).toBe(45);
|
|
33
|
-
expect(time.millisecond).toBe(123);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("tick (millisecond)로 생성한다", () => {
|
|
37
|
-
// 15:30:45.123 = (15*60*60 + 30*60 + 45)*1000 + 123
|
|
38
|
-
const tick = (15 * 60 * 60 + 30 * 60 + 45) * 1000 + 123;
|
|
39
|
-
const time = new Time(tick);
|
|
40
|
-
|
|
41
|
-
expect(time.hour).toBe(15);
|
|
42
|
-
expect(time.minute).toBe(30);
|
|
43
|
-
expect(time.second).toBe(45);
|
|
44
|
-
expect(time.millisecond).toBe(123);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("Date 타입으로 생성한다", () => {
|
|
48
|
-
const date = new Date(2025, 0, 6, 15, 30, 45, 123);
|
|
49
|
-
const time = new Time(date);
|
|
50
|
-
|
|
51
|
-
expect(time.hour).toBe(15);
|
|
52
|
-
expect(time.minute).toBe(30);
|
|
53
|
-
expect(time.second).toBe(45);
|
|
54
|
-
expect(time.millisecond).toBe(123);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("24시간을 넘으면 나머지만 저장한다", () => {
|
|
58
|
-
// 25시간 = 1시간
|
|
59
|
-
const time = new Time(25, 0, 0);
|
|
60
|
-
|
|
61
|
-
expect(time.hour).toBe(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("음수 시분초로 생성하면 24시간 내로 정규화된다", () => {
|
|
65
|
-
// -1시간 30분 = 23시간 30분 (24 - 0.5 = 23.5)
|
|
66
|
-
const time = new Time(-1, 30, 0);
|
|
67
|
-
|
|
68
|
-
expect(time.hour).toBe(23);
|
|
69
|
-
expect(time.minute).toBe(30);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("음수 tick으로 생성하면 24시간 내로 정규화된다", () => {
|
|
73
|
-
// -1시간 = -3600000ms → 23시간
|
|
74
|
-
const time = new Time(-3600000);
|
|
75
|
-
|
|
76
|
-
expect(time.hour).toBe(23);
|
|
77
|
-
expect(time.minute).toBe(0);
|
|
78
|
-
expect(time.second).toBe(0);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("음수 tick(-1ms)은 23:59:59.999로 정규화된다", () => {
|
|
82
|
-
const time = new Time(-1);
|
|
83
|
-
|
|
84
|
-
expect(time.hour).toBe(23);
|
|
85
|
-
expect(time.minute).toBe(59);
|
|
86
|
-
expect(time.second).toBe(59);
|
|
87
|
-
expect(time.millisecond).toBe(999);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
|
|
93
|
-
//#region parse
|
|
94
|
-
|
|
95
|
-
describe("parse()", () => {
|
|
96
|
-
it("HH:mm:ss 형식을 파싱한다", () => {
|
|
97
|
-
const time = Time.parse("15:30:45");
|
|
98
|
-
|
|
99
|
-
expect(time.hour).toBe(15);
|
|
100
|
-
expect(time.minute).toBe(30);
|
|
101
|
-
expect(time.second).toBe(45);
|
|
102
|
-
expect(time.millisecond).toBe(0);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("HH:mm:ss.fff 형식을 파싱한다", () => {
|
|
106
|
-
const time = Time.parse("15:30:45.123");
|
|
107
|
-
|
|
108
|
-
expect(time.hour).toBe(15);
|
|
109
|
-
expect(time.minute).toBe(30);
|
|
110
|
-
expect(time.second).toBe(45);
|
|
111
|
-
expect(time.millisecond).toBe(123);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("오전 HH:mm:ss 형식을 파싱한다", () => {
|
|
115
|
-
const time = Time.parse("오전 9:30:45");
|
|
116
|
-
|
|
117
|
-
expect(time.hour).toBe(9);
|
|
118
|
-
expect(time.minute).toBe(30);
|
|
119
|
-
expect(time.second).toBe(45);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("오후 HH:mm:ss 형식을 파싱한다", () => {
|
|
123
|
-
const time = Time.parse("오후 3:30:45");
|
|
124
|
-
|
|
125
|
-
expect(time.hour).toBe(15); // 12 + 3
|
|
126
|
-
expect(time.minute).toBe(30);
|
|
127
|
-
expect(time.second).toBe(45);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("밀리초 자릿수가 부족하면 0으로 패딩한다", () => {
|
|
131
|
-
const time = Time.parse("15:30:45.1");
|
|
132
|
-
|
|
133
|
-
expect(time.millisecond).toBe(100); // '1' → '100'
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("잘못된 형식이면 에러를 던진다", () => {
|
|
137
|
-
expect(() => Time.parse("invalid-time")).toThrow("시간 형식을 파싱할 수 없습니다");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("오후 12:00:00은 정오(12시)", () => {
|
|
141
|
-
const time = Time.parse("오후 12:00:00");
|
|
142
|
-
|
|
143
|
-
expect(time.hour).toBe(12);
|
|
144
|
-
expect(time.minute).toBe(0);
|
|
145
|
-
expect(time.second).toBe(0);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("오전 12:00:00은 자정(0시)", () => {
|
|
149
|
-
const time = Time.parse("오전 12:00:00");
|
|
150
|
-
|
|
151
|
-
expect(time.hour).toBe(0);
|
|
152
|
-
expect(time.minute).toBe(0);
|
|
153
|
-
expect(time.second).toBe(0);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("오후 12:30:45는 정오 이후(12시 30분 45초)", () => {
|
|
157
|
-
const time = Time.parse("오후 12:30:45");
|
|
158
|
-
|
|
159
|
-
expect(time.hour).toBe(12);
|
|
160
|
-
expect(time.minute).toBe(30);
|
|
161
|
-
expect(time.second).toBe(45);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("오전 12:30:45는 자정 이후(0시 30분 45초)", () => {
|
|
165
|
-
const time = Time.parse("오전 12:30:45");
|
|
166
|
-
|
|
167
|
-
expect(time.hour).toBe(0);
|
|
168
|
-
expect(time.minute).toBe(30);
|
|
169
|
-
expect(time.second).toBe(45);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("ISO 8601 형식에서 시간 부분을 파싱한다 (UTC -> 로컬 변환)", () => {
|
|
173
|
-
// UTC 시간은 로컬 시간으로 변환됨
|
|
174
|
-
const time = Time.parse("2025-01-15T10:30:45Z");
|
|
175
|
-
const expected = new Date("2025-01-15T10:30:45Z");
|
|
176
|
-
|
|
177
|
-
expect(time.hour).toBe(expected.getHours());
|
|
178
|
-
expect(time.minute).toBe(30);
|
|
179
|
-
expect(time.second).toBe(45);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("ISO 8601 형식에서 밀리초도 파싱한다 (UTC -> 로컬 변환)", () => {
|
|
183
|
-
// UTC 시간은 로컬 시간으로 변환됨
|
|
184
|
-
const time = Time.parse("2025-01-15T10:30:45.123Z");
|
|
185
|
-
const expected = new Date("2025-01-15T10:30:45.123Z");
|
|
186
|
-
|
|
187
|
-
expect(time.hour).toBe(expected.getHours());
|
|
188
|
-
expect(time.minute).toBe(30);
|
|
189
|
-
expect(time.second).toBe(45);
|
|
190
|
-
expect(time.millisecond).toBe(123);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
//#endregion
|
|
195
|
-
|
|
196
|
-
//#region Getters
|
|
197
|
-
|
|
198
|
-
describe("Getters", () => {
|
|
199
|
-
it("hour를 반환한다", () => {
|
|
200
|
-
const time = new Time(15, 30, 45, 123);
|
|
201
|
-
expect(time.hour).toBe(15);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("minute를 반환한다", () => {
|
|
205
|
-
const time = new Time(15, 30, 45, 123);
|
|
206
|
-
expect(time.minute).toBe(30);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("second를 반환한다", () => {
|
|
210
|
-
const time = new Time(15, 30, 45, 123);
|
|
211
|
-
expect(time.second).toBe(45);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("millisecond를 반환한다", () => {
|
|
215
|
-
const time = new Time(15, 30, 45, 123);
|
|
216
|
-
expect(time.millisecond).toBe(123);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("tick을 반환한다", () => {
|
|
220
|
-
const time = new Time(15, 30, 45, 123);
|
|
221
|
-
const expectedTick = (15 * 60 * 60 + 30 * 60 + 45) * 1000 + 123;
|
|
222
|
-
expect(time.tick).toBe(expectedTick);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
//#endregion
|
|
227
|
-
|
|
228
|
-
//#region tick 비교
|
|
229
|
-
|
|
230
|
-
describe("tick 비교", () => {
|
|
231
|
-
it("같은 시간은 같은 tick을 가진다", () => {
|
|
232
|
-
const t1 = new Time(10, 30, 45, 123);
|
|
233
|
-
const t2 = new Time(10, 30, 45, 123);
|
|
234
|
-
|
|
235
|
-
expect(t1.tick).toBe(t2.tick);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("다른 시간은 다른 tick을 가진다", () => {
|
|
239
|
-
const t1 = new Time(10, 30, 45, 123);
|
|
240
|
-
const t2 = new Time(10, 30, 45, 124);
|
|
241
|
-
|
|
242
|
-
expect(t1.tick).not.toBe(t2.tick);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it("tick으로 시간 순서를 비교할 수 있다", () => {
|
|
246
|
-
const t1 = new Time(0, 0, 0);
|
|
247
|
-
const t2 = new Time(12, 30, 0);
|
|
248
|
-
const t3 = new Time(23, 59, 59);
|
|
249
|
-
|
|
250
|
-
expect(t1.tick).toBeLessThan(t2.tick);
|
|
251
|
-
expect(t2.tick).toBeLessThan(t3.tick);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("밀리초 단위 비교가 가능하다", () => {
|
|
255
|
-
const t1 = new Time(10, 30, 45, 0);
|
|
256
|
-
const t2 = new Time(10, 30, 45, 1);
|
|
257
|
-
|
|
258
|
-
expect(t2.tick - t1.tick).toBe(1);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it("시간 차이를 tick으로 계산할 수 있다", () => {
|
|
262
|
-
const t1 = new Time(10, 0, 0);
|
|
263
|
-
const t2 = new Time(11, 0, 0);
|
|
264
|
-
|
|
265
|
-
// 1시간 = 3600000ms
|
|
266
|
-
expect(t2.tick - t1.tick).toBe(3600000);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
//#endregion
|
|
271
|
-
|
|
272
|
-
//#region setX 메서드 (불변)
|
|
273
|
-
|
|
274
|
-
describe("setHour()", () => {
|
|
275
|
-
it("시를 변경한 새 인스턴스를 반환한다", () => {
|
|
276
|
-
const time = new Time(15, 30, 45, 123);
|
|
277
|
-
const newTime = time.setHour(20);
|
|
278
|
-
|
|
279
|
-
expect(newTime.hour).toBe(20);
|
|
280
|
-
expect(newTime.minute).toBe(30);
|
|
281
|
-
expect(newTime.second).toBe(45);
|
|
282
|
-
expect(newTime.millisecond).toBe(123);
|
|
283
|
-
expect(time.hour).toBe(15); // 원본 불변
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
describe("setMinute()", () => {
|
|
288
|
-
it("분을 변경한 새 인스턴스를 반환한다", () => {
|
|
289
|
-
const time = new Time(15, 30, 45, 123);
|
|
290
|
-
const newTime = time.setMinute(50);
|
|
291
|
-
|
|
292
|
-
expect(newTime.hour).toBe(15);
|
|
293
|
-
expect(newTime.minute).toBe(50);
|
|
294
|
-
expect(newTime.second).toBe(45);
|
|
295
|
-
expect(newTime.millisecond).toBe(123);
|
|
296
|
-
expect(time.minute).toBe(30); // 원본 불변
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe("setSecond()", () => {
|
|
301
|
-
it("초를 변경한 새 인스턴스를 반환한다", () => {
|
|
302
|
-
const time = new Time(15, 30, 45, 123);
|
|
303
|
-
const newTime = time.setSecond(55);
|
|
304
|
-
|
|
305
|
-
expect(newTime.hour).toBe(15);
|
|
306
|
-
expect(newTime.minute).toBe(30);
|
|
307
|
-
expect(newTime.second).toBe(55);
|
|
308
|
-
expect(newTime.millisecond).toBe(123);
|
|
309
|
-
expect(time.second).toBe(45); // 원본 불변
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
describe("setMillisecond()", () => {
|
|
314
|
-
it("밀리초를 변경한 새 인스턴스를 반환한다", () => {
|
|
315
|
-
const time = new Time(15, 30, 45, 123);
|
|
316
|
-
const newTime = time.setMillisecond(456);
|
|
317
|
-
|
|
318
|
-
expect(newTime.hour).toBe(15);
|
|
319
|
-
expect(newTime.minute).toBe(30);
|
|
320
|
-
expect(newTime.second).toBe(45);
|
|
321
|
-
expect(newTime.millisecond).toBe(456);
|
|
322
|
-
expect(time.millisecond).toBe(123); // 원본 불변
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
//#endregion
|
|
327
|
-
|
|
328
|
-
//#region addX 메서드 (불변)
|
|
329
|
-
|
|
330
|
-
describe("addHours()", () => {
|
|
331
|
-
it("양수 시를 더한다", () => {
|
|
332
|
-
const time = new Time(15, 30, 45);
|
|
333
|
-
const newTime = time.addHours(3);
|
|
334
|
-
|
|
335
|
-
expect(newTime.hour).toBe(18);
|
|
336
|
-
expect(newTime.minute).toBe(30);
|
|
337
|
-
expect(newTime.second).toBe(45);
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it("음수 시를 더한다 (빼기)", () => {
|
|
341
|
-
const time = new Time(15, 30, 45);
|
|
342
|
-
const newTime = time.addHours(-5);
|
|
343
|
-
|
|
344
|
-
expect(newTime.hour).toBe(10);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("24시간을 넘어가면 나머지만 저장한다", () => {
|
|
348
|
-
const time = new Time(22, 0, 0);
|
|
349
|
-
const newTime = time.addHours(5);
|
|
350
|
-
|
|
351
|
-
expect(newTime.hour).toBe(3); // (22 + 5) % 24
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
describe("addMinutes()", () => {
|
|
356
|
-
it("양수 분을 더한다", () => {
|
|
357
|
-
const time = new Time(15, 30, 45);
|
|
358
|
-
const newTime = time.addMinutes(20);
|
|
359
|
-
|
|
360
|
-
expect(newTime.hour).toBe(15);
|
|
361
|
-
expect(newTime.minute).toBe(50);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it("음수 분을 더한다 (빼기)", () => {
|
|
365
|
-
const time = new Time(15, 30, 45);
|
|
366
|
-
const newTime = time.addMinutes(-20);
|
|
367
|
-
|
|
368
|
-
expect(newTime.minute).toBe(10);
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("60분을 넘어가면 시간이 증가한다", () => {
|
|
372
|
-
const time = new Time(15, 50, 0);
|
|
373
|
-
const newTime = time.addMinutes(20);
|
|
374
|
-
|
|
375
|
-
expect(newTime.hour).toBe(16);
|
|
376
|
-
expect(newTime.minute).toBe(10);
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
describe("addSeconds()", () => {
|
|
381
|
-
it("양수 초를 더한다", () => {
|
|
382
|
-
const time = new Time(15, 30, 45);
|
|
383
|
-
const newTime = time.addSeconds(10);
|
|
384
|
-
|
|
385
|
-
expect(newTime.hour).toBe(15);
|
|
386
|
-
expect(newTime.minute).toBe(30);
|
|
387
|
-
expect(newTime.second).toBe(55);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it("음수 초를 더한다 (빼기)", () => {
|
|
391
|
-
const time = new Time(15, 30, 45);
|
|
392
|
-
const newTime = time.addSeconds(-10);
|
|
393
|
-
|
|
394
|
-
expect(newTime.second).toBe(35);
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it("60초를 넘어가면 분이 증가한다", () => {
|
|
398
|
-
const time = new Time(15, 30, 50);
|
|
399
|
-
const newTime = time.addSeconds(20);
|
|
400
|
-
|
|
401
|
-
expect(newTime.minute).toBe(31);
|
|
402
|
-
expect(newTime.second).toBe(10);
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
describe("addMilliseconds()", () => {
|
|
407
|
-
it("양수 밀리초를 더한다", () => {
|
|
408
|
-
const time = new Time(15, 30, 45, 100);
|
|
409
|
-
const newTime = time.addMilliseconds(50);
|
|
410
|
-
|
|
411
|
-
expect(newTime.millisecond).toBe(150);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it("음수 밀리초를 더한다 (빼기)", () => {
|
|
415
|
-
const time = new Time(15, 30, 45, 100);
|
|
416
|
-
const newTime = time.addMilliseconds(-50);
|
|
417
|
-
|
|
418
|
-
expect(newTime.millisecond).toBe(50);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it("1000밀리초를 넘어가면 초가 증가한다", () => {
|
|
422
|
-
const time = new Time(15, 30, 45, 900);
|
|
423
|
-
const newTime = time.addMilliseconds(200);
|
|
424
|
-
|
|
425
|
-
expect(newTime.second).toBe(46);
|
|
426
|
-
expect(newTime.millisecond).toBe(100);
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
//#endregion
|
|
431
|
-
|
|
432
|
-
//#region 음수 연산 (24시간 경계 처리)
|
|
433
|
-
|
|
434
|
-
describe("음수 연산 (24시간 경계)", () => {
|
|
435
|
-
it("addHours(-25)는 전날 같은 시간 (23시간 전)", () => {
|
|
436
|
-
// 10시에서 25시간을 빼면 전날 9시 = 24 - 25 + 10 = 9시
|
|
437
|
-
const time = new Time(10, 0, 0);
|
|
438
|
-
const newTime = time.addHours(-25);
|
|
439
|
-
|
|
440
|
-
expect(newTime.hour).toBe(9);
|
|
441
|
-
expect(newTime.minute).toBe(0);
|
|
442
|
-
expect(newTime.second).toBe(0);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it("addHours(-10)에서 자정을 넘으면 전날 시간", () => {
|
|
446
|
-
// 5시에서 10시간을 빼면 19시
|
|
447
|
-
const time = new Time(5, 0, 0);
|
|
448
|
-
const newTime = time.addHours(-10);
|
|
449
|
-
|
|
450
|
-
expect(newTime.hour).toBe(19);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it("addMinutes(-90)는 1시간 30분 전", () => {
|
|
454
|
-
// 1시 30분에서 90분을 빼면 0시 0분
|
|
455
|
-
const time = new Time(1, 30, 0);
|
|
456
|
-
const newTime = time.addMinutes(-90);
|
|
457
|
-
|
|
458
|
-
expect(newTime.hour).toBe(0);
|
|
459
|
-
expect(newTime.minute).toBe(0);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it("addMinutes(-90)에서 자정을 넘으면 전날 시간", () => {
|
|
463
|
-
// 0시 30분에서 90분을 빼면 전날 23시 0분
|
|
464
|
-
const time = new Time(0, 30, 0);
|
|
465
|
-
const newTime = time.addMinutes(-90);
|
|
466
|
-
|
|
467
|
-
expect(newTime.hour).toBe(23);
|
|
468
|
-
expect(newTime.minute).toBe(0);
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
it("addSeconds(-3700)는 약 1시간 전", () => {
|
|
472
|
-
// 1시 0분 0초에서 3700초(1시간 1분 40초)를 빼면 23시 58분 20초
|
|
473
|
-
const time = new Time(1, 0, 0);
|
|
474
|
-
const newTime = time.addSeconds(-3700);
|
|
475
|
-
|
|
476
|
-
expect(newTime.hour).toBe(23);
|
|
477
|
-
expect(newTime.minute).toBe(58);
|
|
478
|
-
expect(newTime.second).toBe(20);
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
it("addMilliseconds(-1000)에서 자정을 넘으면 전날 시간", () => {
|
|
482
|
-
// 0시 0분 0초 500ms에서 1000ms를 빼면 23시 59분 59초 500ms
|
|
483
|
-
const time = new Time(0, 0, 0, 500);
|
|
484
|
-
const newTime = time.addMilliseconds(-1000);
|
|
485
|
-
|
|
486
|
-
expect(newTime.hour).toBe(23);
|
|
487
|
-
expect(newTime.minute).toBe(59);
|
|
488
|
-
expect(newTime.second).toBe(59);
|
|
489
|
-
expect(newTime.millisecond).toBe(500);
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
|
|
495
|
-
//#region isValid
|
|
496
|
-
|
|
497
|
-
describe("isValid", () => {
|
|
498
|
-
it("유효한 시간은 true를 반환한다", () => {
|
|
499
|
-
const time = new Time(15, 30, 45);
|
|
500
|
-
expect(time.isValid).toBe(true);
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it("기본 생성자는 유효한 시간이다", () => {
|
|
504
|
-
const time = new Time();
|
|
505
|
-
expect(time.isValid).toBe(true);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it("tick으로 생성한 시간은 유효하다", () => {
|
|
509
|
-
const tick = (15 * 60 * 60 + 30 * 60 + 45) * 1000;
|
|
510
|
-
const time = new Time(tick);
|
|
511
|
-
expect(time.isValid).toBe(true);
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
it("NaN tick으로 생성한 시간은 isValid가 false다", () => {
|
|
515
|
-
const time = new Time(NaN);
|
|
516
|
-
expect(time.isValid).toBe(false);
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
//#endregion
|
|
521
|
-
|
|
522
|
-
//#region 포맷팅
|
|
523
|
-
|
|
524
|
-
describe("toFormatString()", () => {
|
|
525
|
-
it("HH:mm:ss 형식으로 포맷팅한다", () => {
|
|
526
|
-
const time = new Time(15, 30, 45);
|
|
527
|
-
expect(time.toFormatString("HH:mm:ss")).toBe("15:30:45");
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
it("HH:mm:ss.fff 형식으로 포맷팅한다", () => {
|
|
531
|
-
const time = new Time(15, 30, 45, 123);
|
|
532
|
-
expect(time.toFormatString("HH:mm:ss.fff")).toBe("15:30:45.123");
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
it("tt hh:mm:ss 형식으로 포맷팅한다 (오전)", () => {
|
|
536
|
-
const time = new Time(9, 30, 45);
|
|
537
|
-
expect(time.toFormatString("tt hh:mm:ss")).toBe("오전 09:30:45");
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
it("tt hh:mm:ss 형식으로 포맷팅한다 (오후)", () => {
|
|
541
|
-
const time = new Time(15, 30, 45);
|
|
542
|
-
expect(time.toFormatString("tt hh:mm:ss")).toBe("오후 03:30:45");
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
it("H:m:s 형식으로 포맷팅한다 (패딩 없음)", () => {
|
|
546
|
-
const time = new Time(9, 5, 3);
|
|
547
|
-
expect(time.toFormatString("H:m:s")).toBe("9:5:3");
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
describe("toString()", () => {
|
|
552
|
-
it("기본 형식 HH:mm:ss.fff로 반환한다", () => {
|
|
553
|
-
const time = new Time(15, 30, 45, 123);
|
|
554
|
-
expect(time.toString()).toBe("15:30:45.123");
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
//#endregion
|
|
559
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { getPrimitiveTypeStr, DateTime, DateOnly, Time, Uuid } from "@simplysm/core-common";
|
|
3
|
-
|
|
4
|
-
describe("types.ts", () => {
|
|
5
|
-
//#region getPrimitiveTypeStr
|
|
6
|
-
|
|
7
|
-
describe("getPrimitiveTypeStr()", () => {
|
|
8
|
-
it("string 타입을 반환한다", () => {
|
|
9
|
-
expect(getPrimitiveTypeStr("hello")).toBe("string");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("number 타입을 반환한다", () => {
|
|
13
|
-
expect(getPrimitiveTypeStr(123)).toBe("number");
|
|
14
|
-
expect(getPrimitiveTypeStr(123.45)).toBe("number");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("boolean 타입을 반환한다", () => {
|
|
18
|
-
expect(getPrimitiveTypeStr(true)).toBe("boolean");
|
|
19
|
-
expect(getPrimitiveTypeStr(false)).toBe("boolean");
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("DateTime 타입을 반환한다", () => {
|
|
23
|
-
const dt = new DateTime(2025, 1, 6);
|
|
24
|
-
expect(getPrimitiveTypeStr(dt)).toBe("DateTime");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("DateOnly 타입을 반환한다", () => {
|
|
28
|
-
const dateOnly = new DateOnly(2025, 1, 6);
|
|
29
|
-
expect(getPrimitiveTypeStr(dateOnly)).toBe("DateOnly");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("Time 타입을 반환한다", () => {
|
|
33
|
-
const time = new Time(15, 30, 45);
|
|
34
|
-
expect(getPrimitiveTypeStr(time)).toBe("Time");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("Uuid 타입을 반환한다", () => {
|
|
38
|
-
const uuid = Uuid.new();
|
|
39
|
-
expect(getPrimitiveTypeStr(uuid)).toBe("Uuid");
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("Bytes 타입을 반환한다", () => {
|
|
43
|
-
const bytes = new Uint8Array([1, 2, 3]);
|
|
44
|
-
expect(getPrimitiveTypeStr(bytes)).toBe("Bytes");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("지원하지 않는 타입이면 에러를 던진다", () => {
|
|
48
|
-
expect(() => getPrimitiveTypeStr({} as never)).toThrow("알 수 없는 값 타입");
|
|
49
|
-
expect(() => getPrimitiveTypeStr([] as never)).toThrow("알 수 없는 값 타입");
|
|
50
|
-
expect(() => getPrimitiveTypeStr(null as never)).toThrow("알 수 없는 값 타입");
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
});
|
package/tests/types/uuid.spec.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { Uuid } from "@simplysm/core-common";
|
|
3
|
-
|
|
4
|
-
describe("Uuid", () => {
|
|
5
|
-
describe("new()", () => {
|
|
6
|
-
it("유효한 UUID v4 형식을 생성한다", () => {
|
|
7
|
-
const uuid = Uuid.new();
|
|
8
|
-
const str = uuid.toString();
|
|
9
|
-
|
|
10
|
-
// UUID v4 형식: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
11
|
-
expect(str).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("매번 새로운 UUID를 생성한다", () => {
|
|
15
|
-
const uuid1 = Uuid.new();
|
|
16
|
-
const uuid2 = Uuid.new();
|
|
17
|
-
|
|
18
|
-
expect(uuid1.toString()).not.toBe(uuid2.toString());
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("fromBytes()", () => {
|
|
23
|
-
it("16바이트 Uint8Array로부터 UUID를 생성한다", () => {
|
|
24
|
-
const bytes = new Uint8Array([
|
|
25
|
-
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
|
26
|
-
]);
|
|
27
|
-
const uuid = Uuid.fromBytes(bytes);
|
|
28
|
-
|
|
29
|
-
expect(uuid.toString()).toBe("12345678-9abc-def0-1234-56789abcdef0");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("16바이트가 아닌 경우 에러를 던진다", () => {
|
|
33
|
-
const bytes = new Uint8Array([0x12, 0x34]);
|
|
34
|
-
|
|
35
|
-
expect(() => Uuid.fromBytes(bytes)).toThrow("UUID 바이트 크기는 16이어야 합니다");
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("toBytes()", () => {
|
|
40
|
-
it("UUID를 16바이트 Uint8Array로 변환한다", () => {
|
|
41
|
-
const uuid = new Uuid("12345678-9abc-def0-1234-56789abcdef0");
|
|
42
|
-
const bytes = uuid.toBytes();
|
|
43
|
-
|
|
44
|
-
expect(bytes).toBeInstanceOf(Uint8Array);
|
|
45
|
-
expect(bytes.length).toBe(16);
|
|
46
|
-
expect(Array.from(bytes)).toEqual([
|
|
47
|
-
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
|
48
|
-
]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("fromBytes와 toBytes가 서로 역변환된다", () => {
|
|
52
|
-
const originalBytes = new Uint8Array([
|
|
53
|
-
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
|
54
|
-
]);
|
|
55
|
-
const uuid = Uuid.fromBytes(originalBytes);
|
|
56
|
-
const resultBytes = uuid.toBytes();
|
|
57
|
-
|
|
58
|
-
expect(Array.from(resultBytes)).toEqual(Array.from(originalBytes));
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("toString()", () => {
|
|
63
|
-
it("하이픈이 포함된 형식으로 반환한다", () => {
|
|
64
|
-
const uuid = new Uuid("12345678-9abc-def0-1234-56789abcdef0");
|
|
65
|
-
|
|
66
|
-
expect(uuid.toString()).toBe("12345678-9abc-def0-1234-56789abcdef0");
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("constructor", () => {
|
|
71
|
-
it("유효하지 않은 UUID 형식은 에러를 던진다", () => {
|
|
72
|
-
expect(() => new Uuid("invalid-uuid")).toThrow();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("길이가 맞지 않는 UUID는 에러를 던진다", () => {
|
|
76
|
-
expect(() => new Uuid("12345678-9abc")).toThrow();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("대문자 UUID를 정상적으로 파싱한다", () => {
|
|
80
|
-
const uuid = new Uuid("12345678-9ABC-DEF0-1234-56789ABCDEF0");
|
|
81
|
-
|
|
82
|
-
expect(uuid.toString()).toBe("12345678-9ABC-DEF0-1234-56789ABCDEF0");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("대소문자 혼합 UUID를 정상적으로 파싱한다", () => {
|
|
86
|
-
const uuid = new Uuid("12345678-9AbC-DeF0-1234-56789AbCdEf0");
|
|
87
|
-
|
|
88
|
-
expect(uuid.toString()).toBe("12345678-9AbC-DeF0-1234-56789AbCdEf0");
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
});
|