@ray-js/lamp-schedule-core 1.0.4-beta-7 → 1.0.4-beta-9
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.
|
@@ -82,9 +82,11 @@ function doRangesOverlap(aStart, aEnd, bStart, bEnd) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// 情况4: 标准区间重叠判断
|
|
85
|
-
// 使用标准区间重叠判断: [a1,a2] 和 [b1,b2] 重叠当且仅当 a2
|
|
85
|
+
// 使用标准区间重叠判断: [a1,a2] 和 [b1,b2] 重叠当且仅当 a2 >= b1 && b2 >= a1
|
|
86
86
|
// 注意:这里已经处理了跨天情况(通过标准化为连续分钟数)
|
|
87
|
-
|
|
87
|
+
// 使用 >= 而不是 >,因为时间段是闭区间,边界值相等时也应该认为有重叠
|
|
88
|
+
// 例如:[10:00, 23:00] 和 [23:00, 23:05] 在 23:00 这个时间点重叠
|
|
89
|
+
return aEndMin >= bStartMin && bEndMin >= aStartMin;
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
// 辅助函数
|
|
@@ -228,5 +228,47 @@ describe('ConflictResolver', () => {
|
|
|
228
228
|
const conflicts = checkConflicts([rhythmSchedule], timerSchedule);
|
|
229
229
|
expect(conflicts.length).toBe(1);
|
|
230
230
|
});
|
|
231
|
+
|
|
232
|
+
// 测试边界值重叠问题:灯光助眠 23:00-23:05 与 灯光看家 10:00-23:00
|
|
233
|
+
// 这两个时间段在 23:00 这个时间点应该被认为有重叠
|
|
234
|
+
it('should detect conflicts when one schedule ends exactly when another starts (boundary overlap)', () => {
|
|
235
|
+
const homeSchedule = {
|
|
236
|
+
id: 'random_1',
|
|
237
|
+
type: EScheduleFunctionType.RANDOM,
|
|
238
|
+
// 灯光看家
|
|
239
|
+
data: {
|
|
240
|
+
status: true,
|
|
241
|
+
weeks: [1, 0, 0, 0, 0, 0, 0],
|
|
242
|
+
// 周日
|
|
243
|
+
startTime: '10:00',
|
|
244
|
+
endTime: '23:00' // 结束于 23:00
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const sleepSchedule = {
|
|
248
|
+
id: 'sleep_1',
|
|
249
|
+
type: EScheduleFunctionType.SLEEP,
|
|
250
|
+
// 灯光助眠
|
|
251
|
+
data: {
|
|
252
|
+
status: true,
|
|
253
|
+
weeks: [1, 0, 0, 0, 0, 0, 0],
|
|
254
|
+
// 周日
|
|
255
|
+
startTime: '23:00',
|
|
256
|
+
// 开始于 23:00
|
|
257
|
+
endTime: '23:05'
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// 灯光看家 vs 灯光助眠
|
|
262
|
+
const conflicts1 = checkConflicts([homeSchedule], sleepSchedule);
|
|
263
|
+
expect(conflicts1.length).toBe(1);
|
|
264
|
+
expect(conflicts1[0].current).toBe(sleepSchedule);
|
|
265
|
+
expect(conflicts1[0].other).toBe(homeSchedule);
|
|
266
|
+
|
|
267
|
+
// 灯光助眠 vs 灯光看家(反向测试)
|
|
268
|
+
const conflicts2 = checkConflicts([sleepSchedule], homeSchedule);
|
|
269
|
+
expect(conflicts2.length).toBe(1);
|
|
270
|
+
expect(conflicts2[0].current).toBe(homeSchedule);
|
|
271
|
+
expect(conflicts2[0].other).toBe(sleepSchedule);
|
|
272
|
+
});
|
|
231
273
|
});
|
|
232
274
|
});
|
package/lib/conflict/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
|
6
6
|
import { checkConflicts } from './ConflictResolver';
|
|
7
7
|
import { ScheduleDataManager } from './scheduleDataManager';
|
|
8
8
|
import { transScheduleListToConflictList } from './transform';
|
|
9
|
+
import { EScheduleFunctionType } from '../types';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 冲突检测
|
|
@@ -58,7 +59,27 @@ export class Conflict {
|
|
|
58
59
|
static remove(current) {
|
|
59
60
|
const [cur] = transScheduleListToConflictList([current]);
|
|
60
61
|
scheduleLogger.debug('Conflict.remove cur, current:', cur, current);
|
|
61
|
-
|
|
62
|
+
|
|
63
|
+
// 如果转换后为空(例如倒计时为0时,status为false会被过滤),需要特殊处理
|
|
64
|
+
if (!cur) {
|
|
65
|
+
// 对于倒计时类型,即使status为false,也需要删除冲突数据(因为倒计时的id是固定的)
|
|
66
|
+
if (current.type === EScheduleFunctionType.COUNTDOWN) {
|
|
67
|
+
const countdownSchedule = {
|
|
68
|
+
id: `${EScheduleFunctionType.COUNTDOWN}`,
|
|
69
|
+
type: EScheduleFunctionType.COUNTDOWN,
|
|
70
|
+
data: {
|
|
71
|
+
status: false,
|
|
72
|
+
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
73
|
+
startTime: '',
|
|
74
|
+
endTime: ''
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
scheduleLogger.debug('Conflict.remove: 倒计时为0,使用固定id删除', countdownSchedule);
|
|
78
|
+
ScheduleDataManager.getInstance().deleteData(countdownSchedule);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
ScheduleDataManager.getInstance().deleteData(cur);
|
|
62
83
|
}
|
|
63
84
|
|
|
64
85
|
/**
|