scschedule 4.1.1 → 4.2.0

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/README.md CHANGED
@@ -213,6 +213,25 @@ const isOpen = isScheduleAvailable(
213
213
  )
214
214
  ```
215
215
 
216
+ #### `isInOvernightSpillover(schedule: Schedule, date: SDate | string, time: STime | string): boolean`
217
+
218
+ Returns true if the given date and time fall within overnight spillover from the previous day's schedule. Useful when modifying the previous day's schedule would affect current availability (e.g., a business owner wanting to close early during an overnight shift that started yesterday).
219
+
220
+ ```typescript
221
+ import { isInOvernightSpillover } from 'scschedule'
222
+ import { sDate, sTime } from 'scdate'
223
+
224
+ // Friday 01:00 is in Thursday's 22:00-02:00 spillover
225
+ const inSpillover = isInOvernightSpillover(
226
+ schedule,
227
+ sDate('2025-01-11'),
228
+ sTime('01:00'),
229
+ )
230
+ if (inSpillover) {
231
+ // Modifying Thursday's schedule would affect current availability
232
+ }
233
+ ```
234
+
216
235
  #### `getNextAvailableFromSchedule(schedule: Schedule, fromTimestamp: STimestamp | string, maxDaysToSearch: number): STimestamp | undefined`
217
236
 
218
237
  Find the next available timestamp from a given time. Searches up to `maxDaysToSearch` days forward.
package/dist/index.d.ts CHANGED
@@ -8,4 +8,5 @@ export * from './getApplicableRuleForDate.js';
8
8
  export * from './getAvailableRangesFromSchedule.js';
9
9
  export * from './getNextAvailableFromSchedule.js';
10
10
  export * from './getNextUnavailableFromSchedule.js';
11
+ export * from './isInOvernightSpillover.js';
11
12
  export * from './isScheduleAvailable.js';
package/dist/index.js CHANGED
@@ -11,4 +11,5 @@ export * from './getApplicableRuleForDate.js';
11
11
  export * from './getAvailableRangesFromSchedule.js';
12
12
  export * from './getNextAvailableFromSchedule.js';
13
13
  export * from './getNextUnavailableFromSchedule.js';
14
+ export * from './isInOvernightSpillover.js';
14
15
  export * from './isScheduleAvailable.js';
@@ -0,0 +1,21 @@
1
+ import { type SDate, type STime } from 'scdate';
2
+ import type { Schedule, SDateString, STimeString } from './types.js';
3
+ /**
4
+ * Returns true if the given date and time fall within overnight spillover from
5
+ * the previous day's schedule.
6
+ *
7
+ * An overnight rule (where `to` < `from`, e.g. 22:00-02:00) spills into the
8
+ * next calendar day. This function checks whether the given time on the given
9
+ * date falls before that rule's `to` time — i.e., within the spillover window.
10
+ *
11
+ * Use this to determine whether modifying the previous day's schedule would
12
+ * affect current availability. For example, a business owner wanting to close
13
+ * early during an overnight shift that started yesterday needs to know if
14
+ * today's early-morning availability is driven by yesterday's rules.
15
+ *
16
+ * @param schedule The schedule to check.
17
+ * @param date The date to check (the "current" day).
18
+ * @param time The time to check.
19
+ * @returns True if (date, time) is in spillover from the previous day.
20
+ */
21
+ export declare const isInOvernightSpillover: (schedule: Schedule, date: SDate | SDateString, time: STime | STimeString) => boolean;
@@ -0,0 +1,36 @@
1
+ import { addDaysToDate, getTimeAtMidnight, getWeekdayFromDate, isSameTime, } from 'scdate';
2
+ import { getApplicableRuleForDate } from './getApplicableRuleForDate.js';
3
+ import { getEffectiveTimesForWeekday } from './internal/getEffectiveTimesForWeekday.js';
4
+ import { isTimeInTimeRange } from './internal/isTimeInTimeRange.js';
5
+ /**
6
+ * Returns true if the given date and time fall within overnight spillover from
7
+ * the previous day's schedule.
8
+ *
9
+ * An overnight rule (where `to` < `from`, e.g. 22:00-02:00) spills into the
10
+ * next calendar day. This function checks whether the given time on the given
11
+ * date falls before that rule's `to` time — i.e., within the spillover window.
12
+ *
13
+ * Use this to determine whether modifying the previous day's schedule would
14
+ * affect current availability. For example, a business owner wanting to close
15
+ * early during an overnight shift that started yesterday needs to know if
16
+ * today's early-morning availability is driven by yesterday's rules.
17
+ *
18
+ * @param schedule The schedule to check.
19
+ * @param date The date to check (the "current" day).
20
+ * @param time The time to check.
21
+ * @returns True if (date, time) is in spillover from the previous day.
22
+ */
23
+ export const isInOvernightSpillover = (schedule, date, time) => {
24
+ const previousDate = addDaysToDate(date, -1);
25
+ const currentWeekday = getWeekdayFromDate(date);
26
+ const previousResult = getApplicableRuleForDate(schedule, previousDate);
27
+ if (previousResult.rules === true) {
28
+ return false;
29
+ }
30
+ const midnight = getTimeAtMidnight();
31
+ return previousResult.rules.some((rule) => {
32
+ const effectiveTimes = getEffectiveTimesForWeekday(rule, currentWeekday);
33
+ const spilloverRanges = effectiveTimes.filter((range) => isSameTime(range.from, midnight));
34
+ return spilloverRanges.some((range) => isTimeInTimeRange(time, range, true));
35
+ });
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scschedule",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dist/index.js"
@@ -20,7 +20,7 @@
20
20
  "test": "vitest run"
21
21
  },
22
22
  "dependencies": {
23
- "scdate": "4.1.1"
23
+ "scdate": "4.2.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@eslint/js": "^9.39.3",