chuvsu-js 5.3.0 → 5.3.1

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.
@@ -21,8 +21,8 @@ export interface SerializedScheduleSnapshot {
21
21
  end: LocalDate;
22
22
  series: SerializedSeries[];
23
23
  direct: SerializedOccurrence[];
24
- holidays: Holiday[];
25
- holidayTransfers: {
24
+ holidays?: Holiday[];
25
+ holidayTransfers?: {
26
26
  dayOff: string;
27
27
  workDay: string | null;
28
28
  }[];
@@ -1,4 +1,4 @@
1
- import { formatLocalDate, parseLocalDate } from "../utils/index.js";
1
+ import { formatLocalDate, parseLocalDate, RUSSIAN_HOLIDAYS } from "../utils/index.js";
2
2
  import { Schedule } from "./schedule.js";
3
3
  function serializeSources(sources, include) {
4
4
  return include
@@ -8,6 +8,12 @@ function serializeSources(sources, include) {
8
8
  function deserializeSources(sources) {
9
9
  return sources.map((source) => ({ ...structuredClone(source), observedAt: new Date(source.observedAt) }));
10
10
  }
11
+ function usesDefaultHolidays(holidays) {
12
+ return holidays.length === RUSSIAN_HOLIDAYS.length && holidays.every((holiday, index) => {
13
+ const standard = RUSSIAN_HOLIDAYS[index];
14
+ return holiday.month === standard.month && holiday.day === standard.day && holiday.name === standard.name;
15
+ });
16
+ }
11
17
  /** Browser-ready schedule backed by recurring rules and dated exceptions. */
12
18
  export class ScheduleSnapshot extends Schedule {
13
19
  snapshot;
@@ -27,7 +33,7 @@ export class ScheduleSnapshot extends Schedule {
27
33
  const options = {
28
34
  period: snapshot.period,
29
35
  holidays: snapshot.holidays,
30
- holidayTransfers: snapshot.holidayTransfers.map((value) => ({
36
+ holidayTransfers: snapshot.holidayTransfers?.map((value) => ({
31
37
  dayOff: new Date(value.dayOff),
32
38
  workDay: value.workDay ? new Date(value.workDay) : null,
33
39
  })),
@@ -86,10 +92,12 @@ export function createScheduleSnapshot(schedule, options) {
86
92
  end: formatLocalDate(end),
87
93
  series,
88
94
  direct,
89
- holidays: structuredClone(schedule.holidays),
90
- holidayTransfers: schedule.holidayTransfers.map((value) => ({
91
- dayOff: value.dayOff.toISOString(),
92
- workDay: value.workDay?.toISOString() ?? null,
93
- })),
95
+ ...(!usesDefaultHolidays(schedule.holidays) ? { holidays: structuredClone(schedule.holidays) } : {}),
96
+ ...(schedule.holidayTransfers.length ? {
97
+ holidayTransfers: schedule.holidayTransfers.map((value) => ({
98
+ dayOff: value.dayOff.toISOString(),
99
+ workDay: value.workDay?.toISOString() ?? null,
100
+ })),
101
+ } : {}),
94
102
  };
95
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chuvsu-js",
3
- "version": "5.3.0",
3
+ "version": "5.3.1",
4
4
  "description": "Библиотека для расписания и личного кабинета ЧГУ им. И. Н. Ульянова",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",