scschedule 2.1.1 → 3.1.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.
Files changed (44) hide show
  1. package/README.md +161 -74
  2. package/dist/cleanupExpiredOverridesFromSchedule.d.ts +4 -0
  3. package/dist/cleanupExpiredOverridesFromSchedule.js +4 -0
  4. package/dist/constants.d.ts +1 -10
  5. package/dist/constants.js +1 -10
  6. package/dist/getAvailableRangesFromSchedule.d.ts +10 -0
  7. package/dist/getAvailableRangesFromSchedule.js +29 -13
  8. package/dist/getNextAvailableFromSchedule.d.ts +9 -8
  9. package/dist/getNextAvailableFromSchedule.js +21 -17
  10. package/dist/getNextUnavailableFromSchedule.d.ts +19 -9
  11. package/dist/getNextUnavailableFromSchedule.js +120 -63
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.js +4 -2
  14. package/dist/internal/doTimeRangesOverlap.d.ts +1 -1
  15. package/dist/internal/getApplicableRuleForDate.d.ts +11 -11
  16. package/dist/internal/getApplicableRuleForDate.js +11 -7
  17. package/dist/internal/getEffectiveTimesForWeekday.d.ts +2 -1
  18. package/dist/internal/getEffectiveTimesForWeekday.js +9 -14
  19. package/dist/internal/index.d.ts +1 -4
  20. package/dist/internal/index.js +0 -4
  21. package/dist/internal/isTimeInTimeRange.d.ts +2 -1
  22. package/dist/internal/splitCrossMidnightTimeRange.d.ts +1 -1
  23. package/dist/internal/splitCrossMidnightTimeRange.js +3 -2
  24. package/dist/internal/types.d.ts +13 -0
  25. package/dist/internal/types.js +1 -0
  26. package/dist/internal/validateNoEmptyWeekdays.js +2 -1
  27. package/dist/internal/validateNoOverlappingRules.js +5 -4
  28. package/dist/internal/validateNoSpilloverConflictsAtOverrideBoundaries.d.ts +4 -2
  29. package/dist/internal/validateNoSpilloverConflictsAtOverrideBoundaries.js +95 -88
  30. package/dist/internal/validateScDateFormats.js +4 -5
  31. package/dist/isScheduleAvailable.d.ts +9 -0
  32. package/dist/isScheduleAvailable.js +23 -6
  33. package/dist/types.d.ts +18 -64
  34. package/dist/validateSchedule.d.ts +4 -2
  35. package/dist/validateSchedule.js +4 -8
  36. package/package.json +2 -2
  37. package/dist/internal/isValidTimezone.d.ts +0 -4
  38. package/dist/internal/isValidTimezone.js +0 -12
  39. package/dist/internal/validateNoOverlappingTimesInRule.d.ts +0 -5
  40. package/dist/internal/validateNoOverlappingTimesInRule.js +0 -54
  41. package/dist/internal/validateNonEmptyTimes.d.ts +0 -5
  42. package/dist/internal/validateNonEmptyTimes.js +0 -35
  43. package/dist/internal/validateTimezone.d.ts +0 -5
  44. package/dist/internal/validateTimezone.js +0 -16
@@ -1,54 +0,0 @@
1
- import { RuleLocationType, ValidationIssue } from '../constants.js';
2
- import { doTimeRangesOverlap } from './doTimeRangesOverlap.js';
3
- /**
4
- * Validates that time ranges within a single rule do not overlap.
5
- */
6
- const validateRuleTimes = (rule, location) => {
7
- const errors = [];
8
- if (rule.times.length < 2) {
9
- return errors;
10
- }
11
- // Check all pairs of time ranges for overlap on the same weekday
12
- for (let i = 0; i < rule.times.length; i++) {
13
- for (let j = i + 1; j < rule.times.length; j++) {
14
- const timeRange1 = rule.times[i];
15
- const timeRange2 = rule.times[j];
16
- if (timeRange1 &&
17
- timeRange2 &&
18
- doTimeRangesOverlap(timeRange1, timeRange2)) {
19
- errors.push({
20
- issue: ValidationIssue.OverlappingTimesInRule,
21
- location,
22
- timeRangeIndexes: [i, j],
23
- });
24
- }
25
- }
26
- }
27
- return errors;
28
- };
29
- /**
30
- * Validates that time ranges within rules do not overlap with each other.
31
- */
32
- export const validateNoOverlappingTimesInRule = (schedule) => {
33
- const errors = [];
34
- // Validate weekly rules
35
- schedule.weekly.forEach((rule, ruleIndex) => {
36
- const ruleErrors = validateRuleTimes(rule, {
37
- type: RuleLocationType.Weekly,
38
- ruleIndex,
39
- });
40
- errors.push(...ruleErrors);
41
- });
42
- // Validate override rules
43
- schedule.overrides?.forEach((override, overrideIndex) => {
44
- override.rules.forEach((rule, ruleIndex) => {
45
- const ruleErrors = validateRuleTimes(rule, {
46
- type: RuleLocationType.Override,
47
- overrideIndex,
48
- ruleIndex,
49
- });
50
- errors.push(...ruleErrors);
51
- });
52
- });
53
- return errors;
54
- };
@@ -1,5 +0,0 @@
1
- import type { Schedule, ValidationError } from '../types.js';
2
- /**
3
- * Validates that all rules have at least one time range defined.
4
- */
5
- export declare const validateNonEmptyTimes: (schedule: Schedule) => ValidationError[];
@@ -1,35 +0,0 @@
1
- import { RuleLocationType, ValidationIssue } from '../constants.js';
2
- /**
3
- * Validates that all rules have at least one time range defined.
4
- */
5
- export const validateNonEmptyTimes = (schedule) => {
6
- const errors = [];
7
- // Validate weekly rules
8
- schedule.weekly.forEach((rule, ruleIndex) => {
9
- if (rule.times.length === 0) {
10
- errors.push({
11
- issue: ValidationIssue.EmptyTimes,
12
- location: {
13
- type: RuleLocationType.Weekly,
14
- ruleIndex,
15
- },
16
- });
17
- }
18
- });
19
- // Validate override rules
20
- schedule.overrides?.forEach((override, overrideIndex) => {
21
- override.rules.forEach((rule, ruleIndex) => {
22
- if (rule.times.length === 0) {
23
- errors.push({
24
- issue: ValidationIssue.EmptyTimes,
25
- location: {
26
- type: RuleLocationType.Override,
27
- overrideIndex,
28
- ruleIndex,
29
- },
30
- });
31
- }
32
- });
33
- });
34
- return errors;
35
- };
@@ -1,5 +0,0 @@
1
- import type { Schedule, ValidationError } from '../types.js';
2
- /**
3
- * Validates that a schedule's timezone is a valid IANA timezone identifier.
4
- */
5
- export declare const validateTimezone: (schedule: Schedule) => ValidationError[];
@@ -1,16 +0,0 @@
1
- import { ValidationIssue } from '../constants.js';
2
- import { isValidTimezone } from './isValidTimezone.js';
3
- /**
4
- * Validates that a schedule's timezone is a valid IANA timezone identifier.
5
- */
6
- export const validateTimezone = (schedule) => {
7
- if (!isValidTimezone(schedule.timezone)) {
8
- return [
9
- {
10
- issue: ValidationIssue.InvalidTimezone,
11
- timezone: schedule.timezone,
12
- },
13
- ];
14
- }
15
- return [];
16
- };