assignment-user-matcher 1.9.0 → 1.11.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 +164 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/learning/auto-weights.d.ts +7 -4
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +7 -6
- package/dist/lua/workflow-transition.lua +8 -2
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +47 -0
- package/dist/managers/WorkflowManager.d.ts +7 -1
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +85 -12
- package/dist/matcher.class.d.ts +35 -3
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +319 -76
- package/dist/queries/users.d.ts +34 -0
- package/dist/queries/users.d.ts.map +1 -0
- package/dist/queries/users.js +227 -0
- package/dist/scheduling/constraints/availability.d.ts +43 -0
- package/dist/scheduling/constraints/availability.d.ts.map +1 -0
- package/dist/scheduling/constraints/availability.js +165 -0
- package/dist/scheduling/constraints/consecutive.d.ts +25 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
- package/dist/scheduling/constraints/consecutive.js +215 -0
- package/dist/scheduling/constraints/constraint.d.ts +35 -0
- package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
- package/dist/scheduling/constraints/constraint.js +97 -0
- package/dist/scheduling/constraints/contract.d.ts +21 -0
- package/dist/scheduling/constraints/contract.d.ts.map +1 -0
- package/dist/scheduling/constraints/contract.js +120 -0
- package/dist/scheduling/constraints/cost.d.ts +18 -0
- package/dist/scheduling/constraints/cost.d.ts.map +1 -0
- package/dist/scheduling/constraints/cost.js +65 -0
- package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
- package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/daily-rest.js +123 -0
- package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
- package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
- package/dist/scheduling/constraints/duty-quota.js +95 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
- package/dist/scheduling/constraints/engagement-floor.js +79 -0
- package/dist/scheduling/constraints/fairness.d.ts +34 -0
- package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
- package/dist/scheduling/constraints/fairness.js +149 -0
- package/dist/scheduling/constraints/group-composition.d.ts +19 -0
- package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
- package/dist/scheduling/constraints/group-composition.js +92 -0
- package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
- package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
- package/dist/scheduling/constraints/hour-budget.js +65 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
- package/dist/scheduling/constraints/in-shift-breaks.js +99 -0
- package/dist/scheduling/constraints/intervals.d.ts +5 -0
- package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
- package/dist/scheduling/constraints/intervals.js +17 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
- package/dist/scheduling/constraints/max-shift-duration.js +38 -0
- package/dist/scheduling/constraints/min-rest.d.ts +22 -0
- package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-rest.js +49 -0
- package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-staffing.js +59 -0
- package/dist/scheduling/constraints/night-work.d.ts +24 -0
- package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
- package/dist/scheduling/constraints/night-work.js +179 -0
- package/dist/scheduling/constraints/no-overlap.d.ts +11 -0
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
- package/dist/scheduling/constraints/no-overlap.js +35 -0
- package/dist/scheduling/constraints/notice.d.ts +44 -0
- package/dist/scheduling/constraints/notice.d.ts.map +1 -0
- package/dist/scheduling/constraints/notice.js +140 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
- package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
- package/dist/scheduling/constraints/overtime.d.ts +47 -0
- package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
- package/dist/scheduling/constraints/overtime.js +149 -0
- package/dist/scheduling/constraints/protections.d.ts +21 -0
- package/dist/scheduling/constraints/protections.d.ts.map +1 -0
- package/dist/scheduling/constraints/protections.js +93 -0
- package/dist/scheduling/constraints/qualification.d.ts +18 -0
- package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
- package/dist/scheduling/constraints/qualification.js +78 -0
- package/dist/scheduling/constraints/rest-days.d.ts +30 -0
- package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
- package/dist/scheduling/constraints/rest-days.js +133 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
- package/dist/scheduling/constraints/rolling-hours.js +147 -0
- package/dist/scheduling/constraints/start-interval.d.ts +20 -0
- package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
- package/dist/scheduling/constraints/start-interval.js +53 -0
- package/dist/scheduling/constraints/support.d.ts +48 -0
- package/dist/scheduling/constraints/support.d.ts.map +1 -0
- package/dist/scheduling/constraints/support.js +97 -0
- package/dist/scheduling/constraints/time-off.d.ts +7 -0
- package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
- package/dist/scheduling/constraints/time-off.js +42 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/weekly-rest.js +103 -0
- package/dist/scheduling/cost.d.ts +56 -0
- package/dist/scheduling/cost.d.ts.map +1 -0
- package/dist/scheduling/cost.js +120 -0
- package/dist/scheduling/engine/construction.d.ts +22 -0
- package/dist/scheduling/engine/construction.d.ts.map +1 -0
- package/dist/scheduling/engine/construction.js +104 -0
- package/dist/scheduling/engine/explain.d.ts +12 -0
- package/dist/scheduling/engine/explain.d.ts.map +1 -0
- package/dist/scheduling/engine/explain.js +24 -0
- package/dist/scheduling/engine/objective.d.ts +73 -0
- package/dist/scheduling/engine/objective.d.ts.map +1 -0
- package/dist/scheduling/engine/objective.js +164 -0
- package/dist/scheduling/engine/prng.d.ts +5 -0
- package/dist/scheduling/engine/prng.d.ts.map +1 -0
- package/dist/scheduling/engine/prng.js +24 -0
- package/dist/scheduling/engine/propagation.d.ts +19 -0
- package/dist/scheduling/engine/propagation.d.ts.map +1 -0
- package/dist/scheduling/engine/propagation.js +40 -0
- package/dist/scheduling/engine/search.d.ts +50 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -0
- package/dist/scheduling/engine/search.js +127 -0
- package/dist/scheduling/engine/state.d.ts +28 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -0
- package/dist/scheduling/engine/state.js +96 -0
- package/dist/scheduling/engine/timeline.d.ts +179 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -0
- package/dist/scheduling/engine/timeline.js +416 -0
- package/dist/scheduling/engine/verdicts.d.ts +18 -0
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
- package/dist/scheduling/engine/verdicts.js +74 -0
- package/dist/scheduling/index.d.ts +10 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +29 -0
- package/dist/scheduling/model.d.ts +53 -0
- package/dist/scheduling/model.d.ts.map +1 -0
- package/dist/scheduling/model.js +380 -0
- package/dist/scheduling/operations.d.ts +134 -0
- package/dist/scheduling/operations.d.ts.map +1 -0
- package/dist/scheduling/operations.js +376 -0
- package/dist/scheduling/provenance.d.ts +33 -0
- package/dist/scheduling/provenance.d.ts.map +1 -0
- package/dist/scheduling/provenance.js +70 -0
- package/dist/scheduling/rules.d.ts +23 -0
- package/dist/scheduling/rules.d.ts.map +1 -0
- package/dist/scheduling/rules.js +37 -0
- package/dist/scheduling/scheduler.class.d.ts +24 -0
- package/dist/scheduling/scheduler.class.d.ts.map +1 -0
- package/dist/scheduling/scheduler.class.js +150 -0
- package/dist/scheduling/time.d.ts +138 -0
- package/dist/scheduling/time.d.ts.map +1 -0
- package/dist/scheduling/time.js +267 -0
- package/dist/scheduling/types.d.ts +938 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +19 -0
- package/dist/types/matcher.d.ts +86 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +1 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +6 -0
- package/package.json +4 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Night work — Directive 2003/88/EC Art 2(3), 2(4) and 8.
|
|
4
|
+
*
|
|
5
|
+
* Art 8 has two limbs that behave differently and are routinely conflated:
|
|
6
|
+
*
|
|
7
|
+
* - **8(a)** caps a night worker's normal hours at an *average* of eight per
|
|
8
|
+
* 24h, over a reference period national law sets (the Directive fixes no
|
|
9
|
+
* ceiling on it);
|
|
10
|
+
* - **8(b)** caps night work involving *special hazards or heavy physical or
|
|
11
|
+
* mental strain* at eight hours in any 24h — **absolute, no averaging**.
|
|
12
|
+
*
|
|
13
|
+
* So the same eight-hour figure is a soft average for most workers and a hard
|
|
14
|
+
* per-day ceiling for some, selected per person by a `hazardousNight`
|
|
15
|
+
* protection. Getting that backwards under-protects exactly the people the
|
|
16
|
+
* provision exists for.
|
|
17
|
+
*
|
|
18
|
+
* The night band itself is national and, in Poland, employer-chosen: it ranges
|
|
19
|
+
* from 20:00–06:00 (BE) to 00:00–07:00 (IE), subject to the Art 2(3) floor of
|
|
20
|
+
* at least seven hours including 00:00–05:00.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.nightWork = exports.NIGHT_WORK_CITATION = void 0;
|
|
24
|
+
const support_1 = require("./support");
|
|
25
|
+
exports.NIGHT_WORK_CITATION = 'Directive 2003/88/EC Art 8';
|
|
26
|
+
function nightWork(rule) {
|
|
27
|
+
return (0, support_1.fromVerdict)({
|
|
28
|
+
id: 'night-work',
|
|
29
|
+
hardness: 'hard',
|
|
30
|
+
weight: 1,
|
|
31
|
+
citation: exports.NIGHT_WORK_CITATION,
|
|
32
|
+
verdict(state, pair) {
|
|
33
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
34
|
+
if (!inst)
|
|
35
|
+
return (0, support_1.pass)('night-work', 'unknown shift');
|
|
36
|
+
const clock = state.ctx.clock;
|
|
37
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
38
|
+
// Outright bans first: 94/33/EC bars adolescents from 00:00-04:00
|
|
39
|
+
// regardless of how the rest of the rule is configured.
|
|
40
|
+
for (const banned of rule.prohibitedRanges ?? []) {
|
|
41
|
+
const inside = clock.minutesInClockRange(range, banned);
|
|
42
|
+
if (inside > 0) {
|
|
43
|
+
return (0, support_1.fail)('night-work', 'hard', `employee "${pair.employeeId}" may not work ${banned.from}-${banned.to}; "${inst.id}" overlaps it by ${(0, support_1.h)(inside)}`, { actual: inside, required: 0, unit: 'minutes', citation: exports.NIGHT_WORK_CITATION });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const timelineForHazard = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
47
|
+
const hazardProbe = {
|
|
48
|
+
...range,
|
|
49
|
+
id: (0, support_1.entryIdOf)(pair),
|
|
50
|
+
workingMinutes: inst.workingMinutes,
|
|
51
|
+
tag: inst.shiftTypeTag,
|
|
52
|
+
};
|
|
53
|
+
// Art 8(b) is checked before the night-shift gate on purpose. The cap
|
|
54
|
+
// is on a hazardous night worker's total work in any 24 hours, so a
|
|
55
|
+
// day shift stacked onto the same rolling day breaches it just as a
|
|
56
|
+
// second night would — gating on "is this shift itself a night shift"
|
|
57
|
+
// would let exactly that combination through.
|
|
58
|
+
if (isHazardous(state, pair.employeeId, rule) && rule.maxShiftMinutes !== undefined) {
|
|
59
|
+
const breach = timelineForHazard.withEntry(hazardProbe, (t) => {
|
|
60
|
+
const worstDay = t.maxWorkingMinutesInAnyWindow(support_1.MINUTES_PER_DAY, {
|
|
61
|
+
start: range.start - support_1.MINUTES_PER_DAY,
|
|
62
|
+
end: range.end + support_1.MINUTES_PER_DAY,
|
|
63
|
+
});
|
|
64
|
+
return worstDay > rule.maxShiftMinutes ? worstDay : null;
|
|
65
|
+
});
|
|
66
|
+
if (breach !== null) {
|
|
67
|
+
return (0, support_1.fail)('night-work', 'hard', `employee "${pair.employeeId}" does hazardous night work and would reach ${(0, support_1.h)(breach)} in a 24h window, over the absolute ${(0, support_1.h)(rule.maxShiftMinutes)} cap`, {
|
|
68
|
+
actual: breach,
|
|
69
|
+
required: rule.maxShiftMinutes,
|
|
70
|
+
unit: 'minutes',
|
|
71
|
+
citation: 'Directive 2003/88/EC Art 8(b)',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!inst.isNightShift) {
|
|
76
|
+
return (0, support_1.pass)('night-work', `"${inst.id}" is not a night shift`, { citation: exports.NIGHT_WORK_CITATION });
|
|
77
|
+
}
|
|
78
|
+
if (rule.maxShiftMinutes !== undefined && inst.workingMinutes > rule.maxShiftMinutes) {
|
|
79
|
+
return (0, support_1.fail)('night-work', 'hard', `night shift "${inst.id}" is ${(0, support_1.h)(inst.workingMinutes)}, over the ${(0, support_1.h)(rule.maxShiftMinutes)} night limit`, {
|
|
80
|
+
actual: inst.workingMinutes,
|
|
81
|
+
required: rule.maxShiftMinutes,
|
|
82
|
+
unit: 'minutes',
|
|
83
|
+
citation: exports.NIGHT_WORK_CITATION,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
87
|
+
const probe = {
|
|
88
|
+
...range,
|
|
89
|
+
id: (0, support_1.entryIdOf)(pair),
|
|
90
|
+
workingMinutes: inst.workingMinutes,
|
|
91
|
+
tag: inst.shiftTypeTag,
|
|
92
|
+
};
|
|
93
|
+
return timeline.withEntry(probe, (t) => {
|
|
94
|
+
// Art 8(a): the averaged limit, for night workers generally.
|
|
95
|
+
if (rule.averageWindowDays !== undefined && rule.maxShiftMinutes !== undefined) {
|
|
96
|
+
const span = rule.averageWindowDays * support_1.MINUTES_PER_DAY;
|
|
97
|
+
const worst = t.maxWorkingMinutesInAnyWindow(span, {
|
|
98
|
+
start: range.start - span,
|
|
99
|
+
end: range.end + span,
|
|
100
|
+
});
|
|
101
|
+
const allowance = rule.maxShiftMinutes * rule.averageWindowDays;
|
|
102
|
+
if (worst > allowance) {
|
|
103
|
+
return (0, support_1.fail)('night-work', 'hard', `employee "${pair.employeeId}" would average over ${(0, support_1.h)(rule.maxShiftMinutes)} of night work per 24h across ${rule.averageWindowDays} days`, {
|
|
104
|
+
actual: worst,
|
|
105
|
+
required: allowance,
|
|
106
|
+
unit: 'minutes',
|
|
107
|
+
citation: 'Directive 2003/88/EC Art 8(a)',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const quota of rule.volumeQuotas ?? []) {
|
|
112
|
+
const span = quota.windowDays * support_1.MINUTES_PER_DAY;
|
|
113
|
+
const count = worstNightCount(state, t, quota, span, range);
|
|
114
|
+
if (count > quota.max) {
|
|
115
|
+
const label = quota.label ?? `${quota.max} night shifts / ${quota.windowDays}d`;
|
|
116
|
+
return (0, support_1.fail)('night-work', 'hard', `employee "${pair.employeeId}" would reach ${count} qualifying night shifts in a ${quota.windowDays}-day window, over the ${label} quota`, { actual: count, required: quota.max, unit: 'count', citation: exports.NIGHT_WORK_CITATION });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return (0, support_1.pass)('night-work', 'within every configured night-work limit', { citation: exports.NIGHT_WORK_CITATION });
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
exports.nightWork = nightWork;
|
|
125
|
+
/** Whether this person is subject to the Art 8(b) absolute cap. */
|
|
126
|
+
function isHazardous(state, employeeId, rule) {
|
|
127
|
+
if (rule.absoluteWhenHazardous === false)
|
|
128
|
+
return false;
|
|
129
|
+
const employee = state.ctx.employeeById.get(employeeId);
|
|
130
|
+
return (employee?.protections ?? []).some((p) => p.kind === 'hazardousNight');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Worst count of qualifying night shifts over any window of `span`.
|
|
134
|
+
*
|
|
135
|
+
* `endingAfter` narrows the count to shifts finishing past a wall-clock time —
|
|
136
|
+
* the Netherlands counts only those ending after 02:00 towards its 36-per-16-week
|
|
137
|
+
* quota, so a 22:00–01:00 shift does not consume the allowance.
|
|
138
|
+
*/
|
|
139
|
+
function worstNightCount(state, timeline, quota, span, around) {
|
|
140
|
+
const clock = state.ctx.clock;
|
|
141
|
+
const qualifies = (entry) => {
|
|
142
|
+
const inst = findInstance(state, entry);
|
|
143
|
+
if (!inst?.isNightShift)
|
|
144
|
+
return false;
|
|
145
|
+
if (!quota.endingAfter)
|
|
146
|
+
return true;
|
|
147
|
+
const day = clock.dayIndexOfMinute(entry.end);
|
|
148
|
+
const threshold = clock.toPeriodMinutes(clock.dateAt(day), quota.endingAfter, 'nightWork.volumeQuotas.endingAfter');
|
|
149
|
+
return entry.end > threshold;
|
|
150
|
+
};
|
|
151
|
+
// Candidate window starts anchored on qualifying-entry boundaries, never a
|
|
152
|
+
// day grid (a grid silently misses straddling breaches — see CLAUDE.md).
|
|
153
|
+
// The count is piecewise constant in the window start: it drops when the
|
|
154
|
+
// left edge passes an entry's end (start = e.end) and gains when the right
|
|
155
|
+
// edge passes an entry's start (start = e.start - span + 1, integer
|
|
156
|
+
// minutes), so those are the only starts that need probing.
|
|
157
|
+
const bounds = { start: around.start - span, end: around.end };
|
|
158
|
+
const starts = new Set([bounds.start, bounds.end]);
|
|
159
|
+
for (const entry of timeline.entriesIn({ start: bounds.start, end: bounds.end + span })) {
|
|
160
|
+
if (!qualifies(entry))
|
|
161
|
+
continue;
|
|
162
|
+
for (const s of [entry.end, entry.start - span + 1]) {
|
|
163
|
+
if (s >= bounds.start && s <= bounds.end)
|
|
164
|
+
starts.add(s);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let worst = 0;
|
|
168
|
+
for (const start of starts) {
|
|
169
|
+
const count = timeline.countIn({ start, end: start + span }, qualifies);
|
|
170
|
+
if (count > worst)
|
|
171
|
+
worst = count;
|
|
172
|
+
}
|
|
173
|
+
return worst;
|
|
174
|
+
}
|
|
175
|
+
/** Recover the shift instance behind a timeline entry, if it is one. */
|
|
176
|
+
function findInstance(state, entry) {
|
|
177
|
+
const instanceId = entry.id.includes('@@') ? entry.id.slice(entry.id.indexOf('@@') + 2) : entry.id;
|
|
178
|
+
return state.ctx.instanceById.get(instanceId);
|
|
179
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-overlap — a person's assignments must never overlap in time, including
|
|
3
|
+
* across midnight for overnight shifts. Hard by default.
|
|
4
|
+
*
|
|
5
|
+
* Judged on the person timeline, not the employee record (CJEU C-585/19): two
|
|
6
|
+
* contracts sharing a `personId` must not put the person in two places at
|
|
7
|
+
* once, and a rostered shift must not overlap a history entry either.
|
|
8
|
+
*/
|
|
9
|
+
import type { SchedulingConstraint } from '../types';
|
|
10
|
+
export declare function noOverlap(): SchedulingConstraint;
|
|
11
|
+
//# sourceMappingURL=no-overlap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-overlap.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/no-overlap.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD,wBAAgB,SAAS,IAAI,oBAAoB,CAmBhD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* No-overlap — a person's assignments must never overlap in time, including
|
|
4
|
+
* across midnight for overnight shifts. Hard by default.
|
|
5
|
+
*
|
|
6
|
+
* Judged on the person timeline, not the employee record (CJEU C-585/19): two
|
|
7
|
+
* contracts sharing a `personId` must not put the person in two places at
|
|
8
|
+
* once, and a rostered shift must not overlap a history entry either.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.noOverlap = void 0;
|
|
12
|
+
const support_1 = require("./support");
|
|
13
|
+
function noOverlap() {
|
|
14
|
+
return {
|
|
15
|
+
id: 'no-overlap',
|
|
16
|
+
hardness: 'hard',
|
|
17
|
+
delta(state, pair) {
|
|
18
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
19
|
+
if (!inst)
|
|
20
|
+
return 0;
|
|
21
|
+
const own = (0, support_1.entryIdOf)(pair);
|
|
22
|
+
for (const entry of (0, support_1.timelineFor)(state, pair.employeeId).entriesIn((0, support_1.rangeOf)(inst))) {
|
|
23
|
+
if (entry.id !== own)
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
},
|
|
28
|
+
explain(state, pair) {
|
|
29
|
+
return this.delta(state, pair) > 0
|
|
30
|
+
? `shift "${pair.shiftInstanceId}" overlaps other work of employee "${pair.employeeId}"'s person`
|
|
31
|
+
: null;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.noOverlap = noOverlap;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predictability of work — Directive (EU) 2019/1152 Art 10.
|
|
3
|
+
*
|
|
4
|
+
* Where a work pattern is wholly or mostly unpredictable, a worker may not be
|
|
5
|
+
* required to work unless *both* the work falls within predetermined reference
|
|
6
|
+
* hours and days, *and* they were given reasonable notice. Where either fails,
|
|
7
|
+
* Art 10(2) gives a **right to refuse without adverse consequences** — so the
|
|
8
|
+
* engine's job is not to forbid the assignment but to mark it refusable, since
|
|
9
|
+
* a roster built on refusable shifts is a roster that will not survive contact
|
|
10
|
+
* with the workforce.
|
|
11
|
+
*
|
|
12
|
+
* Art 10(3) adds that cancelling after a specified deadline entitles the worker
|
|
13
|
+
* to compensation. The Netherlands pays the originally-called hours outright.
|
|
14
|
+
* That makes a late change a *real cost*, not a soft preference, which is why
|
|
15
|
+
* it surfaces as a ledger entry rather than a score nudge.
|
|
16
|
+
*
|
|
17
|
+
* None of this means anything without a published roster: notice is measured
|
|
18
|
+
* from `published.publishedAt`, and with no publication there is nothing to give
|
|
19
|
+
* notice of.
|
|
20
|
+
*/
|
|
21
|
+
import type { NoticeRule, SchedulingConstraint, SearchState } from '../types';
|
|
22
|
+
export declare const NOTICE_CITATION = "Directive (EU) 2019/1152 Art 10";
|
|
23
|
+
export declare function noticeRule(rule: NoticeRule): SchedulingConstraint;
|
|
24
|
+
/**
|
|
25
|
+
* Compensation owed for assignments dropped from a published roster.
|
|
26
|
+
*
|
|
27
|
+
* Computed against the published roster rather than the new one, because the
|
|
28
|
+
* liability attaches to what the worker was told to expect.
|
|
29
|
+
*
|
|
30
|
+
* `cancellationDeadlineMinutes` bounds the protected window before the shift's
|
|
31
|
+
* start: a cancellation inside it owes compensation, one before it does not.
|
|
32
|
+
* The cancellation instant is the run's `asOf`; without one the engine cannot
|
|
33
|
+
* know when the change was made, so every cancellation is treated as late —
|
|
34
|
+
* the conservative reading, since under-stating a wage liability is the error
|
|
35
|
+
* that matters.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cancellationLedger(state: SearchState, rule: NoticeRule | undefined): {
|
|
38
|
+
kind: "lateCancellationPay";
|
|
39
|
+
employeeId: string;
|
|
40
|
+
minutes: number;
|
|
41
|
+
reason: string;
|
|
42
|
+
citation: string;
|
|
43
|
+
}[];
|
|
44
|
+
//# sourceMappingURL=notice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notice.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/notice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAER,UAAU,EAEV,oBAAoB,EACpB,WAAW,EAEd,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,eAAe,oCAAoC,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,oBAAoB,CAoEjE;AAwBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS;;;;;;IAwBlF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Predictability of work — Directive (EU) 2019/1152 Art 10.
|
|
4
|
+
*
|
|
5
|
+
* Where a work pattern is wholly or mostly unpredictable, a worker may not be
|
|
6
|
+
* required to work unless *both* the work falls within predetermined reference
|
|
7
|
+
* hours and days, *and* they were given reasonable notice. Where either fails,
|
|
8
|
+
* Art 10(2) gives a **right to refuse without adverse consequences** — so the
|
|
9
|
+
* engine's job is not to forbid the assignment but to mark it refusable, since
|
|
10
|
+
* a roster built on refusable shifts is a roster that will not survive contact
|
|
11
|
+
* with the workforce.
|
|
12
|
+
*
|
|
13
|
+
* Art 10(3) adds that cancelling after a specified deadline entitles the worker
|
|
14
|
+
* to compensation. The Netherlands pays the originally-called hours outright.
|
|
15
|
+
* That makes a late change a *real cost*, not a soft preference, which is why
|
|
16
|
+
* it surfaces as a ledger entry rather than a score nudge.
|
|
17
|
+
*
|
|
18
|
+
* None of this means anything without a published roster: notice is measured
|
|
19
|
+
* from `published.publishedAt`, and with no publication there is nothing to give
|
|
20
|
+
* notice of.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.cancellationLedger = exports.noticeRule = exports.NOTICE_CITATION = void 0;
|
|
24
|
+
const support_1 = require("./support");
|
|
25
|
+
exports.NOTICE_CITATION = 'Directive (EU) 2019/1152 Art 10';
|
|
26
|
+
function noticeRule(rule) {
|
|
27
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
28
|
+
id: 'notice',
|
|
29
|
+
// Medium, not hard: work outside the reference hours is refusable, not
|
|
30
|
+
// unlawful. Treating it as hard would make rosters infeasible for a
|
|
31
|
+
// right the worker may well not exercise.
|
|
32
|
+
hardness: 'medium',
|
|
33
|
+
weight: 200,
|
|
34
|
+
citation: exports.NOTICE_CITATION,
|
|
35
|
+
verdict(state, pair) {
|
|
36
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
37
|
+
if (!inst)
|
|
38
|
+
return (0, support_1.pass)('notice', 'unknown shift');
|
|
39
|
+
if (rule.referenceHours?.length && !insideReferenceHours(state, inst, rule)) {
|
|
40
|
+
return (0, support_1.fail)('notice', 'medium', `"${inst.id}" falls outside employee "${pair.employeeId}"'s reference hours, so it may be refused without detriment`, { citation: exports.NOTICE_CITATION });
|
|
41
|
+
}
|
|
42
|
+
const shortfall = noticeShortfall(state, inst, rule);
|
|
43
|
+
if (shortfall !== null) {
|
|
44
|
+
return (0, support_1.fail)('notice', 'medium', `"${inst.id}" gives ${(0, support_1.h)(shortfall.given)} notice, below the ${(0, support_1.h)(shortfall.required)} required — refusable without detriment`, {
|
|
45
|
+
actual: shortfall.given,
|
|
46
|
+
required: shortfall.required,
|
|
47
|
+
unit: 'minutes',
|
|
48
|
+
citation: exports.NOTICE_CITATION,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return (0, support_1.pass)('notice', 'within reference hours and given adequate notice', { citation: exports.NOTICE_CITATION });
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
// A published roster that may only change by consent (Finland) or for cause
|
|
55
|
+
// makes every *new* assignment a reportable change, not merely a late one.
|
|
56
|
+
constraint.evaluate = (state) => {
|
|
57
|
+
const out = [];
|
|
58
|
+
if (rule.changeAfterPublication === undefined || rule.changeAfterPublication === 'free')
|
|
59
|
+
return out;
|
|
60
|
+
if (state.ctx.publishedPairs.size === 0)
|
|
61
|
+
return out;
|
|
62
|
+
for (const [instanceId, employees] of state.assignments) {
|
|
63
|
+
for (const employeeId of employees) {
|
|
64
|
+
if (state.ctx.publishedPairs.has(`${employeeId}|${instanceId}`))
|
|
65
|
+
continue;
|
|
66
|
+
out.push({
|
|
67
|
+
constraintId: 'notice',
|
|
68
|
+
severity: 'medium',
|
|
69
|
+
employeeId,
|
|
70
|
+
shiftInstanceId: instanceId,
|
|
71
|
+
message: rule.changeAfterPublication === 'consent'
|
|
72
|
+
? `"${instanceId}" was added for "${employeeId}" after publication; this needs the employee's consent`
|
|
73
|
+
: `"${instanceId}" was added for "${employeeId}" after publication; this needs a compelling reason on record`,
|
|
74
|
+
citation: exports.NOTICE_CITATION,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
};
|
|
80
|
+
return constraint;
|
|
81
|
+
}
|
|
82
|
+
exports.noticeRule = noticeRule;
|
|
83
|
+
function insideReferenceHours(state, inst, rule) {
|
|
84
|
+
const clock = state.ctx.clock;
|
|
85
|
+
const span = inst.endMinute - inst.startMinute;
|
|
86
|
+
for (const window of rule.referenceHours ?? []) {
|
|
87
|
+
if (window.daysOfWeek.length && !window.daysOfWeek.includes(inst.weekday))
|
|
88
|
+
continue;
|
|
89
|
+
const covered = clock.minutesInClockRange({ start: inst.startMinute, end: inst.endMinute }, window);
|
|
90
|
+
if (covered >= span)
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
/** Notice actually given against the notice owed, or `null` when adequate. */
|
|
96
|
+
function noticeShortfall(state, inst, rule) {
|
|
97
|
+
if (rule.minNoticeMinutes === undefined || state.ctx.publishedAtMinute === undefined)
|
|
98
|
+
return null;
|
|
99
|
+
const given = inst.startMinute - state.ctx.publishedAtMinute;
|
|
100
|
+
return given < rule.minNoticeMinutes ? { given: Math.max(0, given), required: rule.minNoticeMinutes } : null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compensation owed for assignments dropped from a published roster.
|
|
104
|
+
*
|
|
105
|
+
* Computed against the published roster rather than the new one, because the
|
|
106
|
+
* liability attaches to what the worker was told to expect.
|
|
107
|
+
*
|
|
108
|
+
* `cancellationDeadlineMinutes` bounds the protected window before the shift's
|
|
109
|
+
* start: a cancellation inside it owes compensation, one before it does not.
|
|
110
|
+
* The cancellation instant is the run's `asOf`; without one the engine cannot
|
|
111
|
+
* know when the change was made, so every cancellation is treated as late —
|
|
112
|
+
* the conservative reading, since under-stating a wage liability is the error
|
|
113
|
+
* that matters.
|
|
114
|
+
*/
|
|
115
|
+
function cancellationLedger(state, rule) {
|
|
116
|
+
if (!rule?.cancellationCompensationMinutes)
|
|
117
|
+
return [];
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const key of state.ctx.publishedPairs) {
|
|
120
|
+
const [employeeId, instanceId] = key.split('|');
|
|
121
|
+
if (state.assignments.get(instanceId)?.has(employeeId))
|
|
122
|
+
continue;
|
|
123
|
+
const inst = state.ctx.instanceById.get(instanceId);
|
|
124
|
+
if (rule.cancellationDeadlineMinutes !== undefined &&
|
|
125
|
+
state.ctx.asOfMinute !== undefined &&
|
|
126
|
+
inst !== undefined &&
|
|
127
|
+
inst.startMinute - state.ctx.asOfMinute >= rule.cancellationDeadlineMinutes) {
|
|
128
|
+
continue; // cancelled with the deadline still ahead — no liability
|
|
129
|
+
}
|
|
130
|
+
out.push({
|
|
131
|
+
kind: 'lateCancellationPay',
|
|
132
|
+
employeeId,
|
|
133
|
+
minutes: Math.max(rule.cancellationCompensationMinutes, inst?.workingMinutes ?? 0),
|
|
134
|
+
reason: `published assignment "${instanceId}" was cancelled`,
|
|
135
|
+
citation: exports.NOTICE_CITATION,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
exports.cancellationLedger = cancellationLedger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shift-per-day — an employee works at most one shift instance per calendar day.
|
|
3
|
+
* Hard by default (mirrors the legacy `<= 1` rule, which was correct).
|
|
4
|
+
*/
|
|
5
|
+
import type { SchedulingConstraint } from '../types';
|
|
6
|
+
export declare function oneShiftPerDay(): SchedulingConstraint;
|
|
7
|
+
//# sourceMappingURL=one-shift-per-day.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one-shift-per-day.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/one-shift-per-day.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,wBAAgB,cAAc,IAAI,oBAAoB,CAsBrD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* One-shift-per-day — an employee works at most one shift instance per calendar day.
|
|
4
|
+
* Hard by default (mirrors the legacy `<= 1` rule, which was correct).
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.oneShiftPerDay = void 0;
|
|
8
|
+
function oneShiftPerDay() {
|
|
9
|
+
return {
|
|
10
|
+
id: 'one-shift-per-day',
|
|
11
|
+
hardness: 'hard',
|
|
12
|
+
delta(state, pair) {
|
|
13
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
14
|
+
if (!inst)
|
|
15
|
+
return 0;
|
|
16
|
+
const assigned = state.byEmployee.get(pair.employeeId);
|
|
17
|
+
if (!assigned)
|
|
18
|
+
return 0;
|
|
19
|
+
for (const otherId of assigned) {
|
|
20
|
+
if (otherId === pair.shiftInstanceId)
|
|
21
|
+
continue;
|
|
22
|
+
const other = state.ctx.instanceById.get(otherId);
|
|
23
|
+
if (other && other.date === inst.date)
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
},
|
|
28
|
+
explain(state, pair) {
|
|
29
|
+
return this.delta(state, pair) > 0
|
|
30
|
+
? `employee "${pair.employeeId}" already has a shift on ${state.ctx.instanceById.get(pair.shiftInstanceId)?.date}`
|
|
31
|
+
: null;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.oneShiftPerDay = oneShiftPerDay;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overtime — the ordinary-vs-overtime split.
|
|
3
|
+
*
|
|
4
|
+
* `rolling-hours` caps *total* working time; this rule regulates the overtime
|
|
5
|
+
* portion by itself, which several member states do separately: Estonia's TLS
|
|
6
|
+
* §44 makes overtime conditional on the employee's agreement and compensates it
|
|
7
|
+
* primarily in equal time off, Germany builds the 10-hour day out of 8 ordinary
|
|
8
|
+
* plus averaged surplus, Austria caps overtime hours in their own right.
|
|
9
|
+
*
|
|
10
|
+
* Overtime is defined against an *ordinary baseline*, never inferred: the
|
|
11
|
+
* caller supplies `ordinaryPerDayMinutes` / `ordinaryPerWeekMinutes`, and a
|
|
12
|
+
* person's `contract.weeklyMinutes` overrides the weekly figure — a part-timer
|
|
13
|
+
* on 20 agreed hours starts earning overtime at 20, not at full time. Both
|
|
14
|
+
* measures run over rolling windows anchored on the person's own assignment
|
|
15
|
+
* boundaries, like every other window rule in this module.
|
|
16
|
+
*
|
|
17
|
+
* Three checks, all hard:
|
|
18
|
+
* - consent: with `requiresConsent`, any overtime at all needs the employee's
|
|
19
|
+
* recorded `overtimeConsent`;
|
|
20
|
+
* - a cap on overtime in any rolling 24h;
|
|
21
|
+
* - caps on overtime over longer rolling windows, against the weekly baseline
|
|
22
|
+
* pro-rated to the window.
|
|
23
|
+
*
|
|
24
|
+
* Compensation in time off is not a constraint but a debt: `overtimeLedger`
|
|
25
|
+
* turns each employee's period overtime into a `timeOffInLieu` ledger entry.
|
|
26
|
+
*/
|
|
27
|
+
import type { LedgerEntry, OvertimeRule, SchedulingConstraint, SearchState } from '../types';
|
|
28
|
+
export declare const OVERTIME_CITATION = "National overtime law (e.g. EE T\u00F6\u00F6lepingu seadus \u00A744, DE ArbZG \u00A73)";
|
|
29
|
+
/**
|
|
30
|
+
* Assert an overtime rule can actually be evaluated. Applied to the global rule
|
|
31
|
+
* at registration and to each per-person override in `buildModel` — an override
|
|
32
|
+
* replaces the whole family, so it must stand on its own.
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertValidOvertimeRule(rule: OvertimeRule, owner?: string): void;
|
|
35
|
+
export declare function overtime(rule: OvertimeRule): SchedulingConstraint;
|
|
36
|
+
/**
|
|
37
|
+
* Time-off-in-lieu accrued by the roster: each employee's working minutes past
|
|
38
|
+
* their pro-rated ordinary baseline, where the applied rule compensates
|
|
39
|
+
* overtime in time off.
|
|
40
|
+
*
|
|
41
|
+
* Accrual is per employee record, not per person — the debt is owed under a
|
|
42
|
+
* contract even when working-time *limits* aggregate across contracts. It needs
|
|
43
|
+
* a weekly baseline (contract minutes or `ordinaryPerWeekMinutes`); a purely
|
|
44
|
+
* daily split cannot be pro-rated over a period without inventing a workweek.
|
|
45
|
+
*/
|
|
46
|
+
export declare function overtimeLedger(state: SearchState): LedgerEntry[];
|
|
47
|
+
//# sourceMappingURL=overtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overtime.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/overtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAY,WAAW,EAAE,YAAY,EAAe,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAgBpH,eAAO,MAAM,iBAAiB,2FAAuE,CAAC;AAEtG;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,SAAU,GAAG,IAAI,CAYjF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,oBAAoB,CAkFjE;AAOD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,EAAE,CAiBhE"}
|