@escapenavigator/utils 1.10.132 → 1.10.133

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.
@@ -0,0 +1,31 @@
1
+ export declare const BOOKING_LEAD_TIME_MINUTE_STEP = 5;
2
+ /** Максимум в селекте «часы» (7 суток). */
3
+ export declare const BOOKING_LEAD_TIME_MAX_HOURS = 168;
4
+ export declare const BOOKING_LEAD_TIME_MAX_MINUTES: number;
5
+ export type BookingLeadTimeParts = {
6
+ hours: number;
7
+ minutes: number;
8
+ };
9
+ export declare const roundBookingLeadMinutesToStep: (totalMinutes: number, step?: number) => number;
10
+ export declare const minutesToBookingLeadParts: (totalMinutes: number) => BookingLeadTimeParts;
11
+ export declare const bookingLeadPartsToMinutes: (hours: number, minutes: number) => number;
12
+ export declare const buildBookingLeadHourOptions: () => Array<{
13
+ key: number;
14
+ content: number;
15
+ }>;
16
+ export declare const buildBookingLeadMinuteOptions: () => Array<{
17
+ key: number;
18
+ content: number;
19
+ }>;
20
+ type RuleLeadTimeLegacy = {
21
+ blockingMinutes?: number | null;
22
+ blockingHours?: number | null;
23
+ minMinutesForBooking?: number | null;
24
+ minHoursForBooking?: number | null;
25
+ };
26
+ export declare const resolveBlockingMinutes: (rule?: RuleLeadTimeLegacy | null) => number;
27
+ export declare const resolveMinMinutesForBooking: (rule?: RuleLeadTimeLegacy | null) => number;
28
+ type TranslateFn = (key: string, options?: Record<string, unknown>) => string;
29
+ /** Человекочитаемый интервал до начала игры для таблиц и описаний. */
30
+ export declare const formatBookingLeadTime: (totalMinutes: number, t: TranslateFn) => string;
31
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatBookingLeadTime = exports.resolveMinMinutesForBooking = exports.resolveBlockingMinutes = exports.buildBookingLeadMinuteOptions = exports.buildBookingLeadHourOptions = exports.bookingLeadPartsToMinutes = exports.minutesToBookingLeadParts = exports.roundBookingLeadMinutesToStep = exports.BOOKING_LEAD_TIME_MAX_MINUTES = exports.BOOKING_LEAD_TIME_MAX_HOURS = exports.BOOKING_LEAD_TIME_MINUTE_STEP = void 0;
4
+ exports.BOOKING_LEAD_TIME_MINUTE_STEP = 5;
5
+ /** Максимум в селекте «часы» (7 суток). */
6
+ exports.BOOKING_LEAD_TIME_MAX_HOURS = 168;
7
+ exports.BOOKING_LEAD_TIME_MAX_MINUTES = exports.BOOKING_LEAD_TIME_MAX_HOURS * 60 + 55;
8
+ const roundBookingLeadMinutesToStep = (totalMinutes, step = exports.BOOKING_LEAD_TIME_MINUTE_STEP) => Math.max(0, Math.round(totalMinutes / step) * step);
9
+ exports.roundBookingLeadMinutesToStep = roundBookingLeadMinutesToStep;
10
+ const minutesToBookingLeadParts = (totalMinutes) => {
11
+ const normalized = (0, exports.roundBookingLeadMinutesToStep)(Math.max(0, totalMinutes || 0));
12
+ const hours = Math.min(exports.BOOKING_LEAD_TIME_MAX_HOURS, Math.floor(normalized / 60));
13
+ const minutes = Math.min(55, normalized - hours * 60);
14
+ return { hours, minutes };
15
+ };
16
+ exports.minutesToBookingLeadParts = minutesToBookingLeadParts;
17
+ const bookingLeadPartsToMinutes = (hours, minutes) => Math.min(exports.BOOKING_LEAD_TIME_MAX_MINUTES, Math.max(0, hours) * 60 + (0, exports.roundBookingLeadMinutesToStep)(minutes));
18
+ exports.bookingLeadPartsToMinutes = bookingLeadPartsToMinutes;
19
+ const buildBookingLeadHourOptions = () => Array.from({ length: exports.BOOKING_LEAD_TIME_MAX_HOURS + 1 }, (_, hours) => ({
20
+ key: hours,
21
+ content: hours,
22
+ }));
23
+ exports.buildBookingLeadHourOptions = buildBookingLeadHourOptions;
24
+ const buildBookingLeadMinuteOptions = () => Array.from({ length: 60 / exports.BOOKING_LEAD_TIME_MINUTE_STEP }, (_, i) => {
25
+ const minutes = i * exports.BOOKING_LEAD_TIME_MINUTE_STEP;
26
+ return { key: minutes, content: minutes };
27
+ });
28
+ exports.buildBookingLeadMinuteOptions = buildBookingLeadMinuteOptions;
29
+ const resolveBlockingMinutes = (rule) => {
30
+ if (rule?.blockingMinutes != null)
31
+ return rule.blockingMinutes;
32
+ return (rule?.blockingHours ?? 0) * 60;
33
+ };
34
+ exports.resolveBlockingMinutes = resolveBlockingMinutes;
35
+ const resolveMinMinutesForBooking = (rule) => {
36
+ if (rule?.minMinutesForBooking != null)
37
+ return rule.minMinutesForBooking;
38
+ return (rule?.minHoursForBooking ?? 0) * 60;
39
+ };
40
+ exports.resolveMinMinutesForBooking = resolveMinMinutesForBooking;
41
+ /** Человекочитаемый интервал до начала игры для таблиц и описаний. */
42
+ const formatBookingLeadTime = (totalMinutes, t) => {
43
+ const { hours, minutes } = (0, exports.minutesToBookingLeadParts)(totalMinutes);
44
+ if (hours > 0 && minutes > 0) {
45
+ return `${hours} ${t('часов')} ${minutes} ${t('мин')}`;
46
+ }
47
+ if (hours > 0) {
48
+ return `${hours} ${t('часов')}`;
49
+ }
50
+ return `${minutes} ${t('мин')}`;
51
+ };
52
+ exports.formatBookingLeadTime = formatBookingLeadTime;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ describe('booking-lead-time', () => {
5
+ it('splits and merges hours and minutes', () => {
6
+ expect((0, index_1.minutesToBookingLeadParts)(90)).toEqual({ hours: 1, minutes: 30 });
7
+ expect((0, index_1.bookingLeadPartsToMinutes)(1, 30)).toBe(90);
8
+ });
9
+ it('rounds to 5-minute step', () => {
10
+ expect((0, index_1.roundBookingLeadMinutesToStep)(32)).toBe(30);
11
+ expect((0, index_1.roundBookingLeadMinutesToStep)(33)).toBe(35);
12
+ });
13
+ it('resolves minutes with legacy hours fallback', () => {
14
+ expect((0, index_1.resolveBlockingMinutes)({ blockingHours: 2 })).toBe(120);
15
+ expect((0, index_1.resolveMinMinutesForBooking)({ minHoursForBooking: 48 })).toBe(2880);
16
+ expect((0, index_1.resolveBlockingMinutes)({ blockingMinutes: 30, blockingHours: 2 })).toBe(30);
17
+ });
18
+ });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './agreement-config';
2
+ export * from './booking-lead-time';
2
3
  export * from './convert-hhmm-to-minutes';
