@webitel/api-services 26.12.38 → 26.12.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "26.12.38",
3
+ "version": "26.12.39",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,10 +24,17 @@ describe('getTimeRangeDuration', () => {
24
24
  ],
25
25
  [
26
26
  {
27
- start: 700,
28
- end: 600,
27
+ start: 1320,
28
+ end: 360,
29
29
  },
30
- 0,
30
+ 480,
31
+ ],
32
+ [
33
+ {
34
+ start: 1320,
35
+ end: 0,
36
+ },
37
+ 120,
31
38
  ],
32
39
  [
33
40
  {
@@ -59,6 +66,17 @@ describe('setTimeRangeDuration', () => {
59
66
  });
60
67
  });
61
68
 
69
+ it('wraps end past midnight', () => {
70
+ const range = {
71
+ start: 1320,
72
+ end: 1380,
73
+ };
74
+
75
+ setTimeRangeDuration(range, 480);
76
+
77
+ expect(range.end).toBe(360);
78
+ });
79
+
62
80
  it('counts from 0 when start is unset', () => {
63
81
  const range: Partial<TimeRange> = {};
64
82
 
@@ -1,3 +1,4 @@
1
+ import { minutesInDay } from 'date-fns/constants';
1
2
  import { z } from 'zod';
2
3
 
3
4
  import { i18nIssue } from './i18nIssue';
@@ -5,7 +6,10 @@ import { i18nIssue } from './i18nIssue';
5
6
  export const dayMinuteSchema = z
6
7
  .number()
7
8
  .int()
8
- .refine((value) => value >= 0 && value < 24 * 60, i18nIssue('hourRange'));
9
+ .refine(
10
+ (value) => value >= 0 && value < minutesInDay,
11
+ i18nIssue('hourRange'),
12
+ );
9
13
 
10
14
  export type TimeRange = {
11
15
  start: number;
@@ -47,6 +51,21 @@ export const refineTimeRangeStartLessThanEnd = (
47
51
  if (item.start >= item.end) addRangeIssue(ctx, 'timerangeStartLessThanEnd');
48
52
  };
49
53
 
54
+ /** [Claude] an empty range (start = end) is reported once, on `end` */
55
+ export const refineTimeRangeEndNotEqualStart = (
56
+ item: TimeRange,
57
+ ctx: z.RefinementCtx,
58
+ ) => {
59
+ if (item.start !== item.end) return;
60
+ ctx.addIssue({
61
+ code: 'custom',
62
+ path: [
63
+ 'end',
64
+ ],
65
+ ...i18nIssue('timerangeEndNotEqualStart'),
66
+ });
67
+ };
68
+
50
69
  export const timeRangeSchema = z
51
70
  .object({
52
71
  start: dayMinuteSchema,
@@ -55,19 +74,20 @@ export const timeRangeSchema = z
55
74
  .superRefine(refineTimeRangeStartLessThanEnd);
56
75
 
57
76
  /**
58
- * [Claude] range length in minutes; an unset bound counts as 0, an inverted range as 0
77
+ * [Claude] range length in minutes, crossing midnight when `end` is before `start`
78
+ * (22:00–06:00 → 8h); an unset bound counts as 0
59
79
  */
60
80
  export const getTimeRangeDuration = (range: Partial<TimeRange>) =>
61
- Math.max(0, (range.end ?? 0) - (range.start ?? 0));
81
+ ((range.end ?? 0) - (range.start ?? 0) + minutesInDay) % minutesInDay;
62
82
 
63
83
  /**
64
- * [Claude] sets the length by moving `end`; `start` stays
84
+ * [Claude] sets the length by moving `end`, wrapping past midnight; `start` stays
65
85
  */
66
86
  export const setTimeRangeDuration = (
67
87
  range: Partial<TimeRange>,
68
88
  minutes: number,
69
89
  ) => {
70
- range.end = (range.start ?? 0) + minutes;
90
+ range.end = ((range.start ?? 0) + minutes) % minutesInDay;
71
91
  };
72
92
 
73
93
  const isIntersecting = (a: TimeRange, b: TimeRange) =>
@@ -77,14 +77,21 @@ describe('shiftTemplateSchema', () => {
77
77
  ).toBe(false);
78
78
  });
79
79
 
80
+ it('accepts an overnight row (end before start)', () => {
81
+ expect(
82
+ shiftTemplateSchema.safeParse({
83
+ ...valid,
84
+ times: [
85
+ {
86
+ start: 1320,
87
+ end: 360,
88
+ },
89
+ ],
90
+ }).success,
91
+ ).toBe(true);
92
+ });
93
+
80
94
  it.each([
81
- [
82
- 'end before start',
83
- {
84
- start: 600,
85
- end: 540,
86
- },
87
- ],
88
95
  [
89
96
  'zero duration',
90
97
  {
@@ -118,28 +125,23 @@ describe('shiftTemplateSchema', () => {
118
125
  });
119
126
 
120
127
  describe('getShiftTemplateTimeRangeErrors', () => {
121
- it('marks both ends of a row whose start is not before its end', () => {
128
+ it('marks only the end of a row whose start equals its end', () => {
122
129
  expect(
123
130
  getShiftTemplateTimeRangeErrors([
124
131
  {
125
- start: 540,
126
- end: 1200,
132
+ start: 1320,
133
+ end: 360,
127
134
  },
128
135
  {
129
136
  start: 600,
130
- end: 540,
137
+ end: 600,
131
138
  },
132
139
  ]),
133
140
  ).toEqual([
134
- {
135
- index: 1,
136
- prop: 'start',
137
- key: 'timerangeStartLessThanEnd',
138
- },
139
141
  {
140
142
  index: 1,
141
143
  prop: 'end',
142
- key: 'timerangeStartLessThanEnd',
144
+ key: 'timerangeEndNotEqualStart',
143
145
  },
144
146
  ]);
145
147
  });
@@ -2,16 +2,25 @@ import type { WfmShiftTemplate } from '@webitel/api-services/gen/models';
2
2
  import { z } from 'zod';
3
3
 
4
4
  import {
5
+ dayMinuteSchema,
5
6
  getTimeRangeErrors,
7
+ refineTimeRangeEndNotEqualStart,
6
8
  type TimeRange,
7
- timeRangeSchema,
8
9
  } from '../_shared/timeRange.validations';
9
10
  import type { ZodShape } from '../types';
10
11
 
11
12
  /**
12
- * [Claude] each row is a part of the shift within a day: start < end, both in minutes
13
+ * [Claude] each row is a part of the shift, in minutes of the day; it may cross
14
+ * midnight (22:00–06:00), so only start = end is rejected, under `end`
13
15
  */
14
- const shiftTemplateTimesSchema = z.array(timeRangeSchema).min(1);
16
+ const shiftTemplateTimeSchema = z
17
+ .object({
18
+ start: dayMinuteSchema,
19
+ end: dayMinuteSchema,
20
+ })
21
+ .superRefine(refineTimeRangeEndNotEqualStart);
22
+
23
+ const shiftTemplateTimesSchema = z.array(shiftTemplateTimeSchema).min(1);
15
24
 
16
25
  /**
17
26
  * [Claude] row errors for `useTimeRangesValidation`: regle marks a row as a plain field,