@ray-js/lamp-schedule-core 1.0.4-beta-7 → 1.0.4-beta-8

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 > b1 && b2 > a1
85
+ // 使用标准区间重叠判断: [a1,a2] 和 [b1,b2] 重叠当且仅当 a2 >= b1 && b2 >= a1
86
86
  // 注意:这里已经处理了跨天情况(通过标准化为连续分钟数)
87
- return aEndMin > bStartMin && bEndMin > aStartMin;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-schedule-core",
3
- "version": "1.0.4-beta-7",
3
+ "version": "1.0.4-beta-8",
4
4
  "description": "照明计划模块核心能力",
5
5
  "main": "./lib/index.js",
6
6
  "files": [