Skip to content

Commit 6f9101d

Browse files
committed
chore: move to duration based schedule
1 parent 90fdf38 commit 6f9101d

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

docs/es-modules/schedule.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ <h3 class="mt-4">Example Code (ESM):</h3>
5252
publicId: 'sea_turtle',
5353
schedule: {
5454
weekly: [
55-
{ day: 'monday', start: '09:00', end: '17:00' },
56-
{ day: 'tuesday', start: '09:00', end: '17:00' }
55+
{ day: 'monday', start: '09:00', duration: 8 },
56+
{ day: 'tuesday', start: '09:00', duration: 8 }
5757
]
5858
}
5959
});
@@ -73,7 +73,7 @@ <h3 class="mt-4">Example Code (ESM):</h3>
7373
const slots = [];
7474
for (let d = 0; d < 7; d++) {
7575
if (d !== today) {
76-
slots.push({ day: DAY_NAMES[d], start: '00:00', end: '23:59' });
76+
slots.push({ day: DAY_NAMES[d], start: '00:00', duration: 24 });
7777
}
7878
}
7979
return slots;
@@ -82,7 +82,7 @@ <h3 class="mt-4">Example Code (ESM):</h3>
8282
function getScheduleForPlayerMode() {
8383
const now = new Date();
8484
const today = now.getDay();
85-
return [{ day: DAY_NAMES[today], start: '00:00', end: '23:59' }];
85+
return [{ day: DAY_NAMES[today], start: '00:00', duration: 24 }];
8686
}
8787

8888
function loadPlayerWithMode(showPlayer) {

docs/schedule.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var slots = [];
2323
for (var d = 0; d < 7; d++) {
2424
if (d !== today) {
25-
slots.push({ day: DAY_NAMES[d], start: '00:00', end: '23:59' });
25+
slots.push({ day: DAY_NAMES[d], start: '00:00', duration: 24 });
2626
}
2727
}
2828
return slots;
@@ -31,7 +31,7 @@
3131
function getScheduleForPlayerMode() {
3232
var now = new Date();
3333
var today = now.getDay();
34-
return [{ day: DAY_NAMES[today], start: '00:00', end: '23:59' }];
34+
return [{ day: DAY_NAMES[today], start: '00:00', duration: 24 }];
3535
}
3636

3737
function loadPlayerWithMode(showPlayer) {
@@ -105,8 +105,8 @@ <h3 class="mt-4">Example Code:</h3>
105105
publicId: 'sea_turtle',
106106
schedule: {
107107
weekly: [
108-
{ day: 'monday', start: '09:00', end: '17:00' },
109-
{ day: 'tuesday', start: '09:00', end: '17:00' }
108+
{ day: 'monday', start: '09:00', duration: 8 },
109+
{ day: 'tuesday', start: '09:00', duration: 8 }
110110
]
111111
}
112112
});

src/config/configSchema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,9 @@
569569
"properties": {
570570
"day": { "type": "string" },
571571
"start": { "type": "string" },
572-
"end": { "type": "string" }
572+
"duration": { "type": "number" }
573573
},
574-
"required": ["day", "start", "end"]
574+
"required": ["day", "start", "duration"]
575575
},
576576
"default": []
577577
}

src/utils/schedule.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const parseTime = (timeStr) => {
121121

122122
/**
123123
* Check if a date falls within any configured weekly slot (local time).
124-
* @param {{ weekly?: Array<{ day: string, start: string, end: string }> }} schedule - schedule config
124+
* @param {{ weekly?: Array<{ day: string, start: string, duration: number }> }} schedule - schedule config
125125
* @param {Date} date - date to check (uses local time)
126126
* @returns {boolean} true if within a slot
127127
*/
@@ -139,8 +139,8 @@ export const isWithinSchedule = (schedule, date) => {
139139
if (slotDay !== day) continue;
140140

141141
const startMin = parseTime(slot.start);
142-
const endMin = parseTime(slot.end);
143-
if (startMin === null || endMin === null) continue;
142+
if (startMin === null || typeof slot.duration !== 'number' || slot.duration <= 0) continue;
143+
const endMin = startMin + slot.duration * 60;
144144

145145
if (startMin <= endMin) {
146146
if (minutes >= startMin && minutes < endMin) return true;

test/unit/schedule.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ describe('schedule utils', () => {
4646
it('returns true when date falls within a slot', () => {
4747
const monday9am = new Date(2025, 2, 10, 9, 30);
4848
const schedule = {
49-
weekly: [{ day: 'monday', start: '09:00', end: '17:00' }]
49+
weekly: [{ day: 'monday', start: '09:00', duration: 8 }]
5050
};
5151
expect(isWithinSchedule(schedule, monday9am)).toBe(true);
5252
});
5353

5454
it('returns false when date is outside all slots', () => {
5555
const monday8am = new Date(2025, 2, 10, 8, 0);
5656
const schedule = {
57-
weekly: [{ day: 'monday', start: '09:00', end: '17:00' }]
57+
weekly: [{ day: 'monday', start: '09:00', duration: 8 }]
5858
};
5959
expect(isWithinSchedule(schedule, monday8am)).toBe(false);
6060
});
@@ -63,7 +63,7 @@ describe('schedule utils', () => {
6363
const monday9am = new Date(2025, 2, 10, 9, 0);
6464
const monday5pm = new Date(2025, 2, 10, 17, 0);
6565
const schedule = {
66-
weekly: [{ day: 'monday', start: '09:00', end: '17:00' }]
66+
weekly: [{ day: 'monday', start: '09:00', duration: 8 }]
6767
};
6868
expect(isWithinSchedule(schedule, monday9am)).toBe(true);
6969
expect(isWithinSchedule(schedule, monday5pm)).toBe(false);
@@ -73,8 +73,8 @@ describe('schedule utils', () => {
7373
const wednesday2pm = new Date(2025, 2, 12, 14, 0);
7474
const schedule = {
7575
weekly: [
76-
{ day: 'monday', start: '09:00', end: '17:00' },
77-
{ day: 'wednesday', start: '12:00', end: '18:00' }
76+
{ day: 'monday', start: '09:00', duration: 8 },
77+
{ day: 'wednesday', start: '12:00', duration: 6 }
7878
]
7979
};
8080
expect(isWithinSchedule(schedule, wednesday2pm)).toBe(true);

0 commit comments

Comments
 (0)