3
4
  export * from './convert-minutes-to-hhmm';
4
5
  export * from './convert-to-options';
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./agreement-config"), exports);
18
+ __exportStar(require("./booking-lead-time"), exports);
18
19
  __exportStar(require("./convert-hhmm-to-minutes"), exports);
19
20
  __exportStar(require("./convert-minutes-to-hhmm"), exports);
20
21
  __exportStar(require("./convert-to-options"), exports);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializeSlot = exports.serializeSlotOrderData = void 0;
4
4
  const defailt_rule_1 = require("@escapenavigator/types/dist/slot-rule/defailt-rule");
5
5
  const buildRuleSummary = (rule) => {
6
- const { prepayment, prepaymentType, title, minHoursForBooking, minHoursForFreeCanceling, cancelationRule, minHoursForFullFine, cancelationAmount, } = rule || defailt_rule_1.defaultRule;
6
+ const { prepayment, prepaymentType, title, minHoursForBooking, minMinutesForBooking, minHoursForFreeCanceling, cancelationRule, minHoursForFullFine, cancelationAmount, } = rule || defailt_rule_1.defaultRule;
7
7
  return {
8
8
  prepayment,
9
9
  minHoursForFullFine,
@@ -11,6 +11,7 @@ const buildRuleSummary = (rule) => {
11
11
  prepaymentType,
12
12
  title,
13
13
  minHoursForBooking,
14
+ minMinutesForBooking: minMinutesForBooking ?? (minHoursForBooking ?? 0) * 60,
14
15
  minHoursForFreeCanceling,
15
16
  cancelationRule,
16
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escapenavigator/utils",
3
- "version": "1.10.132",
3
+ "version": "1.10.133",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "test": "jest"
15
15
  },
16
16
  "dependencies": {
17
- "@escapenavigator/types": "^1.10.128",
17
+ "@escapenavigator/types": "^1.10.129",
18
18
  "axios": "^0.21.4",
19
19
  "class-transformer": "^0.5.1",
20
20
  "class-validator": "^0.13.2",
@@ -27,5 +27,5 @@
27
27
  "ts-jest": "^29.1.1",
28
28
  "typescript": "^5.6"
29
29
  },
30
- "gitHead": "f314b83d632fc068719426b472f60ab03213d533"
30
+ "gitHead": "25c61a2bd7e70a03406358540c8b2b7b2d76bd3a"
31
31
  }