chuvsu-js 2.4.1 → 2.4.2
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/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/tt/schedule.d.ts +4 -2
- package/dist/tt/schedule.js +5 -2
- package/dist/tt/utils.d.ts +43 -3
- package/dist/tt/utils.js +180 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export { LkClient } from "./lk/client.js";
|
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
4
|
export type { CacheEntry } from "./common/cache.js";
|
|
5
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
6
|
-
export type { Holiday } from "./tt/utils.js";
|
|
5
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, getEffectiveHolidays, getHolidayTransfers, getCompensatingWorkDays, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
6
|
+
export type { Holiday, HolidayTransfer } from "./tt/utils.js";
|
|
7
7
|
export { Period, EducationType, AuthError, ParseError, } from "./common/types.js";
|
|
8
8
|
export type { Time, WeekRange, Teacher } from "./common/types.js";
|
|
9
9
|
export type { PersonalData } from "./lk/types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { LkClient } from "./lk/client.js";
|
|
2
2
|
export { TtClient } from "./tt/client.js";
|
|
3
3
|
export { Schedule } from "./tt/schedule.js";
|
|
4
|
-
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
4
|
+
export { getCurrentPeriod, isSessionPeriod, getSemesterStart, getSemesterWeeks, getWeekNumber, getWeekdayName, getTimeSlots, getLessonNumber, getAdjacentSemester, isHoliday, getEffectiveHolidays, getHolidayTransfers, getCompensatingWorkDays, RUSSIAN_HOLIDAYS, } from "./tt/utils.js";
|
|
5
5
|
export { AuthError, ParseError, } from "./common/types.js";
|
package/dist/tt/schedule.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { FullScheduleDay, SemesterWeek, Lesson } from "./types.js";
|
|
2
2
|
import { Period, EducationType } from "../common/types.js";
|
|
3
|
-
import { type Holiday } from "./utils.js";
|
|
3
|
+
import { type Holiday, type HolidayTransfer } from "./utils.js";
|
|
4
4
|
export declare class Schedule {
|
|
5
5
|
readonly groupId: number;
|
|
6
6
|
readonly scheduleMap: Map<number, FullScheduleDay[]>;
|
|
7
7
|
readonly educationType: EducationType;
|
|
8
8
|
/** List of holidays to exclude from schedule queries. Pass `[]` to disable. */
|
|
9
9
|
readonly holidays: Holiday[];
|
|
10
|
+
/** Government decree day-off transfers (Постановление Правительства). */
|
|
11
|
+
readonly holidayTransfers: HolidayTransfer[];
|
|
10
12
|
private _period?;
|
|
11
|
-
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType, holidays?: Holiday[] | null);
|
|
13
|
+
constructor(groupId: number, scheduleMap: Map<number, FullScheduleDay[]>, period?: Period, educationType?: EducationType, holidays?: Holiday[] | null, holidayTransfers?: HolidayTransfer[]);
|
|
12
14
|
/** Current (or fixed) period for this schedule. */
|
|
13
15
|
get period(): Period;
|
|
14
16
|
/** Days for the current period. */
|
package/dist/tt/schedule.js
CHANGED
|
@@ -5,13 +5,16 @@ export class Schedule {
|
|
|
5
5
|
educationType;
|
|
6
6
|
/** List of holidays to exclude from schedule queries. Pass `[]` to disable. */
|
|
7
7
|
holidays;
|
|
8
|
+
/** Government decree day-off transfers (Постановление Правительства). */
|
|
9
|
+
holidayTransfers;
|
|
8
10
|
_period;
|
|
9
|
-
constructor(groupId, scheduleMap, period, educationType, holidays) {
|
|
11
|
+
constructor(groupId, scheduleMap, period, educationType, holidays, holidayTransfers) {
|
|
10
12
|
this.groupId = groupId;
|
|
11
13
|
this.scheduleMap = scheduleMap;
|
|
12
14
|
this.educationType = educationType ?? 1 /* EducationType.HigherEducation */;
|
|
13
15
|
this._period = period;
|
|
14
16
|
this.holidays = holidays ?? RUSSIAN_HOLIDAYS;
|
|
17
|
+
this.holidayTransfers = holidayTransfers ?? [];
|
|
15
18
|
}
|
|
16
19
|
/** Current (or fixed) period for this schedule. */
|
|
17
20
|
get period() {
|
|
@@ -80,7 +83,7 @@ export class Schedule {
|
|
|
80
83
|
return slotsToLessons(slots, date);
|
|
81
84
|
}
|
|
82
85
|
forDate(date, opts) {
|
|
83
|
-
if (isHoliday(date, this.holidays))
|
|
86
|
+
if (isHoliday(date, this.holidays, this.holidayTransfers))
|
|
84
87
|
return [];
|
|
85
88
|
const period = getCurrentPeriod({ date });
|
|
86
89
|
const lessons = [];
|
package/dist/tt/utils.d.ts
CHANGED
|
@@ -54,10 +54,50 @@ export interface Holiday {
|
|
|
54
54
|
/** Human-readable name. */
|
|
55
55
|
name: string;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* A government-decree day-off transfer (Постановление Правительства).
|
|
59
|
+
* Moves a day off from one date to another.
|
|
60
|
+
*/
|
|
61
|
+
export interface HolidayTransfer {
|
|
62
|
+
/** The date that becomes a day off. */
|
|
63
|
+
dayOff: Date;
|
|
64
|
+
/** The date that becomes a working day (e.g. a Saturday). `null` if no compensating work day. */
|
|
65
|
+
workDay: Date | null;
|
|
66
|
+
}
|
|
57
67
|
/** Russian non-working public holidays (Статья 112 ТК РФ). */
|
|
58
68
|
export declare const RUSSIAN_HOLIDAYS: Holiday[];
|
|
59
69
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
70
|
+
* Compute effective non-working holiday dates for a given year.
|
|
71
|
+
*
|
|
72
|
+
* Rules (Art. 112 ТК РФ):
|
|
73
|
+
* 1. All holidays in the list are non-working days.
|
|
74
|
+
* 2. For non-January holidays: if a holiday falls on Sat/Sun, the day off
|
|
75
|
+
* automatically transfers to the next working day.
|
|
76
|
+
* 3. For January holidays (1–8): weekend transfers are NOT automatic —
|
|
77
|
+
* they are decided by annual government decree. Pass them via `transfers`.
|
|
78
|
+
* 4. Bridge days: if a non-January holiday falls on Tue, Mon is day off
|
|
79
|
+
* (preceding Sat works); if on Thu, Fri is day off (following Sat works).
|
|
80
|
+
* Computed automatically, can be overridden via `transfers`.
|
|
81
|
+
* 5. Government decree transfers (`transfers`) add extra days off and
|
|
82
|
+
* override auto-computed bridge days.
|
|
83
|
+
* 6. For 6-day week (`sixDayWeek`): Saturday is a work day, so
|
|
84
|
+
* Thursday bridges don't apply and Saturday holidays don't auto-transfer.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getEffectiveHolidays(year: number, holidays?: Holiday[], transfers?: HolidayTransfer[], sixDayWeek?: boolean): Date[];
|
|
87
|
+
/**
|
|
88
|
+
* Compute all transfers (auto bridges + explicit) for a given year.
|
|
89
|
+
* Useful for getting compensating work days (Saturdays that become working).
|
|
90
|
+
*/
|
|
91
|
+
export declare function getHolidayTransfers(year: number, holidays: Holiday[] | undefined, transfers: HolidayTransfer[] | undefined, sixDayWeek: boolean): HolidayTransfer[];
|
|
92
|
+
/**
|
|
93
|
+
* Returns the list of compensating work days (e.g. Saturdays that become working).
|
|
94
|
+
* Includes both auto-computed bridge compensations and explicit transfers.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getCompensatingWorkDays(year: number, holidays: Holiday[] | undefined, transfers: HolidayTransfer[] | undefined, sixDayWeek: boolean): Date[];
|
|
97
|
+
/**
|
|
98
|
+
* Returns true if the given date is a non-working holiday,
|
|
99
|
+
* including transferred holidays when they fall on weekends (Art. 112 ТК РФ)
|
|
100
|
+
* and auto-computed bridge days.
|
|
101
|
+
* Pass an empty array for `holidays` to disable holiday checking.
|
|
62
102
|
*/
|
|
63
|
-
export declare function isHoliday(date: Date, holidays?: Holiday[]): boolean;
|
|
103
|
+
export declare function isHoliday(date: Date, holidays?: Holiday[], transfers?: HolidayTransfer[], sixDayWeek?: boolean): boolean;
|
package/dist/tt/utils.js
CHANGED
|
@@ -324,11 +324,185 @@ export const RUSSIAN_HOLIDAYS = [
|
|
|
324
324
|
{ month: 11, day: 4, name: "День народного единства" },
|
|
325
325
|
];
|
|
326
326
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
327
|
+
* January holiday dates (1–8) are excluded from automatic weekend transfer
|
|
328
|
+
* per Art. 112 ТК РФ. Their transfers are decided by government decree.
|
|
329
329
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
330
|
+
function isJanuaryHoliday(h) {
|
|
331
|
+
return h.month === 1 && h.day >= 1 && h.day <= 8;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Compute bridge-day transfers for non-January holidays.
|
|
335
|
+
*
|
|
336
|
+
* Pattern (consistent across government decrees):
|
|
337
|
+
* - Holiday on Tuesday → Monday becomes day off, preceding Saturday is work day
|
|
338
|
+
* - Holiday on Thursday → Friday becomes day off, following Saturday is work day
|
|
339
|
+
* (only for 5-day week; 6-day week has Saturday classes, so no gap to bridge)
|
|
340
|
+
*
|
|
341
|
+
* January holidays are excluded (their 2 transfers are unpredictable).
|
|
342
|
+
*/
|
|
343
|
+
function computeBridgeDays(year, holidays, effectiveDays, sixDayWeek) {
|
|
344
|
+
const bridges = [];
|
|
345
|
+
for (const h of holidays) {
|
|
346
|
+
if (isJanuaryHoliday(h))
|
|
347
|
+
continue;
|
|
348
|
+
const date = new Date(year, h.month - 1, h.day);
|
|
349
|
+
const dow = date.getDay();
|
|
350
|
+
if (dow === 2) {
|
|
351
|
+
// Tuesday → Monday off, preceding Saturday works
|
|
352
|
+
const monday = new Date(date);
|
|
353
|
+
monday.setDate(date.getDate() - 1);
|
|
354
|
+
const saturday = new Date(date);
|
|
355
|
+
saturday.setDate(date.getDate() - 3);
|
|
356
|
+
if (!effectiveDays.some((d) => isSameDay(d, monday))) {
|
|
357
|
+
bridges.push({
|
|
358
|
+
dayOff: monday,
|
|
359
|
+
workDay: sixDayWeek ? null : saturday,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (dow === 4 && !sixDayWeek) {
|
|
364
|
+
// Thursday → Friday off, following Saturday works
|
|
365
|
+
// Only for 5-day week: 6-day week has no gap (Saturday is a work day)
|
|
366
|
+
const friday = new Date(date);
|
|
367
|
+
friday.setDate(date.getDate() + 1);
|
|
368
|
+
const saturday = new Date(date);
|
|
369
|
+
saturday.setDate(date.getDate() + 2);
|
|
370
|
+
if (!effectiveDays.some((d) => isSameDay(d, friday))) {
|
|
371
|
+
bridges.push({ dayOff: friday, workDay: saturday });
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return bridges;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Compute effective non-working holiday dates for a given year.
|
|
379
|
+
*
|
|
380
|
+
* Rules (Art. 112 ТК РФ):
|
|
381
|
+
* 1. All holidays in the list are non-working days.
|
|
382
|
+
* 2. For non-January holidays: if a holiday falls on Sat/Sun, the day off
|
|
383
|
+
* automatically transfers to the next working day.
|
|
384
|
+
* 3. For January holidays (1–8): weekend transfers are NOT automatic —
|
|
385
|
+
* they are decided by annual government decree. Pass them via `transfers`.
|
|
386
|
+
* 4. Bridge days: if a non-January holiday falls on Tue, Mon is day off
|
|
387
|
+
* (preceding Sat works); if on Thu, Fri is day off (following Sat works).
|
|
388
|
+
* Computed automatically, can be overridden via `transfers`.
|
|
389
|
+
* 5. Government decree transfers (`transfers`) add extra days off and
|
|
390
|
+
* override auto-computed bridge days.
|
|
391
|
+
* 6. For 6-day week (`sixDayWeek`): Saturday is a work day, so
|
|
392
|
+
* Thursday bridges don't apply and Saturday holidays don't auto-transfer.
|
|
393
|
+
*/
|
|
394
|
+
export function getEffectiveHolidays(year, holidays = RUSSIAN_HOLIDAYS, transfers = [], sixDayWeek = true) {
|
|
395
|
+
const originalDates = holidays.map((h) => new Date(year, h.month - 1, h.day));
|
|
396
|
+
const isOriginalHoliday = (d) => originalDates.some((od) => isSameDay(od, d));
|
|
397
|
+
const effectiveDays = [...originalDates];
|
|
398
|
+
// Auto-transfer: only non-January holidays that fall on weekends
|
|
399
|
+
const nonJanuaryOnWeekend = holidays
|
|
400
|
+
.filter((h) => !isJanuaryHoliday(h))
|
|
401
|
+
.map((h) => new Date(year, h.month - 1, h.day))
|
|
402
|
+
.filter((d) => d.getDay() === 0 || d.getDay() === 6)
|
|
403
|
+
.sort((a, b) => a.getTime() - b.getTime());
|
|
404
|
+
for (const holiday of nonJanuaryOnWeekend) {
|
|
405
|
+
let candidate = new Date(holiday);
|
|
406
|
+
if (candidate.getDay() === 6) {
|
|
407
|
+
candidate.setDate(candidate.getDate() + 2);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
411
|
+
}
|
|
412
|
+
while (candidate.getDay() === 0 ||
|
|
413
|
+
candidate.getDay() === 6 ||
|
|
414
|
+
isOriginalHoliday(candidate) ||
|
|
415
|
+
effectiveDays.some((ed) => isSameDay(ed, candidate))) {
|
|
416
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
417
|
+
}
|
|
418
|
+
effectiveDays.push(new Date(candidate));
|
|
419
|
+
}
|
|
420
|
+
// Bridge days (auto-computed, can be overridden)
|
|
421
|
+
const autoBridges = computeBridgeDays(year, holidays, effectiveDays, sixDayWeek);
|
|
422
|
+
// Merge: explicit transfers override auto-computed bridges
|
|
423
|
+
const allTransfers = [...autoBridges];
|
|
424
|
+
for (const t of transfers) {
|
|
425
|
+
const idx = allTransfers.findIndex((b) => isSameDay(b.dayOff, t.dayOff));
|
|
426
|
+
if (idx !== -1) {
|
|
427
|
+
allTransfers[idx] = t;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
allTransfers.push(t);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const compensatingWorkDays = [];
|
|
434
|
+
for (const t of allTransfers) {
|
|
435
|
+
if (!effectiveDays.some((d) => isSameDay(d, t.dayOff))) {
|
|
436
|
+
effectiveDays.push(t.dayOff);
|
|
437
|
+
}
|
|
438
|
+
if (t.workDay) {
|
|
439
|
+
compensatingWorkDays.push(t.workDay);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return effectiveDays.sort((a, b) => a.getTime() - b.getTime());
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Compute all transfers (auto bridges + explicit) for a given year.
|
|
446
|
+
* Useful for getting compensating work days (Saturdays that become working).
|
|
447
|
+
*/
|
|
448
|
+
export function getHolidayTransfers(year, holidays = RUSSIAN_HOLIDAYS, transfers = [], sixDayWeek) {
|
|
449
|
+
const originalDates = holidays.map((h) => new Date(year, h.month - 1, h.day));
|
|
450
|
+
const effectiveDays = [...originalDates];
|
|
451
|
+
// Replay weekend transfers to build effectiveDays for bridge computation
|
|
452
|
+
const nonJanuaryOnWeekend = holidays
|
|
453
|
+
.filter((h) => !isJanuaryHoliday(h))
|
|
454
|
+
.map((h) => new Date(year, h.month - 1, h.day))
|
|
455
|
+
.filter((d) => d.getDay() === 0 || d.getDay() === 6)
|
|
456
|
+
.sort((a, b) => a.getTime() - b.getTime());
|
|
457
|
+
const isOriginalHoliday = (d) => originalDates.some((od) => isSameDay(od, d));
|
|
458
|
+
for (const holiday of nonJanuaryOnWeekend) {
|
|
459
|
+
let candidate = new Date(holiday);
|
|
460
|
+
if (candidate.getDay() === 6) {
|
|
461
|
+
candidate.setDate(candidate.getDate() + 2);
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
465
|
+
}
|
|
466
|
+
while (candidate.getDay() === 0 ||
|
|
467
|
+
candidate.getDay() === 6 ||
|
|
468
|
+
isOriginalHoliday(candidate) ||
|
|
469
|
+
effectiveDays.some((ed) => isSameDay(ed, candidate))) {
|
|
470
|
+
candidate.setDate(candidate.getDate() + 1);
|
|
471
|
+
}
|
|
472
|
+
effectiveDays.push(new Date(candidate));
|
|
473
|
+
}
|
|
474
|
+
const autoBridges = computeBridgeDays(year, holidays, effectiveDays, sixDayWeek);
|
|
475
|
+
const allTransfers = [...autoBridges];
|
|
476
|
+
for (const t of transfers) {
|
|
477
|
+
const idx = allTransfers.findIndex((b) => isSameDay(b.dayOff, t.dayOff));
|
|
478
|
+
if (idx !== -1) {
|
|
479
|
+
allTransfers[idx] = t;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
allTransfers.push(t);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return allTransfers;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Returns the list of compensating work days (e.g. Saturdays that become working).
|
|
489
|
+
* Includes both auto-computed bridge compensations and explicit transfers.
|
|
490
|
+
*/
|
|
491
|
+
export function getCompensatingWorkDays(year, holidays = RUSSIAN_HOLIDAYS, transfers = [], sixDayWeek) {
|
|
492
|
+
return getHolidayTransfers(year, holidays, transfers, sixDayWeek)
|
|
493
|
+
.filter((t) => t.workDay != null)
|
|
494
|
+
.map((t) => t.workDay);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Returns true if the given date is a non-working holiday,
|
|
498
|
+
* including transferred holidays when they fall on weekends (Art. 112 ТК РФ)
|
|
499
|
+
* and auto-computed bridge days.
|
|
500
|
+
* Pass an empty array for `holidays` to disable holiday checking.
|
|
501
|
+
*/
|
|
502
|
+
export function isHoliday(date, holidays = RUSSIAN_HOLIDAYS, transfers = [], sixDayWeek = true) {
|
|
503
|
+
if (holidays.length === 0 && transfers.length === 0)
|
|
504
|
+
return false;
|
|
505
|
+
const year = date.getFullYear();
|
|
506
|
+
const effectiveDays = getEffectiveHolidays(year, holidays, transfers, sixDayWeek);
|
|
507
|
+
return effectiveDays.some((d) => isSameDay(d, date));
|
|
334
508
|
}
|